CentOS下yum Error 21问题及解决方案。

执行yum update时出现:

error: db5 error(21) from dbenv->open: Is a directory
error: cannot open Packages index using db5 - Is a directory (21)
error: cannot open Packages database in /var/lib/rpm
CRITICAL:yum.main:

Error: rpmdb open failed

原因是RPM数据库损坏,重建即可。

执行:
cd /var/lib/rpm/
for i in `ls | grep 'db.'`;do mv $i $i.bak;done

rpm --rebuilddb

yum clean all