如何从 rpm 数据库中删除软件包

如何从 rpm 数据库中删除软件包

我有一台Centos 6服务器,我意外地将一个RHEL 7包添加到了它的 rpm 数据库中。

添加了错误的包

sudo rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm

因此,当我尝试添加正确的包时,我得到了:

sudo rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/6/x86_64/zabbix-release-3.2-1.el6.noarch.rpm
Retrieving http://repo.zabbix.com/zabbix/3.2/rhel/6/x86_64/zabbix-release-3.2-1.el6.noarch.rpm
warning: /var/tmp/rpm-tmp.rzDcOd: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing...                ########################################### [100%]
    file /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX from install of zabbix-release-3.2-1.el6.noarch conflicts with file from package zabbix-release-3.0-1.el7.noarch
    file /etc/yum.repos.d/zabbix.repo from install of zabbix-release-3.2-1.el6.noarch conflicts with file from package zabbix-release-3.0-1.el7.noarch

因此我运行了以下命令:

yum clean all
rpm --rebuilddb

然后添加 RHEL 6 包:

sudo rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/6/x86_64/zabbix-release-3.2-1.el6.noarch.rpm
Retrieving http://repo.zabbix.com/zabbix/3.2/rhel/6/x86_64/zabbix-release-3.2-1.el6.noarch.rpm
warning: /var/tmp/rpm-tmp.DgETOM: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing...                ########################################### [100%]
   1:zabbix-release         ########################################### [100%]

但安装仍然恢复到错误的包:

sudo yum install zabbix-agent
Loaded plugins: fastestmirror, presto, refresh-packagekit
Setting up Install Process
Determining fastest mirrors
epel/metalink                                                                                                                                                                      |  18 kB     00:00     
 * base: repos-va.psychz.net
 * epel: mirror.vcu.edu
 * extras: centos.mirror.constant.com
 * fasttrack: mirror.fileplanet.com
 * updates: mirror.fileplanet.com
base                                                                                                                                                                               | 3.7 kB     00:00     
base/primary_db                                                                                                                                                                    | 4.7 MB     00:01     
centos-sclo-rh                                                                                                                                                                     | 2.9 kB     00:00     
centos-sclo-rh/primary_db                                                                                                                                                          | 1.2 MB     00:00     
centos-sclo-sclo                                                                                                                                                                   | 2.9 kB     00:00     
centos-sclo-sclo/primary_db                                                                                                                                                        | 154 kB     00:00     
cr                                                                                                                                                                                 | 3.3 kB     00:00     
cr/primary_db                                                                                                                                                                      | 1.2 kB     00:00     
epel                                                                                                                                                                               | 4.7 kB     00:00     
epel/primary_db                                                                                                                                                                    | 6.0 MB     00:02     
extras                                                                                                                                                                             | 3.4 kB     00:00     
extras/primary_db                                                                                                                                                                  |  27 kB     00:00     
fasttrack                                                                                                                                                                          | 2.9 kB     00:00     
fasttrack/primary_db                                                                                                                                                               | 9.9 kB     00:00     
updates                                                                                                                                                                            | 3.4 kB     00:00     
updates/primary_db                                                                                                                                                                 | 3.0 MB     00:00     
Resolving Dependencies
--> Running transaction check
---> Package zabbix-agent.x86_64 0:3.0.24-1.el7 will be installed
--> Processing Dependency: libc.so.6(GLIBC_2.17)(64bit) for package: zabbix-agent-3.0.24-1.el7.x86_64
--> Processing Dependency: systemd for package: zabbix-agent-3.0.24-1.el7.x86_64
--> Processing Dependency: systemd for package: zabbix-agent-3.0.24-1.el7.x86_64
--> Finished Dependency Resolution
Error: Package: zabbix-agent-3.0.24-1.el7.x86_64 (zabbix)
           Requires: libc.so.6(GLIBC_2.17)(64bit)
Error: Package: zabbix-agent-3.0.24-1.el7.x86_64 (zabbix)
           Requires: systemd
 You could try using --skip-broken to work around the problem
** Found 1 pre-existing rpmdb problem(s), 'yum check' output follows:
libmodule-10.0.1.274-b10_0_1_274.x86_64 has missing requires of libodbc.so.1()(64bit)
[root@medherent ~]# sudo rpm -evh zabbix-release-3.0-1.el7.noarch
rpm: --hash (-h) may only be specified during package installation
[root@medherent ~]# sudo rpm -ev zabbix-release-3.0-1.el7.noarch
error: package zabbix-release-3.0-1.el7.noarch is not installed

因此我尝试明确删除包:

sudo rpm -ev zabbix-release-3.0-1.el7.noarch
error: package zabbix-release-3.0-1.el7.noarch is not installed

如何运行 YUM 安装以使用 RHEL 6 包或从 rpm db 中删除 RHEL 7 包?

编辑

因此我按照建议运行了以下命令:

rpm -e zabbix-release

看起来执行没有错误。

我不知道哪些软件包属于我的发行版:

