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

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等其他源地址,而CentOS8原版是分拆为多个文件分别管理的。
阿里云还新增了PowerTools、centosplus等仓储地址。并将本地gpgkey路径改为了https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official

sed自行修改

#备份
sudo cp -r yum.repos.d yum.repos.d.bak
#替换
sudo sed -i 
-e 's|^mirrorlist=|#mirrorlist=|' 
-e 's|^#baseurl=|baseurl=|' 
-e 's|http://mirror.centos.org|https://mirrors.aliyun.com|' 
/etc/yum.repos.d/*.repo

sudo dnf clean all
sudo dnf makecache

EPEL

https://developer.aliyun.com/mirror/epel

sudo dnf install epel-release

sudo sed -i 
-e 's|^metalink|#metalink|' 
-e 's|^#baseurl=|baseurl=|' 
-e 's|download.fedoraproject.org/pub|mirrors.aliyun.com|' 
/etc/yum.repos.d/epel*.repo

sudo dnf clean all
sudo dnf makecache

dnf fastest mirror

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

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

fastestmirror=True

#使用
sudo dnf clean all
sudo dnf makecache
原文地址:https://www.cnblogs.com/wswind/p/11751829.html