Linux更换yum源

Linux更换yum源,第1张

有时候CentOS默认的yum源不一定是国内镜像,导致yum在线安装及更新速度不是很理想。这时候需要将yum源设置为国内镜像站点。国内主要开源的开源镜像站点应该是网易和阿里云了。

[[email protected] ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

[[email protected] ~]]# cd /etc/yum.repos.d/

[[email protected] yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo

[[email protected] yum.repos.d]# wget http://mirrors.163.com/.help/CentOS6-Base-163.repo

[[email protected] yum.repos.d]# wget http://mirrors.163.com/.help/CentOS5-Base-163.repo

[[email protected] yum.repos.d]# yum makecache

[[email protected] yum.repos.d]# yum -y update

[[email protected] ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

[[email protected] ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

[[email protected] ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

[[email protected] ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo

[[email protected] ~]# yum makecache

[[email protected] ~]# yum -y update

将上面的镜像源覆盖到sources.list里,保存。

将上面的一个镜像源 覆盖 到sources.list里,保存。

4.2 sudo rm -f /var/lib/apt/lists/lock 删除lock文件

4.3 再用 sudo apt-get update 更新源

一、[endif] 为啥centos8要换源?

当前时间是2022年2月22号

2021年12月31日CentOS 8 *** 作系统版本结束了生命周期(EOL),Linux社区已不再维护该 *** 作系统版本。后续新的服务器建议使用CentOS Stream,或者其他linux版本,按照社区规则,CentOS 8的源地址http://mirror.centos.org/centos/8/内容已移除,目前第三方的镜像站中均已移除CentOS 8的源。但是对于业务过渡期仍然需要使用centos8,并且在上面安装软件,那我们需要更新备用源,之前第三方的源都是同步centos官方的,并随之更新,官方的源去掉后,第三方也就无法同步到了,所以第三方的源也就不复存在了,但是大部分第三方都把最后的源做了个备份弄了个新的地址,方便过渡期使用。当然切换到阿里云的源速度也会更快些。

阿里云镜像站官网: https://developer.aliyun.com/mirror/

阿里云centos源地址: https://developer.aliyun.com/mirror/centos

二、[endif] 如何更换centos8源的阿里云镜像地址

两种情况,阿里云ecs和非阿里云ecs,非阿里云ecs要求可以连接上公网,如果是阿里云ecs使用阿里云提供的内网链接源,不是阿里云的服务器,使用的公网源,肯定内网源的速度会更快些。

仔细观察就能发现内网链接:mirrors.cloud.aliyuncs.com

公网链接:mirrors.aliyun.com

非阿里云服务器用户:

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

wget -O /etc/yum.repos.d/CentOS-Base.repo https: //mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo

yum clean all &&yum makecache

阿里云服务器用户:

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

wget -O /etc/yum.repos.d/CentOS-Base.repo https: //mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo

sed -i 's/mirrors.cloud.aliyuncs.com/url_tmp/g' /etc/yum.repos.d/CentOS-Base.repo &&sed -i 's/mirrors.aliyun.com/mirrors.cloud.aliyuncs.com/g' /etc/yum.repos.d/CentOS-Base.repo &&sed -i 's/url_tmp/mirrors.aliyun.com/g' /etc/yum.repos.d/CentOS-Base.repo

yum clean all &&yum makecache

三、[endif] 其他工具换源

推荐使用linux一键换源脚本, https://supermanito.github.io/LinuxMirrors/#/

不仅支持centos,还支持其他linux发行版本,感谢原作者的无私奉献。

Gitee地址: https://gitee.com/SuperManito/LinuxMirrors


欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/tougao/6072211.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-13
下一篇 2023-03-13

发表评论

登录后才能评论

评论列表(0条)

保存