删除起始的源
cd /etc/yum.repos.d/ && rm -f ./* || echo "delete error"
卸载yum
rpm -qa | grep yum | xargs -I {} rpm -e --nodeps {}
下载最新的yum程序的rpm包
如果/etc/yum.repos.d目录被删除,需要重新创建该目录,并进入该目录
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-3.4.3-168.el7.centos.noarch.rpm wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm
安装yum程序
rpm -ivh *.rpm
导入证书
rpm --import http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7
添加阿里源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
清理源
yum clean all && yum makecache fast