CentOS 8 换源,设置dnf / yum镜像


centos 8 默认是会读取centos.org的mirrorlist的,所以一般来说是不需要配置镜像的。
如果你的网络访问mirrorlist有问题,才需要另外配置
相关镜像配置,请参考各镜像站的相关帮助
https://developer.aliyun.com/mirror/
https://mirrors.tuna.tsinghua.edu.cn/help/centos/
http://mirrors.ustc.edu.cn/help/centos.html

dnf fastest mirror

dnf集成了fastest mirror功能,在yum中这是需要单独安装插件使用的。
此方法要求你能够访问 http://mirrorlist.centos.org
配置后,dnf会自动到mirror list中查找最快的镜像。

#修改配置
vi /etc/dnf/dnf.conf

fastestmirror=True

#使用
sudo dnf clean all
sudo dnf makecache

aliyun镜像

aliyun更新了centos8的说明:https://developer.aliyun.com/mirror/centos

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

需要注意的是Base.repo文件中也带了AppStream,这会提示重复的AppStream。

sed自行修改

cd /etc/yum.repos.d
#备份
cp CentOS-Base.repo CentOS-Base.repo.bak
cp CentOS-AppStream.repo CentOS-AppStream.repo.bak
cp CentOS-Extras.repo CentOS-Extras.repo.bak

sed -i 's|mirrorlist=|#mirrorlist=|g' CentOS-Base.repo CentOS-AppStream.repo CentOS-Extras.repo
sed -i 's|#baseurl=|baseurl=|g' CentOS-Base.repo CentOS-AppStream.repo CentOS-Extras.repo
sed -i 's|http://mirror.centos.org|https://mirrors.aliyun.com|g' CentOS-Base.repo CentOS-AppStream.repo CentOS-Extras.repo


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM