本文主要总结CentOS7下重装Yum和Python的方法。

1、查看CentOS内核版本:

cat /etc/centos-release

得到结果:

CentOS Linux release 7.6.1810 (Core)

2、卸载所有Python

## 强制删除已安装程序及其关联
rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps
## 删除所有残余文件,xargs,允许你对输出执行其他某些命令
whereis python |xargs rm -frv
## 验证删除,返回无结果
whereis python

3、删除现有Yum

rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps
whereis yum |xargs rm -frv
whereis yum

4、从网易源下载Python和Yum的rpm包及其依赖包

注意:需要根据自己的系统内核找到对应的默认包

# python-*.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/python-libs-2.7.5-76.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/python-ipaddress-1.0.16-2.el7.noarch.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/python-backports-1.0-8.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/python-2.7.5-76.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/python-devel-2.7.5-76.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/python-pycurl-7.19.0-19.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/python-urlgrabber-3.10-9.el7.noarch.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/python-setuptools-0.9.8-7.el7.noarch.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/python-kitchen-1.1.1-5.el7.noarch.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/python-chardet-2.2.1-1.el7_1.noarch.rpm

# libxml2-*.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/libxml2-python-2.9.1-6.el7_2.3.x86_64.rpm


# rpm-*.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/rpm-python-4.11.3-35.el7.x86_64.rpm

# yum-*.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/yum-utils-1.1.31-50.el7.noarch.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/yum-3.4.3-161.el7.centos.noarch.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/yum-plugin-aliases-1.1.31-50.el7.noarch.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/yum-plugin-protectbase-1.1.31-50.el7.noarch.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-50.el7.noarch.rpm

# pkgconfig-*.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/pkgconfig-0.27.1-4.el7.x86_64.rpm


# lvm2-*.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/lvm2-python-libs-2.02.180-8.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/lvm2-libs-2.02.180-8.el7.x86_64.rpm


# device-*.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/device-mapper-event-devel-1.02.149-8.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/device-mapper-event-libs-1.02.149-8.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/device-mapper-event-1.02.149-8.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/device-mapper-1.02.149-8.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/device-mapper-devel-1.02.149-8.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/device-mapper-libs-1.02.149-8.el7.x86_64.rpm

5、安装rpm包

rpm -Uvh --replacepkgs python*.rpm
rpm -Uvh --replacepkgs lvm2-python-libs*.rpm
rpm -Uvh --replacepkgs libxml2-python*.rpm
rpm -Uvh --replacepkgs rpm-python*.rpm
rpm -Uvh --replacepkgs yum*.rpm
rpm -Uvh --replacepkgs pkgconfig*.rpm


rpm -Uvh --replacepkgs lvm2-libs*.rpm
rpm -Uvh --replacepkgs device-mapper-event*.rpm
rpm -Uvh --replacepkgs device-mapper*.rpm

以上就是重装Python和Yum的步骤。