首页 技术 正文
技术 2022年11月20日
0 收藏 985 点赞 3,822 浏览 1907 个字

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=123456for 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

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,086
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,561
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,410
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,183
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,820
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,903