本文是笔者最近遇到的一个故障的处理过程,解决方案是Rebuild RPM 的DB,后面内容其实是REDHAT官方的solutions,不过我遇到的现象和解决方案都与官方有点出入,故一直帖出来:

我遇到的故障现象:

[root@migrationLin6 ~]# rpm -qa
error: rpmdbNextIterator: skipping h# 514 Header V3 RSA/SHA256 Signature, key ID fd431d51: BAD
error: rpmdbNextIterator: skipping h# 259 Header V3 RSA/SHA256 Signature, key ID fd431d51: BAD
error: rpmdbNextIterator: skipping h# 4 Header V3 RSA/SHA256 Signature, key ID fd431d51: BAD

没想到,按照官方步骤做了 rpm --rebuilddb以后,YUM又现现如下错误

[root@migrationLin6 rpm]# yum clean all
Traceback (most recent call last):
File "/usr/bin/yum", line 29, in <module>
yummain.user_main(sys.argv[1:], exit_code=True)
File "/usr/share/yum-cli/yummain.py", line 294, in user_main
errcode = main(args)
File "/usr/share/yum-cli/yummain.py", line 115, in main
base.getOptionsConfig(args)
File "/usr/share/yum-cli/cli.py", line 228, in getOptionsConfig
self.conf
File "/usr/lib/python2.6/site-packages/yum/__init__.py", line 910, in <lambda>
conf = property(fget=lambda self: self._getConfig(),
File "/usr/lib/python2.6/site-packages/yum/__init__.py", line 299, in _getConf ig
startupconf = config.readStartupConfig(fn, root)
File "/usr/lib/python2.6/site-packages/yum/config.py", line 892, in readStartu pConfig
startupconf.releasever = _getsysver(startupconf.installroot, startupconf.dis troverpkg)
File "/usr/lib/python2.6/site-packages/yum/config.py", line 1043, in _getsysve r
hdr = idx.next()
StopIteration

中间走过各种坑,归根结底还是由于rpmdb损坏引起的。网上碰到这种现象的比较少,最后我的解决办法是:

rm -f /var/lib/rpm/*
rpm -vv -rebuilddb
yum update -y

附上官方的方案:  

https://access.redhat.com/solutions/6903

如果没有redhat订阅,可能看不了,我粘上来了:

How to rebuild RPM database on a Red Hat Enterprise Linux system?

Solution 已验证 - 已更新2015年三月23日12:35

环境

  • Red Hat Enterprise Linux (RHEL) - All Versions - All architectures

问题

  • RPM is not working correctly, updates cannot be applied.
  • How to rebuild the RPM database?
  • Why does rpm command segfault when executed?
  • yum update fails with rpmdb errors.
  • Damaged header instance error
  • rpm command terminates with "cannot open Packages database in /var/lib/rpm"
  • Why does rpm or yum terminate with rpmdb: Lock table is out of available locker entries?
  • Attempted to do an rpm -q on a couple of packages and got errors like this:
rpmdb: /var/lib/rpm/Packages: unexpected file type or format
error: cannot open Packages index using db3 - Invalid argument (22)
  • On doing rpm query or install, it is failing with following error:-
error: rpmdbNextIterator: skipping h#    1601 Header V4 RSA/SHA1 signature: BAD, key ID 2874ffbe
  • Why "rpm -qa" command is not showing installed packages?
  • rpm command hangs/hung
  • rpm database got corrupted

决议

  • Depending on the particular scenario, there are several different paths that correct this situation

Important: Before attempting to rebuild the rpm database, first refer to the following known issue for Red Hat Enterprise Linux 6 systems:

Update to nss-softokn 3.14.3-19 breaks RPM

1) Stale lock file cleanup - files needed for updating are being held open.

Note: There are two methods (1A & 1B) to correct this:

1A) Reboot system (preferred)

  1. The best course of action is to simply reboot the machine, as the system cleans up stale locks during the sysinit portion of boot. The cleanup occurs at this stage as the system is assured there is no process that would have a lock on the RPM database.

    # grep rpm /etc/rc.d/rc.sysinit
    rm -f /var/lib/rpm/__db* &> /dev/null

1B) Reboot not feasible (more risky than reboot)

  1. Delete all files in /var/spool/up2date

    # cd /var/spool/up2date
    # rm *
    # rm .*
  2. Ensure there are no processes with the RPM database files open. One way to do this is using lsof & ps as the root user:

    # ps -aux | grep -e rpm -e yum -e up2date
    # lsof | grep /var/lib/rpm
  3. If, and only if, there is no RPM database activity going on it is safe to delete the lock files.
    WARNING: If the system is in multi-user mode it is
    possible that a process may open the RPM database at any time.
    Therefore, the recommended method for clearing stale locks is the reboot
    which cleans up the locks prior to entering multi-user mode.

    # rm -f /var/lib/rpm/__db*


2) DB corruption recovery process - The RPM database has become corrupt and recovery is desired.

  1. As always it best to start by taking a backup before attempting to repair.

    # cd /var/lib
    # tar -zcvf /var/preserve/rpmdb-$(date +%Y-%m-%d_%H-%M-%S).tar.gz rpm

    Note: This tar backup can be used if the attempt to recover the RPM database has issues.

  2. Verify integrity of the Packages file:

    # cd /var/lib/rpm
    # rm -f __db* # to avoid stale locks
    # /usr/lib/rpm/rpmdb_verify Packages

    If the last command shown in method 2 returns without any error, then we can be sure about the integrity of the rpm database. You can also issue the following command to be sure of the success of the rpmdb_verify command.

    $ /usr/lib/rpm/rpmdb_verify Packages
    $ echo $?
    0

    A return value of 0 from echo $? means that the last command has been executed successfully.

  3. If the above verify reports success, go to step 6.

  4. If the above verify reports any errors, a dump and load of the database is required.

    # mv Packages Packages.orig
    # /usr/lib/rpm/rpmdb_dump Packages.orig | /usr/lib/rpm/rpmdb_load Packages
  5. Verify the newly loaded Packages file, as well as rpm output.

    # /usr/lib/rpm/rpmdb_verify Packages
    # rpm -qa >/dev/null # Validating there are no errors
    # rpm -qa # Validating list of installed RPMs
  6. If no errors and everything looks good, rebuild the RPM indexes

    # rpm -vv --rebuilddb
  7. Once again verify RPM database:

    # cd /var/lib/rpm
    # /usr/lib/rpm/rpmdb_verify Packages

Note: If the above recovery steps fail or throw errors, restoring /var/lib/rpm directory from a recent system backup may be your best option. Remember to not overwrite the tar backup as it may still be valuable.

Note: If you have another machine having the exactly same installed package set, you can rebuild the rpm db with Packages file on the machine.

Note: If you have a rpm database in other directory except for /var/lib/rpm and it's corrupted, you will need to do the same things to the rpm database, not one in /var/lib/rpm. The rpm command has --root option to specify the root directory for the rpm database. Especially, please take care of the rpm -vv --rebuilddb command to rebuild the rpm database. For example, if you are using /opt/var/lib/rpm for a directory including rpm database, run this command rpm -vv --rebuilddb --root /opt.


3.) Other resources:

根源

  • rpm database corruption

诊断步骤

  • yum update fails with the following:
[root@localhost ~]# yum update
rpmdb: PANIC: fatal region error detected; run recovery
error: db3 error(-30974) from dbenv->open: DB_RUNRECOVERY: Fatal error, run database recovery
error: cannot open Packages index using db3 - (-30974)
error: cannot open Packages database in /var/lib/rpm
CRITICAL:yum.main: Error: rpmdb open failed
[root@localhost ~]# yum clean all
rpmdb: PANIC: fatal region error detected; run recovery
error: db3 error(-30974) from dbenv->open: DB_RUNRECOVERY: Fatal error, run database recovery
error: cannot open Packages index using db3 - (-30974)
error: cannot open Packages database in /var/lib/rpm
CRITICAL:yum.main: Error: rpmdb open failed
  • rpm shows damaged header instances:
$ rpm -Va
error: rpmdb: damaged header instance #<header number> retrived, skipping
error: rpmdb: damaged header instance #<header number> retrived, skipping
(above message repeated ad infinitum)
  • rpm commands terminate with the error below:
rpmdb: unable to join the environment
error: db3 error(11) from dbenv->open: Resource temporarily unavailble
error: cannot open Packages index using db3 - Resource temporarily unavailable (11)
error: cannot open Packages database in /var/lib/rpm
  • rpm and yum commands return the following:
$ rpm -qa
...
rpmdb: Lock table is out of available locker entries
error: db4 error(22) from db->close: Invalid argument

How to rebuild RPM database on a Red Hat Enterprise Linux system?的更多相关文章

  1. SQL Server on Red Hat Enterprise Linux——RHEL上的SQL Server(全截图)

    本文从零开始一步一步介绍如何在Red Hat Enterprise Linux上搭建SQL Server 2017,包括安装系统.安装SQL等相关步骤和方法(仅供测试学习之用,基础篇). 一.   创 ...

  2. SQL Server on Red Hat Enterprise Linux

    本文从零开始一步一步介绍如何在Red Hat Enterprise Linux上搭建SQL Server 2017,包括安装系统.安装SQL等相关步骤和方法(仅供测试学习之用,基础篇). 一.   创 ...

  3. 在Red Hat Enterprise Linux 5 64-bit安装oracle11g r2

    网上这种文档一搜就一堆,没别的目的,刚接触oracle为了加深理解记忆.只要是跟我的版本一样操作系统和oracle软件,按照步骤肯定可以成功安装 在虚拟机上安装Red Hat Enterprise L ...

  4. ORACLE Install (10g r2) FOR Red Hat Enterprise Linux Server release 5.5 (64 bit) (转)

    OS Info----------# cat /etc/redhat-releaseRed Hat Enterprise Linux Server release 5.5 (Tikanga)# cat ...

  5. Deploy Oracle 10.2.0.5 on Red Hat Enterprise Linux 6.4

    一.Linux系统安装和配置 1.安装系统时选Desktop 2.设置eth0网卡为静态IP,加入子网掩码,网关,DNS.并配置自己主动启动 3.改动/etc/hosts.加入主机名和相应IP 4.禁 ...

  6. [转] KVM storage performance and cache settings on Red Hat Enterprise Linux 6.2

    Almost one year ago, I checked how different cache settings affected KVM storage subsystem performan ...

  7. Red Hat Enterprise Linux 6上安装Oracle 11G(11.2.0.4.0)缺少pdksh包的问题

    RHEL 6上安装Oracle 11G警告缺少pdksh包 前言 相信很多刚刚接触学习Oracle的人,在RHEL6上安装11.2.0.3 or 11.2.0.4这两个版本的时候, 都遇到过先决条件检 ...

  8. Deploy Oracle 10.2.0.5 DataGuard on Red Hat Enterprise Linux 6.4

    系统:Red Hat Enterprise Linux 6.4 数据库:Oracle 10.2.0.5.0 Patch Set 4 主机:10dg1 192.168.1.91 10dg2192.168 ...

  9. Red Hat Enterprise Linux Server(RHEL) yum安装软件时This system is not registered with RHN. RHN support will be disabled. 的解决方法(转)

    新安装了redhat6.5.安装后,登录系统,使用yum update 更新系统.提示: This system is not registered to Red Hat Subscription M ...

随机推荐

  1. 入园的第一篇--where、where

    这篇是入园的第一篇随便,后面我会将自己几年前写的博文都转到这里.哎,其实说到博文的事情,我就很郁闷,甚至有些恼火,后面我会详细说说这中间的过程,也许能帮助某些人避免遇到类似的事情.突然想起<西游 ...

  2. 阿里云OSS Web端直传 服务器签名C#版

    最近用到队里OSS的文件上传,然后阿里官方给的四个服务器签名有Java PHP Python Go四个版本,就是没C#(话说写个C#有多难?) 百度了一下好像也没有,既然这样只能自己动手照着Java版 ...

  3. 在另一个文本框显示input file选择的文件名字

    javascript 获取文件域 (type=file) 的完整路径一直是很麻烦的问题,问题主要出在一些浏览器基于安全性考虑而不能正常获取到文件域中选中图片的决对路径,尤其一些基于webkit的浏览器 ...

  4. python Tk()生成的桌面的具体设置方法

    rom tkinter import * root = Tk() root['height'] = 300 #设置高 root['width'] = 500 #设置宽 root.title('魔方小站 ...

  5. Selenium2+python自动化66-装饰器之运行失败截图【转载】

    前言 对于用例失败截图,很多小伙伴都希望在用例执行失败的时候能自动截图,想法是很好的,实现起来并不是那么容易. 这里分享下我的一些思路,当然目前还没找到完美的解决方案,我的思路是用装饰器去解决,希望有 ...

  6. Selenium2+python自动化32- 测试报告的易读性【转载】

    前言 前一篇已经介绍了报告的生成方法,本篇小编优化一下测试报告,使测试报告便于大多数阅读.虽然在我们在测试用例开发时为每个用例添加了注释,但测试报告一般是给非测试人员阅读的,如果能在报告中为每一个测试 ...

  7. laravel获取checkbox值的小技巧

    以前老是用三元运算符来判断,现在有了更好的方法: 1.html代码 <input type="hidden" name="approved" value= ...

  8. 微信商户现金红包api php

    微信开发文档: 现金红包:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_5 裂变红包:https:// ...

  9. UVA 11636.Hello World!-水题

    Hello World! Time limit: 1.000 seconds When you first made the computer to print the sentence “Hello ...

  10. HDU 2552 三足鼎立(数学函数)

    /* <耶律javac++>欲找出三人所在逐个击破, 现在他发现威士忌的位置s,天外来客的位置u, 不过很难探查到亦纷菲v所在何处,只能知道三人满足关系: arctan(1/s) = ar ...