恢复 CentOS 缺少 YUM 和 RPM

恢复 CentOS 缺少 YUM 和 RPM

历史如下:

我有(或曾经有)一个 Linux 机器,CentOS 5.9以及预安装的 LAMP 配置。它可以工作,但太过时了,例如 mysql 是版本 4。所以我决定用好吃

奇怪的是,我的 sqlite 是 3.6,比 3.3 新,并且被列为较新的 PHP、Apache 和 subversion 的依赖项,因此 yum 停止升级并对此提出抱怨。

然后我做了一件非常错误的事情:我用yum 清除 SQLite从我的系统中删除旧的(但较新的)sqlite。此时 yum 删除了 sqlite 和所有其他依赖它的包。这基本上包括了所有内容 :)

现在我仍然可以通过 ssh 访问我的机器,但是 apache、mysql、php 都不见了,很多其他东西也被删除了,包括开发包、rpm 和 yum 本身。

我对 debian 和 apt-get 很熟悉,我简直不敢相信我在 centos 机器上使用 yum 的头 30 分钟内就遇到了这个问题。现在我完全不知道如何修复它。

我已经找到了如何从 rpm 文件安装 yum,或者从 yum 安装 rpm,但由于我没有……

在我的根目录中我有这个文件:initrd-2.6.18-308.13.1.el5.centos.plus.img我想象这是我的系统预先安装的图像,但我不知道如何从该文件恢复我的系统。

有人可以帮我吗?

答案1

您可以尝试在另一台主机上提取以下包:

http://mirror.mirohost.net/centos/5.9/updates/x86_64/RPMS/rpm-4.4.2.3-32.el5_9.x86_64.rpm http://mirror.mirohost.net/centos/5.9/updates/x86_64/RPMS/rpm-libs-4.4.2.3-32.el5_9.x86_64.rpm

然后只需使用 scp/wget/rsync 复制二进制文件即可。我在 vmware 工作站上试过,一切正常

# yum erase rpm
Loaded plugins: fastestmirror
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package rpm.x86_64 0:4.4.2.3-32.el5_9 set to be erased
--> Processing Dependency: rpm = 4.4.2.3-32.el5_9 for package: rpm-python
--> Processing Dependency: rpm = 4.4.2.3-32.el5_9 for package: rpm-libs
--> Processing Dependency: rpm for package: man
--> Processing Dependency: rpm = 4.4.2.3-32.el5_9 for package: rpm-build
--> Processing Dependency: rpm = 4.4.2.3-32.el5_9 for package: rpm-devel
--> Processing Dependency: rpm >= 4.4.2 for package: yum
--> Running transaction check
---> Package man.x86_64 0:1.6d-3.el5 set to be erased
--> Processing Dependency: man >= 1.6d-2 for package: man-pages-overrides
---> Package rpm-build.x86_64 0:4.4.2.3-32.el5_9 set to be erased
---> Package rpm-devel.x86_64 0:4.4.2.3-32.el5_9 set to be erased
--> Processing Dependency: rpm-devel for package: net-snmp-devel
---> Package rpm-libs.x86_64 0:4.4.2.3-32.el5_9 set to be erased
--> Processing Dependency: librpm-4.4.so()(64bit) for package: net-snmp
--> Processing Dependency: librpmio-4.4.so()(64bit) for package: net-snmp
---> Package rpm-python.x86_64 0:4.4.2.3-32.el5_9 set to be erased
--> Processing Dependency: rpm-python for package: system-config-network-tui
---> Package yum.noarch 0:3.2.22-40.el5.centos set to be erased
--> Processing Dependency: yum >= 3.2.22 for package: yum-updatesd
--> Processing Dependency: yum >= 3.0 for package: yum-fastestmirror
--> Running transaction check
---> Package man-pages-overrides.noarch 0:5.9.2-2.el5 set to be erased
---> Package net-snmp.x86_64 1:5.3.2.2-20.el5 set to be erased
---> Package net-snmp-devel.x86_64 1:5.3.2.2-20.el5 set to be erased
---> Package system-config-network-tui.noarch 0:1.3.99.21-1.el5 set to be erased
--> Processing Dependency: system-config-network-tui for package: firstboot-tui
---> Package yum-fastestmirror.noarch 0:1.1.16-21.el5.centos set to be erased
---> Package yum-updatesd.noarch 1:0.9-5.el5 set to be erased
--> Running transaction check
---> Package firstboot-tui.x86_64 0:1.4.27.9-1.el5.centos set to be erased
--> Processing Dependency: /usr/bin/man for package: redhat-lsb
--> Processing Dependency: /usr/bin/man for package: redhat-lsb
--> Processing Dependency: /bin/rpm for package: policycoreutils
--> Restarting Dependency Resolution with new changes.
--> Running transaction check
---> Package policycoreutils.x86_64 0:1.33.12-14.8.el5_9 set to be erased
--> Processing Dependency: policycoreutils >= 1.33.12-14.5 for package: selinux-policy-targeted
--> Processing Dependency: policycoreutils for package: sudo
--> Processing Dependency: policycoreutils for package: sudo
--> Processing Dependency: policycoreutils >= 1.33.12-14.5 for package: selinux-policy
--> Processing Dependency: policycoreutils for package: setools
---> Package redhat-lsb.i386 0:4.0-2.1.4.el5 set to be erased
---> Package redhat-lsb.x86_64 0:4.0-2.1.4.el5 set to be erased
--> Running transaction check
---> Package selinux-policy.noarch 0:2.4.6-338.el5 set to be erased
---> Package selinux-policy-targeted.noarch 0:2.4.6-338.el5 set to be erased
---> Package setools.x86_64 0:3.0-3.el5 set to be erased
---> Package sudo.x86_64 0:1.7.2p1-22.el5_9.1 set to be erased
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================================================================
 Package                                      Arch                      Version                                    Repository                    Size
