基于centos7
#备份现有base源
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-7.repo --no-check-certificate
#修改repo文件失效地址
sed -i 's/mirrors.cloud.aliyuncs.com/mirrors.aliyun.com/g' /etc/yum.repos.d/CentOS-Base.repo
#卸载现有epel源和安装新的epel源
yum -y remove epel-release && yum install epel-release -y
#清理缓存并加载元数据
yum clean all && yum makecache
基于centos6
执行以下脚本
#!/bin/bash
main(){
local yum_dir=/etc/yum.repos.d
if [ -f ${yum_dir}/epel.repo ];then
mv ${yum_dir}/epel.repo ${yum_dir}/epel.repo.backup
fi
sed -i "s|enabled=1|enabled=0|g" /etc/yum/pluginconf.d/fastestmirror.conf
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
curl -o /etc/yum.repos.d/CentOS-Base.repo https://www.xmpan.com/Centos-6-Vault-Aliyun.repo
yum clean all
yum makecache
}
main