1 uninstall yum

rpm -qa | grep yum | xargs rpm -e --nodeps
rpm -qa | grep python-iniparse | xargs rpm -e --nodeps
rpm -qa | grep python-urlgrabber | xargs rpm -e --nodeps

2 Download yum repo

wget http://mirrors.163.com/centos/7/os/x86_64/Packages/rpm-4.11.3-35.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-urlgrabber-3.10-9.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-3.4.3-161.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-50.el7.noarch.rpm

3 Install the rpm packages

rpm -iv python-urlgrabber-3.10-9.el7.noarch.rpm
rpm -iv python-iniparse-0.4-9.el7.noarch.rpm 
rpm -iv yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
rpm -iv yum-3.4.3-161.el7.centos.noarch.rpm yum-plugin-fastestmirror-1.1.31-50.el7.noarch.rpm

在安装yum和yum-plugin-fastestmirror时会提示rpm的版本不符合需求,需安装指定版本的rpm包

# 参数nodeps:忽略软件包的依赖关系强行安装
# 参数force:忽略软件包及文件的冲突
rpm -iv rpm-4.11.3-35.el7.x86_64.rpm --nodeps --force

4 Modify yum repo

# download repos according the redhat version in http://mirrors.163.com/.help/centos.html
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
# modify the repo file: replace $releasever to 7, open the file using vim first
    :%s/$releasever/7/g

5 Import the key

rpm --import http://mirrors.163.com/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7

6 Clear cache

yum clean all
yum makecache