ls -all /etc/yum.repos.d 
total 68 
drwxr-xr-x.   2 root root  4096 Jan 23 13:43 . drwxr-xr-x. 117 root root 12288 Jan 23 11:37 ..
-rw-r--r--.   1 root root  1991 Jun 26  2018 CentOS-Base.repo
-rw-r--r--.   1 root root   509 Sep 25  2011 CentOS-CR.repo
-rw-r--r--.   1 root root   647 Jun 26  2018 CentOS-Debuginfo.repo
-rw-r--r--.   1 root root   276 May 12  2014 CentOS-fasttrack.repo
-rw-r--r--.   1 root root   289 Aug  3  2015 CentOS-fasttrack.repo.rpmnew
-rw-r--r--.   1 root root   630 Jun 26  2018 CentOS-Media.repo
-rw-r--r--.   1 root root   916 May 23  2016 CentOS-SCLo-scl.repo
-rw-r--r--.   1 root root   892 Jun 16  2016 CentOS-SCLo-scl-rh.repo
-rw-r--r--.   1 root root  8854 Jun 26  2018 CentOS-Vault.repo
-rw-r--r--.   1 root root   954 Oct  3  2016 epel.repo
-rw-r--r--.   1 root root  1056 Nov  4  2012 epel-testing.repo

编辑2

Yum 仍在尝试使用错误的包

sudo yum install zabbix-agent
Loaded plugins: fastestmirror, presto, refresh-packagekit
Setting up Install Process
Determining fastest mirrors
 * base: mirror.vcu.edu
 * extras: mirrors.greenmountainaccess.net
 * fasttrack: packages.oit.ncsu.edu
 * updates: mirror.cisp.com
base                                                                                                                                                                               | 3.7 kB     00:00     
base/primary_db                                                                                                                                                                    | 4.7 MB     00:02     
centos-sclo-rh                                                                                                                                                                     | 2.9 kB     00:00     
centos-sclo-rh/primary_db                                                                                                                                                          | 1.2 MB     00:02     
centos-sclo-sclo                                                                                                                                                                   | 2.9 kB     00:00     
centos-sclo-sclo/primary_db                                                                                                                                                        | 154 kB     00:00     
cr                                                                                                                                                                                 | 3.3 kB     00:00     
cr/primary_db                                                                                                                                                                      | 1.2 kB     00:00     
extras                                                                                                                                                                             | 3.4 kB     00:00     
extras/primary_db                                                                                                                                                                  |  27 kB     00:00     
fasttrack                                                                                                                                                                          | 2.9 kB     00:00     
fasttrack/primary_db                                                                                                                                                               | 9.9 kB     00:00     
updates                                                                                                                                                                            | 3.4 kB     00:00     
updates/primary_db                                                                                                                                                                 | 3.0 MB     00:01     
Resolving Dependencies
--> Running transaction check
---> Package zabbix-agent.x86_64 0:3.0.24-1.el7 will be installed
--> Processing Dependency: libc.so.6(GLIBC_2.17)(64bit) for package: zabbix-agent-3.0.24-1.el7.x86_64
--> Processing Dependency: systemd for package: zabbix-agent-3.0.24-1.el7.x86_64
--> Processing Dependency: systemd for package: zabbix-agent-3.0.24-1.el7.x86_64
--> Finished Dependency Resolution
Error: Package: zabbix-agent-3.0.24-1.el7.x86_64 (zabbix)
           Requires: libc.so.6(GLIBC_2.17)(64bit)
Error: Package: zabbix-agent-3.0.24-1.el7.x86_64 (zabbix)
           Requires: systemd
 You could try using --skip-broken to work around the problem
** Found 1 pre-existing rpmdb problem(s), 'yum check' output follows:
libmodule-10.0.1.274-b10_0_1_274.x86_64 has missing requires of libodbc.so.1()(64bit)

尤其

---> Package zabbix-agent.x86_64 0:3.0.24-1.el7 will be installed

答案1

需要卸载错误安装的包,即:

rpm -e zabbix-release

您可以通过以下方式删除软件包包裹名字,不是文件名,因为已安装的包没有文件名。


当然,这可能无法解决问题,因为您在没有必要的情况下破坏并重建了 RPM 数据库,并且可能存在不再跟踪的错误软件包文件。您需要找到这些文件并手动删除它们。查看目录并/etc/yum.repos.d查找与您的发行版不对应的 repo 文件。或者您可能很幸运,文件会被清除。


完成后,您需要清理 yum 的缓存,yum clean all然后重新安装正确的 zabbix-release RPM。

答案2

对于任何想要真正只是从 rpm 数据库中删除 rpm,如在依赖关系映射不正确的情况下,可以使用以下命令:

rpm -e --justdb packagename

注意:这不是卸载软件包的正确方法,应该是绝对的最后手段

这将立即从 rpmdb 中删除该条目,但安装该 rpm 所创建的任何文件仍将存在于您的系统中,这可能意味着很多不同的事情,具体取决于该软件包是什么。如果它是内核模块、守护进程或其他自动运行的东西,它将继续这样做,因为您实际上并没有卸载它。

来源: https://access.redhat.com/solutions/186933

答案3

请按照以下步骤操作,希望能解决该问题 -

# rpm -e zabbix-release

现在,安装您想要安装的包并按照以下步骤操作。

# yum info zabbix-release 
# yum list zabbix-release

这也将清除你的 yum 缓存。

# yum clean zabbix-release
# yum clean all
# yum install zabbix-agent

相关内容