RPM包管理软件使用详解
RPM(RPM Package Manager):由Red Hat公司开发的一个Linux软件包安装与管理程序。它的作用是将编译好的应用程序的各组成文件打包成一个或几个程序包文件,从而更方便地实现程序包的安装、升级、卸载和查询等管理操作。 由于软件包之间存在着依赖关系,通常是A依赖于B,而B又依赖于C,甚至C又可能依赖于A造成循环依赖。而通过包管理器可以很好地解决软件之间的依赖关系。
1、 各包管理器应用的平台:
yum:rhel系列系统上rpm包管理器的前端工具;
apt-get (apt-cache):deb包管理器的前端工具;
zypper:suse的rpm管理器前端工具;
dnf:Fedora 22+系统上rpm包管理器的前端工具;新一代,提升了包括用户体验,内存占用,依赖分析,运行速度等多方面的内容。
2、 RPM软件包的命名规则:
命令规则:Name-Version-Relase.Arch.rpm
2.1 Name:软件的名称
2.2 Version:版本
包括major.minor.release
major:主版本号,重大版本分支 minor:次版本号,重大功能改版 release:改造号,修复BUG
2.3 Release(有时也为release.os):
rpm自身释放的发行号(次数),通常是编译的次数。与程序源码的发行号无关,仅用于标识对rpm包不同制作的修订;同时,release还包含此包适用的OS
2.4 Arch:适用平台
i386, x64(amd64), ppc, noarch(与平台无关)
2.5 .rpm或.src.rpm:RPM包类型后缀
- .rpm是编译好的二进制包,可用rpm命令直接安装;
- .src.rpm表示是源码包。
软件包拆包后分为主包和支包
- 主包:name-VERSION-release.arch.rpm
- 支包:name-function-VERSION-release.arch.rpm function:devel(开发组件), utils(工具组件), libs(库文件)...
3、 软件包的组成:
- 3.1 二进制程序文件
目录:/bin,/sbin,/usr/bin,/usr/sbin,/usr/local/bin,/usr/local/sbin
- 库文件
目录:/lib,/lib64,/usr/lib,/usr/lib64,/usr/local/lib,/usr/local/lib64
- 配置文件:
目录:/etc
- 帮助文件:
目录:/usr/share/
4、 RPM包的获取途径:
4.1、系统发行版的光盘或官方的文件服务器(或镜像站点):
mirrors.aliyun.com, mirrors.sohu.com, mirrors.163.com
4.2、项目的官方站点
4.3、第三方组织:
(a) EPEL源 (b) 搜索引擎 pkgs.org rpmfind.net rpm.pbone.net
4.4、自动动手编译
注:从第三方组织获取软件包后,建议检查其来源合法性及包的完整性(-V|--verify)
4.5 RPM包加密及验证流程:
- 加密流程:
包制造者先使用单向加密算法,提取出包的特征码。特征码是定长的。 制造者用私钥加密这段特征码,附加到文件后面。这段加密的特征码就是数字签名。
- 验证合法性流程:
拿到制造者的公钥解密数字签名(会得到一个特征码),如果能解密则软件为制造者制造的包。 用同样的公钥解密软件包,得到的特征码和数字签名的特征码比较,只要一样,文件的完整性得到了验证。
上面的步骤中,最关键的是如何获得一个合法的公钥。
5. RPM包的管理:
包含以下部分:安装、卸载、升级、查询和校验、数据库维护
5.1 rpm命令格式:
rpm [OPTIONS] [PACKAGE_FILE]
5.2 GENERAL OPTIONS
These options can be used in all the different modes.
在所有不同的模式下都可以使用的选项
-?, --help Print a longer usage message then normal.
usage:[ˈju:sɪdʒ] 使用、用法
--version Print a single line containing the version number of rpm being used.
--quiet Print as little as possible, normally only error messages will be displayed.
-v Print verbose information, normally routine progress messages will be displayed.
verbose [vɜ:ˈbəʊs] 冗长的,详细的
routine [ru:ˈti:n] 常规的
-vv Print lots of ugly debugging information.
5.3 安装、升级选项
In these options, PACKAGE_FILE can be either rpm binary file or ASCII package manifest (see PACKAGE SELECTION OPTIONS),
and may be specified as an ftp or http URL, in which case the package will be downloaded before being installed.
See FTP/HTTP OPTIONS for information on rpm's internal ftp and http client support.
# 在这个选项中,PACKAGE_FILE可以是二进制的RPM软件包文件或者ASCII程序包清单。也可以明确指定一个FTP或http地址,在这种模式下,软件包会在开始安装前下载好。
rpm {-i|--install} [install-options] PACKAGE_FILE ... Install a new package.# 新安装软件包
rpm {-U|--upgrade} [install-options] PACKAGE_FILE ... upgrade or install the package currently installed to a new version.
All other versions of the package will removed afte the new package is installed. # 升级、安装一个之前已经安装旧版本的软件包。之前的版本会在安装结束后删除。之前的软件包可以没安装过。
rpm {-F|--freshen} [install-options] PACKAGE_FILE ... upgrade package , but only ones of which an earlier version is intalled # 升级软件包,之前须安装过。
5.3.1 Install options 安装选项
Usage:
rpm {-i|--install} [install-options] PACKAGE_FILE ...
options:
-h, --hash Print 50 hash marks as the package archive is unpacked. Use with -v|--verbose for a nicer display. 输出50个哈希标志表示进度
--test Do not install the package, simply check for and report potential conflicts.
# 不安装,检查并报告潜在的冲突
potential [pəˈtenʃəl] 潜在的
conflict [ˈkɔnflikt] 冲突
--replacepkgs Install the packages even if some of them are already installed on this system.
# 安装软件包,即使系统中已经安装过。
--noscripts
--nopre
--nopost
--nopreun
--nopostun
Don't execute the scriptlet of the same name. The --noscripts option is equivalent to --nopre --nopost --nopreun --nopostun and turns off the execution of the corresponding %pre, %post, %preun, and %postun scriptlet(s).
execution [ˌeksiˈkju:ʃən] 执行
corresponding [ˌkɔrisˈpɔndiŋ] 相应的
# 安装时不执行任何脚本。--noscripts等同于--nopre --nopost --nopreun --nopostun,它会关闭%pre, %post, %preun, and %postun所对应的脚本。
# preinstall:安装过程开始之前运行的脚本,%pre , --nopre
# postinstall:安装过程完成之后运行的脚本,%post , --nopost
# preuninstall:卸载过程真正开始执行之前运行的脚本,%preun, --nopreun
# postuninstall:卸载过程完成之后运行的脚本,%postun , --nopostun
5.3.2 upgrade and freshen options 升级选项
Usage
rpm {-U|--upgrade} [install-options] PACKAGE_FILE ...
rpm {-F|--freshen} [install-options] PACKAGE_FILE ...
Options
--oldpackage Allow an upgrade to replace a newer package with an older one.
# 允许升级替换成较旧的软件包,即回滚
--force Same as using --replacepkgs, --replacefiles, and --oldpackage.
# 和使用--replacepkgs, --replacefiles,--oldpackage效果相同
--replacepkgs Install the packages even if some of them are already installed on this system.
# 重新安装
--replacefiles Install the packages even if they replace files from other, already installed packages.
# 安装软件包,即使其中有些软件包已经被安装到了系统中。
注意:
- 不要对内核做升级操作;Linux 支持多内核版本并存,因此,可以直接安装新版本内核
- 如果原程序包的配置文件安装后曾被修改,升级时,新版本的提供的同一个配置文件并不会直接覆盖老版本的配置文件,而把新版本的文件重命名(FILENAME.rpmnew)
5.4 ERASE OPTIONS 卸载选项
ERASE [ɪˈreɪz] 清除
Usage:
rpm {-e|--erase} [--allmatches] [--nodeps] [--noscripts] [--notriggers] [--test] PACKAGE_NAME ...
Options:
The following options may also be used:
--allmatches Remove all versions of the package which match PACKAGE_NAME. Normally an error is issued if PACKAGE_NAME matches multiple packages.
match [mætʃ] 匹配
issue [ˈɪʃu:] 问题
multiple [ˈmʌltipl] 多个
# 删除所有匹配到的软件包,通常如果匹配到多个软件包将导致错误。
--nodeps Don't check dependencies before uninstalling the packages.
# 不检查依赖关系
dependencies [dɪ'pendənsɪz] 附属
--noscripts 同install命令
--test 同install命令,dry run模式
### 5.5 QUERY OPTIONS 查询选项
Usage:
rpm {-q|--query} [select-options] [query-options]
select-options
PACKAGE_NAME Query installed package named PACKAGE_NAME
# 查询指定软件包是否安装
Query [ˈkwɪəri] 查询
-a, --all Query all installed packages.
# 查询所有已安装的包
-f, --file FILE Query package owning FILE.
# 查询文件属于哪个安装包
-p, --package PACKAGE_FILE
# 用于实现对未安装的程序包执行查询操作
--whatprovides CAPABILITY
Query all packages that provide the CAPABILITY capability.
provide [prəˈvaid] 提供
capability [ˌkeɪpəˈbɪlɪti:] 能力
# 查询CAPABILITY由哪个包提供
--whatrequires CAPABILITY
Query all packages that require CAPABILITY for proper functioning.
require [riˈkwaiə] 要求、需求
proper [ˈprɔpə] 特有的 function [ˈfʌŋkʃn] 功能
# 查询指定的CAPABILITY被哪个包所依赖
query-options
--changelog Display change information for the package.
# 显示包的修改信息
-l, --list List files in package
# 显示包的文件列表
-i, --info Display package information, including name, version, and description.
# 显示包的信息,包括名称、版本和描述。
-c, --configfiles
List only configuration files (implies -l).
# 显示配置文件(包含-l选项)
-d, --docfiles
List only documentation files (implies -l).
# 显示文档文件(包含-l选项)
--provides List capabilities this package provides.
# 显示软件提供的CAPABILITIES
-R, --requires List capabilities on which this package depends.
# 列出软件包依赖的其他软件包。
depend [dɪˈpend] 依赖
--scripts List the package specific scriptlet(s) that are used as part of the installation and uninstallation processes.
# 列出软件包特有的在安装和卸载过程中用到的脚本。
specific [spiˈsifik] 特有的
5.6 VERIFY OPTIONS 校验选项
Usage:
rpm {-V|--verify} [select-options] [verify-options]
The package selection options are the same as for package querying (including package manifest files as arguments).Other options unique to verify mode are:
# 包选择选项与查询选项相同,包括以包清单作为参数的选项。校验选项独特的参数如下:
VERIFY [ˈverɪfaɪ] 校验
unique /juˈniːk/ 独一无二的
verify-options it’s not a important option.
--nodeps
Don't verify dependencies of packages.
# 不检查依赖
--nodigest
Don't verify package or header digests when reading.
# 不验证摘要
--nofiles
Don't verify any attributes of package files.
# 不验证包文件的属性
--noconfig
Don't verify config files.
# 不验证配置文件
--noghost
Don't display ghost files.
# 不显示ghost文件
--noscripts
Don't execute the %verifyscript scriptlet (if any).
# 不执行校验脚本,假如有的话。
--nosignature
Don't verify package or header signatures when reading.
signatures /'signətʃə/ 签名
# 读取时,不验证包或头的签名
校验时,每个字符的意义
S file Size differs
# 文件大小发生改变
M Mode differs (includes permissions and file type)
#权限发生改变
5 digest (formerly MD5 sum) differs
MD5码发生改变
D Device major/minor number mismatch
主次设备号不匹配
L readLink(2) path mismatch
readLink路径发生改变
U User ownership differs
属主发生改变
G Group ownership differs
属组发生改变
T mTime differs
时间戳发生改变
P caPabilities differ
capabilities发生改变
5.7 获取并导入信任的包制作者的密钥:
-
获取:
mirrors.aliyun.com, mirrors.sohu.com, mirrors.163.com
网站页面下面有数字签名,可获取地址之后下载到需要签名的主机上。
-
安装:
Centos系列系统安装证书:rpm --import PACKAGE_FILE
-
验正:
(1) 安装此组织签名的程序时,会自动执行验正; (2) 手动验正:rpm -K PACKAGE_FILE CentOS 7 的数字签名位于 /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 不同版本的数字签名只是后面的数字不同。
5.8 RPM数据库工具
rpmdb - RPM Database Tool
rpm管理器数据库路径:/var/lib/rpm/
查询操作:通过/var/lib/rpm/进行
获取帮助方式:
CentOS 6:man rpm
CentOS 7:man rpmdb
Usage:
rpm {--initdb|--rebuilddb} [-v] [--dbpath DIRECTORY] [--root DIRECTORY]
Options:
Use --initdb to create a new database if one doesn't already exist (existing database is not overwritten), use --rebuilddb to rebuild the database indices from the installed package headers.
indices /ˈɪndɪsiːz/ 目录(index的复数)
--initdb # 当前没有数据库时创建新的数据库(不覆盖现有数据库)
--rebuilddb # 读取当前系统所有已安装的程序包进行数据库重新构建
6. 使用示例:
6.1 安装:
不下载RPM软件包,输入软件包地址安装软件包。
[root@promote ~]# rpm -ivh https://mirrors.aliyun.com/centos/7.3.1611/updates/x86_64/Packages/zsh-5.0.2-25.el7_3.1.x86_64.rpm
获取https://mirrors.aliyun.com/centos/7.3.1611/updates/x86_64/Packages/zsh-5.0.2-25.el7_3.1.x86_64.rpm
准备中... ################################# [100%]
正在升级/安装...
1:zsh-5.0.2-25.el7_3.1 ################################# [100%]
[root@promote ~]# rpm -ivh firefox-45.5.0-1.el7.centos.x86_64.rpm #安装firefox,显示进度、显示简略信息
准备中... ################################# [100%]
正在升级/安装...
1:firefox-45.5.0-1.el7.centos ################################# [100%]
[root@promote ~]# rpm -ivh --test bash-4.2.46-21.el7_3.x86_64.rpm #测试软件包的冲突和依赖关系
准备中... ################################# [100%]
file /usr/bin/bash from install of bash-4.2.46-21.el7_3.x86_64 conflicts with file from package bash-4.2.46-19.el7.x86_64
[root@promote ~]# rpm -ivh --replacepkgs firefox-45.5.0-1.el7.centos.x86_64.rpm
#重新安装之前已经安装过的软件包
准备中... ################################# [100%]
正在升级/安装...
1:firefox-45.5.0-1.el7.centos ################################# [100%]
[root@promote ~]# rpm -Uvh firefox-45.7.0-2.el7.centos.x86_64.rpm #升级软件包,显示进度、显示简略信息
准备中... ################################# [100%]
正在升级/安装...
1:firefox-45.7.0-2.el7.centos ################################# [ 50%]
正在清理/删除...
2:firefox-45.6.0-1.el7.centos ################################# [100%]
[root@promote ~]# rpm -Uvh --oldpackage firefox-45.6.0-1.el7.centos.x86_64.rpm #回滚至旧版本
准备中... ################################# [100%]
正在升级/安装...
1:firefox-45.6.0-1.el7.centos ################################# [ 50%]
正在清理/删除...
2:firefox-45.7.0-2.el7.centos ################################# [100%]
6.2 卸载:
[root@promote ~]# rpm -evh firefox #删除firefox,显示进度、显示简略信息
准备中... ################################# [100%]
正在清理/删除...
1:firefox-45.5.0-1.el7.centos ################################# [100%]
[root@promote ~]# rpm -evh --allmatches firefox #删除匹配到的firefox软件包。显示进度、简略信息
准备中... ################################# [100%]
正在清理/删除...
1:firefox-45.5.0-1.el7.centos ################################# [100%]
[root@promote ~]# rpm -evh --test firefox #测试卸载过程中是否有冲突或依赖关系
准备中... ################################# [100%]
[root@promote ~]#
6.3 查询
范例
-qi PACKAGE, -qf FILE, -qc PACKAGE, -ql PACKAGE, -qd PACKAGE
-qpi PACKAGE_FILE, -qpl PACKAGE_FILE, -qpc PACKAGE_FILE, ...
示例:
[root@promote ~]# rpm -q ./bash-4.2.46-21.el7_3.x86_64.rpm #查询软件包是否安装
未安装软件包 ./bash-4.2.46-21.el7_3.x86_64.rpm
[root@promote ~]# rpm -qa | grep "bash" #在所有已经安装的包中查找bash
bash-4.2.46-19.el7.x86_64
bash-completion-2.1-6.el7.noarch
[root@centos6 ~]# rpm -qi bash #查询已安装包的信息
Name : bash Relocations: (not relocatable)
Version : 4.1.2 Vendor: CentOS
Release : 48.el6 Build Date: 2017年03月23日 星期四 08时17分20秒
Install Date: 2017年06月01日 星期四 23时26分31秒 Build Host: c1bm.rdu2.centos.org
Group : System Environment/Shells Source RPM: bash-4.1.2-48.el6.src.rpm
Size : 3142529 License: GPLv3+
Signature : RSA/SHA1, 2017年03月23日 星期四 22时59分39秒, Key ID 0946fca2c105b9de
Packager : CentOS BuildSystem <http://bugs.centos.org>
URL : http://www.gnu.org/software/bash
Summary : The GNU Bourne Again shell
Description :
The GNU Bourne Again shell (Bash) is a shell or command language
interpreter that is compatible with the Bourne shell (sh). Bash
incorporates useful features from the Korn shell (ksh) and the C shell
(csh). Most sh scripts can be run by bash without modification.
[root@promote lib]# rpm -qf /lib/libm.so.6 #查询文件属于哪个安装包
glibc-2.17-157.el7_3.2.i686
[root@promote lib]# rpm -qc bash #查询已安装软件的配置文件
/etc/skel/.bash_logout
/etc/skel/.bash_profile
/etc/skel/.bashrc
[root@promote ~]# rpm -qd firefox #查询已安装软件的文档文件
/usr/lib64/firefox/LICENSE
/usr/share/man/man1/firefox.1.gz
[root@promote ~]# rpm -qpR bash-4.2.46-21.el7_3.x86_64.rpm
#查询未安装的软件包的依赖关系(安装软件包时,解决依赖关系的重要命令)
/bin/sh
config(bash) = 4.2.46-21.el7_3
libc.so.6()(64bit)
libc.so.6(GLIBC_2.11)(64bit)
libc.so.6(GLIBC_2.14)(64bit)
libc.so.6(GLIBC_2.15)(64bit)
libc.so.6(GLIBC_2.2.5)(64bit)
libc.so.6(GLIBC_2.3)(64bit)
libc.so.6(GLIBC_2.3.4)(64bit)
libc.so.6(GLIBC_2.4)(64bit)
libc.so.6(GLIBC_2.8)(64bit)
libdl.so.2()(64bit)
libdl.so.2(GLIBC_2.2.5)(64bit)
libtinfo.so.5()(64bit)
rpmlib(BuiltinLuaScripts) <= 4.2.2-1
rpmlib(CompressedFileNames) <= 3.0.4-1
rpmlib(FileDigests) <= 4.6.0-1
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
rtld(GNU_HASH)
rpmlib(PayloadIsXz) <= 5.2-1
[root@centos6 ~]# rpm -ql zsh |more #查询已安装的包生成的文件
/bin/zsh
/etc/skel/.zshrc
/etc/zlogin
/etc/zlogout
/etc/zprofile
/etc/zshenv
......
[root@promote ~]# rpm -qR zsh #查询已安装的软件包的依赖关系
[root@promote ~]# rpm -qpl bash-4.2.46-21.el7_3.x86_64.rpm #查询未安装软件包的文件列表
[root@promote ~]# rpm -q --provides bash #查询已经安装软件包提供的能力
/bin/bash
/bin/sh
bash = 4.2.46-19.el7
bash(x86-64) = 4.2.46-19.el7
config(bash) = 4.2.46-19.el7
[root@promote ~]# rpm -q --scripts bash #查询已经安装软件包的脚本信息
postinstall scriptlet (using <lua>):
nl = '\n'
sh = '/bin/sh'..nl
bash = '/bin/bash'..nl
f = io.open('/etc/shells', 'a+')
if f then
local shells = nl..f:read('*all')..nl
if not shells:find(nl..sh) then f:write(sh) end
if not shells:find(nl..bash) then f:write(bash) end
f:close()
end
postuninstall scriptlet (using <lua>):
-- Run it only if we are uninstalling
if arg[2] == "0"
then
t={}
for line in io.lines("/etc/shells")
do
if line ~= "/bin/bash" and line ~= "/bin/sh"
then
table.insert(t,line)
end
end
f = io.open("/etc/shells", "w+")
for n,line in pairs(t)
do
f:write(line.."\n")
end
f:close()
end
[root@promote ~]#
对于未安装的软件包的查询操作,需先下载软件包。查询时需指定软件包。
[root@promote ~]# rpm -qpi bash-4.2.46-21.el7_3.x86_64.rpm #查询未安装软件包的信息
Name : bash
Version : 4.2.46
Release : 21.el7_3
Architecture: x86_64
Install Date: (not installed)
Group : System Environment/Shells
Size : 3663714
License : GPLv3+
Signature : RSA/SHA256, 2016年12月07日 星期三 08时11分28秒, Key ID 24c6a8a7f4a80eb5
Source RPM : bash-4.2.46-21.el7_3.src.rpm
Build Date : 2016年12月07日 星期三 07时21分54秒
Build Host : c1bm.rdu2.centos.org
Relocations : (not relocatable)
Packager : CentOS BuildSystem <http://bugs.centos.org>
Vendor : CentOS
URL : http://www.gnu.org/software/bash
Summary : The GNU Bourne Again shell
Description :
The GNU Bourne Again shell (Bash) is a shell or command language
interpreter that is compatible with the Bourne shell (sh). Bash
incorporates useful features from the Korn shell (ksh) and the C shell
(csh). Most sh scripts can be run by bash without modification.
[root@promote ~]#
6.4 校验
[root@promote ~]# rpm -V zsh #校验软件包的完整性
[root@centos6 ~]# rpm -ivh zsh-4.2.6-10.el5_11.x86_64.rpm
warning: zsh-4.2.6-10.el5_11.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID e8562897: NOKEY
Preparing... ########################################### [100%]
1:zsh ########################################### [100%]
[root@promote ~]# # rpm -Va #校验所有软件包
S.5....T. c /etc/sysconfig/authconfig #大小、MD5、时间戳发生改变
遗漏 /var/run/wpa_supplicant #缺失
S.5....T. c /etc/yum/pluginconf.d/langpacks.conf #大小、MD5、时间戳发生改变
....L.... c /etc/pam.d/fingerprint-auth # readLink路径发生改变
[root@centos6 ~]# rpm -qp zsh-4.2.6-10.el5_11.x86_64.rpm #通过软件包查询查询是否通过校验
warning: zsh-4.2.6-10.el5_11.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID e8562897: NOKEY
zsh-4.2.6-10.el5_11.x86_64
[root@centos6 ~]# rpm -K zsh-4.2.6-10.el5_11.x86_64.rpm #查询软件包是否通过校验
zsh-4.2.6-10.el5_11.x86_64.rpm: (SHA1) DSA sha1 md5 (GPG) NOT OK (MISSING KEYS: GPG#e8562897)
#加粗部分提示缺少密钥
[root@centos6 ~]# wget https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-5 #下载密钥
--2017-06-13 19:00:27-- https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-5
正在解析主机 mirrors.aliyun.com... 115.28.122.210
正在连接 mirrors.aliyun.com|115.28.122.210|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1504 (1.5K) [application/octet-stream]
正在保存至: “RPM-GPG-KEY-CentOS-5”
100%[======================================================================================>] 1,504 --.-K/s in 0s
2017-06-13 19:00:27 (110 MB/s) - 已保存 “RPM-GPG-KEY-CentOS-5” [1504/1504])
[root@centos6 ~]# rpm --import RPM-GPG-KEY-CentOS-5 #安装密钥
[root@centos6 ~]# rpm -K zsh-4.2.6-10.el5_11.x86_64.rpm #校验安装包
zsh-4.2.6-10.el5_11.x86_64.rpm: (sha1) dsa sha1 md5 gpg OK
[root@centos6 ~]#
6.5 构建数据库
[root@centos6 ~]# cd /var/lib/rpm
[root@centos6 rpm]# ls
Basenames Dirnames Group Name Packages Provideversion Requirename Sha1header Triggername
Conflictname Filedigests Installtid Obsoletename Providename Pubkeys Requireversion Sigmd5
[root@centos6 rpm]# rm -rf * #删除所有rpm数据库文件
[root@centos6 rpm]# ls
[root@centos6 rpm]# rpm --initdb -v #重建新的rpm数据库文件
[root@centos6 rpm]# ls
__db.001 __db.002 __db.003 __db.004 Packages
[root@centos6 rpm]# rpm --rebuilddb #重新构建rpm数据库
[root@centos6 rpm]# ls
Packages