======================================================================================================================================================
Removing:
 rpm                                          x86_64                    4.4.2.3-32.el5_9                           installed                    3.6 M
Removing for dependencies:
 firstboot-tui                                x86_64                    1.4.27.9-1.el5.centos                      installed                    652 k
 man                                          x86_64                    1.6d-3.el5                                 installed                    354 k
 man-pages-overrides                          noarch                    5.9.2-2.el5                                installed                    181 k
 net-snmp                                     x86_64                    1:5.3.2.2-20.el5                           installed                    2.8 M
 net-snmp-devel                               x86_64                    1:5.3.2.2-20.el5                           installed                    8.0 M
 policycoreutils                              x86_64                    1.33.12-14.8.el5_9                         installed                    2.1 M
 redhat-lsb                                   i386                      4.0-2.1.4.el5                              installed                     21 k
 redhat-lsb                                   x86_64                    4.0-2.1.4.el5                              installed                     22 k
 rpm-build                                    x86_64                    4.4.2.3-32.el5_9                           installed                    1.5 M
 rpm-devel                                    x86_64                    4.4.2.3-32.el5_9                           installed                    4.1 M
 rpm-libs                                     x86_64                    4.4.2.3-32.el5_9                           installed                    2.0 M
 rpm-python                                   x86_64                    4.4.2.3-32.el5_9                           installed                    131 k
 selinux-policy                               noarch                    2.4.6-338.el5                              installed                    7.9 M
 selinux-policy-targeted                      noarch                    2.4.6-338.el5                              installed                     33 M
 setools                                      x86_64                    3.0-3.el5                                  installed                    3.3 M
 sudo                                         x86_64                    1.7.2p1-22.el5_9.1                         installed                    884 k
 system-config-network-tui                    noarch                    1.3.99.21-1.el5                            installed                    4.9 M
 yum                                          noarch                    3.2.22-40.el5.centos                       installed                    3.3 M
 yum-fastestmirror                            noarch                    1.1.16-21.el5.centos                       installed                     47 k
 yum-updatesd                                 noarch                    1:0.9-5.el5                                installed                     55 k

Transaction Summary
======================================================================================================================================================
Remove       21 Package(s)
Reinstall     0 Package(s)
Downgrade     0 Package(s)

Is this ok [y/N]: y

进而

# wget http://mirror.mirohost.net/centos/5.9/os/x86_64/CentOS/yum-3.2.22-40.el5.centos.noarch.rpm

# wget http://mirror.mirohost.net/centos/5.9/os/x86_64/CentOS/rpm-python-4.4.2.3-31.el5.x86_64.rpm

# wget http://mirror.mirohost.net/centos/5.9/os/x86_64/CentOS/yum-fastestmirror-1.1.16-21.el5.centos.noarch.rpm

# rpm -ivh --nodeps yum-3.2.22-40.el5.centos.noarch.rpm  rpm-python-4.4.2.3-31.el5.x86_64.rpm yum-fastestmirror-1.1.16-21.el5.centos.noarch.rpm
Preparing...                ########################################### [100%]
   1:rpm-python             ########################################### [ 33%]
   2:yum-fastestmirror      ########################################### [ 67%]
   3:yum                    ########################################### [100%]

检查一切是否正常

# yum install mc
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.colocall.net
 * epel: ftp.colocall.net
 * extras: ftp.colocall.net
 * rpmforge: ftp.colocall.net
 * updates: centos.itt-consulting.com
base                                                                                                                           | 1.1 kB     00:00
epel                                                                                                                           | 3.6 kB     00:00
extras                                                                                                                         | 2.1 kB     00:00
rpmforge                                                                                                                       | 1.9 kB     00:00
updates                                                                                                                        | 1.9 kB     00:00
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mc.x86_64 1:4.6.1a-35.el5 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================================================================
 Package                        Arch                               Version                                     Repository                        Size
======================================================================================================================================================
Installing:
 mc                             x86_64                             1:4.6.1a-35.el5                             base                             2.1 M

Transaction Summary
======================================================================================================================================================
Install       1 Package(s)
Upgrade       0 Package(s)

Total download size: 2.1 M
Is this ok [y/N]:
Downloading Packages:
mc-4.6.1a-35.el5.x86_64.rpm                                                                                                    | 2.1 MB     00:02
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : mc                                                                                                                             1/1

Installed:
  mc.x86_64 1:4.6.1a-35.el5

Complete!

PS 之后不要忘记通过 yum 重新安装 rpm;)

# yum install rpm

答案2

我遇到过同样的问题。

我卸载了 sqlite,然后yum就没rpm用了。我下载了SQLite 源代码,然后使用 make 和 make install 进行安装./configure。但问题仍然存在。

然后我比较了此服务器中名称中包含 sqlite 的文件,发现服务器运行正常。我发现了以下文件:

/usr/lib/python/site-packages/yum/sqlite*
/usr/lib64/libsqlite3.so.0*
/usr/include/sqlite*

之后,我将这些文件从良好的服务器复制到了故障的服务器,现在一切正常。

答案3

您可以尝试以下命令

# cd /mnt
# zcat /root/initrd-2.6.18-308.13.1.el5.centos.plus.img | cpio -i

但我认为这并不能解决你的问题。你可以尝试下载 сentos dvd,挂载它们并安装所有必要的软件包

# cd /root 
# wget http://mirror.mirohost.net/centos/5.9/isos/x86_64/CentOS-5.9-x86_64-bin-DVD-1of2.iso
# mount -o loop /root/CentOS-5.9-x86_64-bin-DVD-1of2.iso /mnt

PS 您可以在 /var/log/messages 中看到所有已删除的软件包

相关内容