CentOS7 重装python与yum

我的CSDN博客:https://blog.csdn.net/qq_36731677/article/details/83552436

问题描述

今天接手了一个被搞乱的服务器,在安装数据库的时候出现了大量的yum错误(如下列内容所示)。所以就在瞎折腾,我仅把我解决的过程作结一下供大家参考。
错误一

Not removing XXX because it is required XXX
--------------------------------------------------------------------------------------
There are unfinished transactions remaining. You might consider running yum-complete-transaction first to finish them. 
The program yum-complete-transaction is found in the yum-utils package. 

错误二

There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:

   /usr/lib64/python2.7/site-packages/rpm/_rpm.so: undefined symbol: rpmpkgVerifySi

Please install a package which provides this module, or
verify that the module is installed correctly.

It's possible that the above module doesn't match the
current version of Python, which is:
2.7.5 (default, Apr 11 2018, 07:36:10)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)]

If you cannot solve this problem yourself, please go to
the yum faq at:
  http://yum.baseurl.org/wiki/Faq

对于依赖冲突问题的解决方式

  • 使用一个小工具yum-complete-transaction
    yum install yum-utils
  • 清理未完成的yum事务
    yum-complete-transaction –cleanup-only
  • 列出有问题的软件包
    package-cleanup –problems
  • 列出重复安装的软件包
    package-cleanup –dupes
  • 清除重复的已安装的包
    package-cleanup –cleandupes

如果是问题是缺少依赖,你可能需要手动安装这些依赖,我暂时没找到自动补全依赖的命令。
但是,这个流程只能解决一部分问题,就算删了旧内核也没有用,所以我在下面采用了删除python和yum重装的策略来解决。

重装python和yum

  1. 卸载现有的python
    强制删除已安装程序及其关联
    rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps
    强制删除所有残余文件
    whereis python |xargs rm -frv
  2. 卸载现有的yum
    rpm -qa|grep yum|xarg 强制删除已安装程序及其关联s rpm -ev --allmatches --nodeps
    强制删除所有残余文件
    whereis yum |xargs rm -frv
  3. 下载与自己版本对应的rpm包
    查看自己系统版本的命令:cat /etc/redhat-release
    下载地址链接:http://mirrors.ustc.edu.cn/centos/
    CentOS7.5的rpm包:http://mirrors.ustc.edu.cn/centos/7.5.1804/os/x86_64/Packages/
    我下载的rpm包,如果在安装过程中提醒你有被依赖的,你可以在库中下载同名的rpm包。
libxml2-python-2.9.1-6.el7_2.3.x86_64.rpm
python-2.7.5-68.el7.x86_64.rpm
python-backports-1.0-8.el7.x86_64.rpm
python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch.rpm
python-chardet-2.2.1-1.el7_1.noarch.rpm
python-devel-2.7.5-68.el7.x86_64.rpm
python-iniparse-0.4-9.el7.noarch.rpm
python-ipaddress-1.0.16-2.el7.noarch.rpm
python-kitchen-1.1.1-5.el7.noarch.rpm
python-libs-2.7.5-68.el7.x86_64.rpm
python-pycurl-7.19.0-19.el7.x86_64.rpm
python-setuptools-0.9.8-7.el7.noarch.rpm
python-urlgrabber-3.10-8.el7.noarch.rpm
python-virtualenv-15.1.0-2.el7.noarch.rpm
rpm-4.11.3-32.el7.x86_64.rpm
rpm-build-4.11.3-32.el7.x86_64.rpm
rpm-build-libs-4.11.3-32.el7.x86_64.rpm
rpm-libs-4.11.3-32.el7.x86_64.rpm
rpm-python-4.11.3-32.el7.x86_64.rpm
rpm-sign-4.11.3-32.el7.x86_64.rpm
yum-3.4.3-158.el7.centos.noarch.rpm
yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
yum-plugin-aliases-1.1.31-45.el7.noarch.rpm
yum-plugin-fastestmirror-1.1.31-45.el7.noarch.rpm
yum-plugin-protectbase-1.1.31-45.el7.noarch.rpm
yum-utils-1.1.31-45.el7.noarch.rpm

下载完成后安装这些包,有些依赖你可能要自己解决
rpm -Uvh --replacepkgs *.rpm
如果安装完成后键入yum能有正常显示,就说明安装成功了。如果出现了文章开头的错误二,那可能代表着你的rpm包没安装全。

在yum安装成功后,可将源文件清空并下载新的源
可参考:https://blog.csdn.net/qq_36731677/article/details/58288979
之后逐步更新源数据

yum clean all
yum makecache
yum --skip-broken update

参考链接
https://superuser.com/questions/1302240/usr-lib64-python2-7-site-packages-rpm-rpm-so-undefined-symbol-rpmpkgverifysi

You may also like...

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注