yum重装与恢复

在CentOS上如果没有yum命令,装任何软件都将变的异常艰难。最近发现一台闲置的服务器上yum命令运行不起来了,一直报”Python找不到yum扩展”,服务器版本CentOS 6.8。查了各种问题都无法修复,最后想想重装算了。很多时候如果发现修复比重做更费时我们应该果断重做。

  1. 删除所有Python依赖

    首先需要强制删除已安装程序及其关联

    rpm -qa|grep python|sudo xargs rpm -ev –allmatches –nodeps

    然后删除所有残余文件

    whereis python |sudo xargs rm -frv

    最后验证是否删除完成,返回无结果表示删除成功

    whereis python

  2. 删除所有yum依赖

    删除依赖

    rpm -qa|grep yum|sudo xargs rpm -ev –allmatches –nodeps

    全局搜索删除

    whereis yum |sudo xargs rm -frv

  3. 下载需要用到的安装文件

    可以到对应的操作系统版本下载对应的文件,镜像下载链接如下(这里以centos/6.8为例)http://mirrors.ustc.edu.cn/centos/6.8/os/x86_64/Packages/

    需要下载如下文件:

    1. python-2.6.6-64.el6.x86_64.rpm
    2. python-devel-2.6.6-64.el6.x86_64.rpm
    3. python-libs-2.6.6-64.el6.x86_64.rpm
    4. python-pycurl-7.19.0-9.el6.x86_64.rpm
    5. python-setuptools-0.6.10-3.el6.noarch.rpm
    6. python-urlgrabber-3.9.1-11.el6.noarch.rpm
    7. python-iniparse-0.3.1-2.1.el6.noarch.rpm
    8. rpm-python-4.8.0-55.el6.x86_64.rpm
    9. yum-3.2.29-73.el6.centos.noarch.rpm
    10. yum-metadata-parser-1.1.2-16.el6.x86_64.rpm
    11. yum-utils-1.1.30-37.el6.noarch.rpm
    12. yum-plugin-fastestmirror-1.1.30-37.el6.noarch.rpm
    13. yum-plugin-protectbase-1.1.30-37.el6.noarch.rpm
    14. yum-plugin-aliases-1.1.30-37.el6.noarch.rpm

    这样一个一个下载非常麻烦,我建议写成shell脚本,如果是CentOS 6.8可以直接复制如下内容到t.sh文件中,然后执行t.sh。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    wget http://mirrors.ustc.edu.cn/centos/6.8/os/x86_64/Packages/python-2.6.6-64.el6.x86_64.rpm
    wget http://mirrors.ustc.edu.cn/centos/6.8/os/x86_64/Packages/python-devel-2.6.6-64.el6.x86_64.rpm
    wget http://mirrors.ustc.edu.cn/centos/6.8/os/x86_64/Packages/python-libs-2.6.6-64.el6.x86_64.rpm
    wget http://mirrors.ustc.edu.cn/centos/6.8/os/x86_64/Packages/python-pycurl-7.19.0-9.el6.x86_64.rpm
    wget http://mirrors.ustc.edu.cn/centos/6.8/os/x86_64/Packages/python-setuptools-0.6.10-3.el6.noarch.rpm
    wget http://mirrors.ustc.edu.cn/centos/6.8/os/x86_64/Packages/python-urlgrabber-3.9.1-11.el6.noarch.rpm
    wget http://mirrors.ustc.edu.cn/centos/6.8/os/x86_64/Packages/python-iniparse-0.3.1-2.1.el6.noarch.rpm
    wget http://mirrors.ustc.edu.cn/centos/6.8/os/x86_64/Packages/rpm-python-4.8.0-55.el6.x86_64.rpm
    wget http://mirrors.ustc.edu.cn/centos/6.8/os/x86_64/Packages/yum-3.2.29-73.el6.centos.noarch.rpm
    wget http://mirrors.ustc.edu.cn/centos/6.8/os/x86_64/Packages/yum-metadata-parser-1.1.2-16.el6.x86_64.rpm
    wget http://mirrors.ustc.edu.cn/centos/6.8/os/x86_64/Packages/yum-utils-1.1.30-37.el6.noarch.rpm
    wget http://mirrors.ustc.edu.cn/centos/6.8/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.30-37.el6.noarch.rpm
    wget http://mirrors.ustc.edu.cn/centos/6.8/os/x86_64/Packages/yum-plugin-protectbase-1.1.30-37.el6.noarch.rpm
    wget http://mirrors.ustc.edu.cn/centos/6.8/os/x86_64/Packages/yum-plugin-aliases-1.1.30-37.el6.noarch.rpm
  1. 安装文件

    首先安装python相关的rpm包

    rpm -Uvh –replacepkgs python*.rpm

    然后安装yum相关的包

    rpm -Uvh –replacepkgs rpm-python*.rpm yum*.rpm

    如果提示报错,可以一个一个包安装,比如提示(-ivh是安装覆盖,-Uvh是升级安装):

    rpm -ivh yum-plugin-fastestmirror-1.1.30-37.el6.noarch.rpm

    提示:yum >= 3.0 is needed by yum-plugin

    改为:rpm -ivh yum-3.2.29-73.el6.centos.noarch.rpm yum-plugin-fastestmirror-1.1.30-37.el6.noarch.rpm

  2. 运行

    最后我们可以运行”yum -h”来验证是否安装成功。

打赏时请留下微信号