一.首先安装wget,备份原来的centos官方yum源
yum install wget -y
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
二.下载阿里云源
centos6
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
centos7
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
centos8
wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
三.清理原缓存并生成新的缓存
yum clean all
yum makecache
四.yum异常问题解决
rm -f/var/lib/rpm/__db.*
rm -f /var/lib/rpm/.rpm.lock
rpm -v -v --rebuilddb
yum makecache