change_apt_source.sh
# !/bin/bash
# 备份原来的源文件
cp /etc/apt/sources.list /etc/apt/sources.list.bak
# 获取系统的版本信息
SYS_VERSION=$(lsb_release -c | grep -o "\s.*")
# 清空原有的源内容
echo "" > /etc/apt/sources.list
# 将阿里云的源数据源设置到sources.list文件中
cat >> /etc/apt/sources.list << EOF
deb http://mirrors.aliyun.com/ubuntu/ $SYS_VERSION main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ $SYS_VERSION main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ $SYS_VERSION-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ $SYS_VERSION-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ $SYS_VERSION-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ $SYS_VERSION-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ $SYS_VERSION-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ $SYS_VERSION-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ $SYS_VERSION-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ $SYS_VERSION-proposed main restricted universe multiverse
EOF
apt-get update
apt-get upgrade
batch_change_apt_source.sh
# !/bin/bash
SERVERS="g02 g03 g04"
PASSWORD=123456
for SERVER in $SERVERS
do
# 批量创建文件夹
if ssh root@$SERVER test -d "/root/bin/apt";then
echo ‘dir is exist‘
else
echo ‘no this dir and then will create it.‘
ssh root@$SERVER mkdir -p /root/bin/apt
fi
scp ./change_apt_source.sh $SERVER:/root
ssh root@$SERVER /root/change_apt_source.sh
done
多台机器
当需要修改多台机器的源的时候,上面那种方式就有点麻烦了,其实这些工作都可以通过脚本来做的。脚本下载。
配置好hosts,在执行脚本的机器上的hosts文件中添加所有机器名和IP映射关系。
修改脚本文件中batch_change_apt_source.sh的机器名称,即SERVERS变量。
设置可执行权限
chmod 777 batch_change_apt_source.sh
chmod 777 change_apt_source.sh
执行batch_change_apt_source.sh
./batch_change_apt_source.sh
过程中可能会提示输入机器密码和Y/N
————————————————
版权声明:本文为CSDN博主「名字想好没。」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/sinat_27629035/article/details/85561550