centos 7
1, 备份原有repo文件
2,使用阿里yum源
wget -O /etc/yum.repos.d/CentOS7-Aliyun.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel-7-Aliyun.repo http://mirrors.aliyun.com/repo/epel-7.repo
3,centos7 更新epel源
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
4, 更新缓存
yum clean all
yum makecache
#查看源列表
yum repolist all
centos 8
1,备份原有repo文件
cd /etc/yum.repos.d/ && mkdir backup && mv *repo backup/
2,下载阿里源文件
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
3,更新源文件的地址
sed -i -e "s|mirrors.cloud.aliyuncs.com|mirrors.aliyun.com|g " /etc/yum.repos.d/CentOS-*
sed -i -e "s|releasever|releasever-stream|g" /etc/yum.repos.d/CentOS-*
4,安装epel源,centos8 和centos7 完全不同
yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
安装后,在/etc/yum.repos.d目录下会多出下面的文件
5, 将将 repo 配置中的地址替换为阿里云镜像站地址
sed -i 's|^#baseurl=https://download.fedoraproject.org/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
6,生成缓存
yum clean all && yum makecache