Linux系统程序包管理工具-RPM


一、rpm是什么
 
RPM 是RPM Package Manager(RPM软件包管理器)的缩写,这一文件格式名称虽然打上了RedHat的标志,但是其原始设计理念是开放式的。RPM包管理器(RPM)是一个强大的命令行驱动的包管理系统能够安装、卸载、验证、查询和更新计算机软件包。每个软件包包括存档的文件连同包和它的版本信息,描述等。还有一个库API,允许高级开发人员来管理
 
二、程序的组成部分
 
程序的组成部分:
 
编译之前:源代码
编译文件:
二进制程序
库文件
配置文件
帮助文件(手册、文档)
二进制程序:/bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin, /usr/local/sbin, /opt/bin, /opt/sbin
库文件:/lib, /lib64, /usr/lib, /usr/lib64, /usr/local/lib, /usr/local/lib64
配置文件:/etc, /etc/DIR, /usr/local/{etc,conf}
帮助文件:/usr/share/man, /usr/share/doc, /usr/local/share/man
 
注意:有些特殊的应用程序可能会将可执行文件放置在libexec目录;
 
三、rpm包命名格式:
rpm包命名格式:
appname-VERSION-RELEASE.ARCH.rpm
VERSION:
major:主版本号
minor:此版本号
release:发行号
RELEASE:包自身的修订号:有时候还会包含适用于os信息:比如bash-4.3.2-2.centos.x86_64.rpm
ARCH:适用的平台
x86:i386,i486,i586,i686
x86_64,adm64:x86 64bits
powerpc:ppc
noarch:跟平台无关
 
四、分包机制
 
想象一种场景:testapp有30种功能,其中有10种常用,有6次常用,余下的14种极少用;所以rpm包制作者会把一个程序的每个功能制作成一个rpm包,他们都依赖主包。
 
例如:
核心包,主包:命名与原项目名称一致;
bash-4.3.2-2.centos6.x86_64.rpm
 
子包(支包):命令为源项目名称后附加分支包中的文件提供的功能组成;
bash-devel-4.3.2-2.centos6.x86_64.rpm
 
程序包的获取路径:
 
1、系统的发行光盘镜像或官方站点(或站点镜像服务器)
挂载光盘:
mount -r /dev/cdrom /media/cdrom
官方站点,镜像:
mirrors.sohu.com
mirrors.163.com
mirrors.aliyun.com
2、程序包的官方站点
 
3、第三方组织:epel
 
4、搜索引擎
http://rpmfind.net
http://rpm.pbone.net
http://pkgs.org
 
建议:安装之前要验正的其合法性
 
来源合法
包的完整性
五、centos系统上的程序rpm包管理
安装、升级、卸载、查询、校验
 
5.1 安装
rpm {-i|--install} [install-options] PACKAGE_FILE1..
-i:安装
 
# rpm -i zsh-4.3.10-7.el6.x86_64.rpm
# rpm -q zsh#rpm -q为查询次包是否安装,在后面的查询中会讲到。
zsh-4.3.10-7.el6.x86_64
-h:hash, 以#来表示安装进度
 
# rpm -ih zsh-4.3.10-7.el6.x86_64.rpm 
########################################### [100%]
########################################### [100%]
-v,--verbose:显示安装过程中的详细信息   
 
# rpm -ivh zsh-4.3.10-7.el6.x86_64.rpm 
Preparing...########################################### [100%]
   1:zsh########################################### [100%]
-vv:显示更多的详细信息
 
# rpm -ivvh zsh-4.3.10-7.el6.x86_64.rpm
安装时常用的组合:-ivh,-ivvh
--test:不执行真正的安装过程,而仅报告依赖关系及冲突
 
# rpm -ivh --test zsh-4.3.10-7.el6.x86_64.rpm 
Preparing...########################################### [100%]
程序包之间存在依赖关系
由众多目的单一的小程序组成:结果程序包之间存在相关性;
--nodeps:忽略依赖关系:副作用:安装成功,但未必能够成功运行
 
# rpm -ivh php-5.3.3-38.el6.x86_64.rpm 
error: Failed dependencies:
php-cli(x86-64) = 5.3.3-38.el6 is needed by php-5.3.3-38.el6.x86_64
php-common(x86-64) = 5.3.3-38.el6 is needed by php-5.3.3-38.el6.x86_64
# rpm -ivh --nodeps php-5.3.3-38.el6.x86_64.rpm
Preparing...########################################### [100%]
   1:php########################################### [100%]
--replacepkgs:覆盖安装:重新安装并覆盖原有的文件
 
# rpm -ivh zsh-4.3.10-7.el6.x86_64.rpm 
Preparing...########################################### [100%]
package zsh-4.3.10-7.el6.x86_64 is already installed
# rpm -ivh --replacepkgs zsh-4.3.10-7.el6.x86_64.rpm 
Preparing...########################################### [100%]
   1:zsh########################################### [100%]
--force:强制安装
 
# rpm -ivh zsh-4.3.10-7.el6.x86_64.rpm 
Preparing...########################################### [100%]
package zsh-4.3.10-7.el6.x86_64 is already installed
# rpm -ivh --force zsh-4.3.10-7.el6.x86_64.rpm 
Preparing...########################################### [100%]
   1:zsh########################################### [100%]
5.2 升级
-U:升级或安装
 
# rpm -q zsh
zsh-4.3.10-7.el6.x86_64
# rpm -Uvh --nodeps zsh-5.1.1-3.fc24.x86_64.rpm 
warning: zsh-5.1.1-3.fc24.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 81b46521: NOKEY
Preparing...########################################### [100%]
   1:zsh########################################### [100%]
# 此处使用--nodeps的原因是这个版本需要很多依赖关系,所以忽略依赖关系,在生产环境中升级需要安装依赖关系后在升级。
-F:升级
组合:-Uvh,-Fvh
--test
--nodeps
--force 
--oldpackage:降级到旧版本;
 
# rpm -q zsh
zsh-5.1.1-3.fc24.x86_64
# rpm -Uvh --oldpackage /misc/cd/Packages/zsh-4.3.10-7.el6.x86_64.rpm 
Preparing...########################################### [100%]
   1:zsh########################################### [100%]
# rpm -q zsh
zsh-4.3.10-7.el6.x86_64
注意:一定不要对内核升级:Linux允许多内核共存,所以可以直接安装多个不同版本内核;
注意:如果程序包的配置文件安装后曾被修改,升级时,新版本的文件不会覆盖老版本的配置文件,而把新版本的配置文件重命名(加后缀.rpmnew)后保存
 
5.3 卸载
rpm {-e|--erase} [--allmatches] [--nodeps] [--test] 
简单用法:rpm -e PACKAGE_NAME...
 
# rpm -q zsh
zsh-4.3.10-7.el6.x86_64
# rpm -e zsh
# rpm -q zsh
package zsh is not installed
--nodeps:忽略依赖关系;
--test: 测试卸载;dry-run模式;
--allmatches: 如果一个程序包同时安装多个版本,则此选项一次全部卸载之;
注意:如果程序包的配置文件安装后曾被修改,卸载时,此文件通常不会被删除,而是被重命名(加后缀.rpmsave)后留存;
 
5.4 查询
rpm {-q|--query} [select-options] [query-options]
[select-options]
 
1、查询某包或某些包是否安装:
rpm -q PACKAGE_NAME
 
# rpm -q zsh
zsh-5.1.1-3.fc24.x86_64
 
2、查询已经安装的所有包
rpm -qa PACKAGE_NAME
 
# rpm -qa zsh
zsh-5.1.1-3.fc24.x86_64
# 或者,grep后面支持正则表达式过滤
# rpm -qa |grep "zhs"
 
3、查询某文件是由哪个包安装生成:
rpm -qf /PATH/TO/SOMEFILE
 
# rpm -qf /etc/fstab 
setup-2.8.14-20.el6_4.1.noarch
# rpm -qf /etc/httpd/conf/httpd.conf 
httpd-2.2.15-39.el6.centos.x86_64
 
4、查询尚未安装的包文件的相关信息
-p
# rpm -qpi PACKAGE_NAME
 
# rpm -qpi gcc-4.4.7-11.el6.x86_64.rpm 
Name: gcc  Relocations: (not relocatable)
Version : 4.4.7 Vendor: CentOS
Release : 11.el6Build Date: 2014年10月15日 星期三 08时24分47秒
Install Date: (not installed)   Build Host: c6b9.bsys.dev.centos.org
Group   : Development/Languages Source RPM: gcc-4.4.7-11.el6.src.rpm
Size: 19495803 License: GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions
Signature   : RSA/SHA1, 2014年10月18日 星期六 04时02分58秒, Key ID 0946fca2c105b9de
Packager: CentOS BuildSystem <http://bugs.centos.org>
URL : http://gcc.gnu.org
Summary : Various compilers (C, C++, Objective-C, Java, ...)
Description :
The gcc package contains the GNU Compiler Collection version 4.4.
You'll need this package in order to compile C code.
[query-options]:
 
1、查询某包的简要说明信息:
rpm -qi PACKAGE_NAME
 
# rpm -qi zsh
Name: zsh  Relocations: (not relocatable)
Version : 5.1.1 Vendor: Fedora Project
Release : 3.fc24Build Date: 2015年11月05日 星期四 21时41分02秒
Install Date: 2015年11月19日 星期四 15时20分55秒  Build Host: buildvm-26.phx2.fedoraproject.org
Group   : System Environment/Shells Source RPM: zsh-5.1.1-3.fc24.src.rpm
Size: 6474662  License: MIT
Signature   : RSA/8, 2015年11月05日 星期四 21时56分22秒, Key ID 73bde98381b46521
Packager: Fedora Project
URL : http://zsh.sourceforge.net/
Summary : Powerful interactive shell
Description :
The zsh shell is a command interpreter usable as an interactive login
shell and as a shell script command processor.  Zsh resembles the ksh
shell (the Korn shell), but includes many enhancements.  Zsh supports
command line editing, built-in spelling correction, programmable
command completion, shell functions (with autoloading), a history
mechanism, and more.
 
2、查询某包安装后生成了哪些文件列表;
rpm -ql PACKAGE_NAME
 
# rpm -ql zsh|less
 
 
/etc/skel/.zshrc
/etc/zlogin
/etc/zlogout
/etc/zprofile
/etc/zshenv
/etc/zshrc
/usr/bin/zsh
/usr/lib64/zsh
/usr/lib64/zsh/5.1.1
/usr/lib64/zsh/5.1.1/zsh
/usr/lib64/zsh/5.1.1/zsh/attr.so
/usr/lib64/zsh/5.1.1/zsh/cap.so
......
 
3、查询某包安装后生成的配置文件路径
rpm -qc PACKAGE_NAME
 
# rpm -qc zsh
/etc/skel/.zshrc
/etc/zlogin
/etc/zlogout
/etc/zprofile
/etc/zshenv
/etc/zshrc
 
4、查询某包安装后生成的所有帮助文件
rpm -qd PACKAGE_NAME
 
# rpm -qd zsh
/usr/share/doc/zsh/BUGS
/usr/share/doc/zsh/CONTRIBUTORS
/usr/share/doc/zsh/FAQ
/usr/share/doc/zsh/FEATURES
/usr/share/doc/zsh/LICENCE
/usr/share/doc/zsh/MACHINES
/usr/share/doc/zsh/NEWS
/usr/share/doc/zsh/README
/usr/share/doc/zsh/completion-style-guide
/usr/share/doc/zsh/zsh-development-guide
/usr/share/doc/zsh/zshprompt.pl
/usr/share/info/zsh.info-1.gz
/usr/share/info/zsh.info-2.gz
/usr/share/info/zsh.info-3.gz
/usr/share/info/zsh.info-4.gz
/usr/share/info/zsh.info-5.gz
....
 
5、查看某包制作时随版本变化的changelog信息;
rpm-q --changelog PACKAGE_NAME

# rpm -q --changelog zsh
* 四 11月 05 2015 Kamil Dudka <kdudka@redhat.com> - 5.1.1-3
- make loading of module's dependencies work again (#1277996)

* 四 10月 08 2015 Kamil Dudka <kdudka@redhat.com> - 5.1.1-2
- fix crash in ksh mode with -n and $HOME (#1269883)

* 一 9月 14 2015 Kamil Dudka <kdudka@redhat.com> - 5.1.1-1
- Update to latest upstream release: Zsh 5.1.1

* 一 8月 31 2015 Kamil Dudka <kdudka@redhat.com> - 5.1-1
- Update to latest upstream release: Zsh 5.1
- remove outdated workarounds in %check

* 四 7月 30 2015 Kamil Dudka <kdudka@redhat.com> - 5.0.8-6
- fix handling of command substitution in math context

* 三 7月 22 2015 Kamil Dudka <kdudka@redhat.com> - 5.0.8-5
- prevent infinite recursion in ihungetc() (#1245712)

* 二 7月 07 2015 Kamil Dudka <kdudka@redhat.com> - 5.0.8-4
- backport completion for dnf (#1239337)

* 四 7月 02 2015 Kamil Dudka <kdudka@redhat.com> - 5.0.8-3
- backport completion-related upstream fixes (#1238544)

* 五 6月 19 2015 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 5.0.8-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_23_Mass_Rebuild

* 三 6月 03 2015 Kamil Dudka <kdudka@redhat.com> - 5.0.8-1
- Update to latest upstream release: Zsh 5.0.8

* 五 5月 22 2015 Kamil Dudka <kdudka@redhat.com> - 5.0.7-8
- fix SIGSEGV of the syntax check in ksh emulation mode (#1222867)

* 一 4月 20 2015 Kamil Dudka <kdudka@redhat.com> - 5.0.7-7
- fix SIGSEGV when handling heredocs and keyboard interrupt (#972624)
- queue signals when manipulating global state to avoid deadlock

* 日 1月 25 2015 Kamil Dudka <kdudka@redhat.com> - 5.0.7-6
- use correct allocation function in the new 'cd' code (#1183238)

* 五 1月 23 2015 Kamil Dudka <kdudka@redhat.com> - 5.0.7-5
- suppress a warning about closing an already closed file descriptor (#1184002)
- improve handling of NULL in the 'cd' built-in (#1183238)

* 三 11月 19 2014 Kamil Dudka <kdudka@redhat.com> - 5.0.7-4
- update documentation of POSIX_JOBS in the zshoptions.1 man page (#1162198)

* 二 11月 18 2014 Kamil Dudka <kdudka@redhat.com> - 5.0.7-3
- replace an incorrect comment in /etc/zshenv (#1164313)

* 一 11月 10 2014 Kamil Dudka <kdudka@redhat.com> - 5.0.7-2
- make the wait built-in work for already exited processes (#1162198)

* 三 10月 08 2014 Dominic Hopf <dmaphy@fedoraproject.org> - 5.0.7-1
- Update to latest upstream release: Zsh 5.0.7

* 四 8月 28 2014 Dominic Hopf <dmaphy@fedoraproject.org> - 5.0.6-1
- Update to latest upstream release: Zsh 5.0.6

* 一 8月 18 2014 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 5.0.5-8
- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_22_Mass_Rebuild

* 四 7月 17 2014 Dominic Hopf <dmaphy@fedoraproject.org> - 5.0.5-7
- apply upstream patch which fixes CPU load issue (RHBZ#1120424)

* 三 7月 09 2014 Adam Jackson <ajax@redhat.com> 5.0.5-6
- Fix missing 'fi' in %post

* 四 7月 03 2014 Dominic Hopf <dmaphy@fedoraproject.org> - 5.0.5-5
- improve handling of /etc/shells

* 三 7月 02 2014 Dominic Hopf <dmaphy@fedoraproject.org> - 5.0.5-4
- fix FTBFS issue (RHBZ#1106713)
- remove individual _bindir setting; install to /usr/bin/ (RHBZ#1034060)
- require info package instead of /sbin/install-info binary

* 六 6月 07 2014 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 5.0.5-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_Mass_Rebuild

* 二 4月 08 2014 Dominic Hopf <dmaphy@fedoraproject.org> - 5.0.5-1
- Update to latest upstream release: Zsh 5.0.5

* 四 1月 16 2014 James Antill <james@fedoraproject.org> - 5.0.2-8
- Remove unneeded build require on tetex.

* 六 10月 26 2013 Dominic Hopf <dmaphy@fedoraproject.org> - 5.0.2-7
- Require hostname package instead of /bin/hostname

* 二 10月 22 2013 Dominic Hopf <dmaphy@fedoraproject.org> - 5.0.2-6
- remove systemd completion, it delivers it's own now (RHBZ#1022039)

* 四 8月 01 2013 Dominic Hopf <dmaphy@fedoraproject.org> - 5.0.2-5
- update systemd completion (adds machinectl command)

* 二 6月 25 2013 Dominic Hopf <dmaphy@fedoraproject.org> - 5.0.2-4
- up-to-date systemd completion (#949003)
- apply patch for building for aarch64 (#926864)

* 一 4月 15 2013 James Antill <james@fedoraproject.org> - 5.0.2-3
- Fix the changelog dates.
- Fix the texi itemx bug.
- Resolves: bug#927863

* 五 2月 15 2013 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 5.0.2-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_19_Mass_Rebuild

* 二 1月 08 2013 Dominic Hopf <dmaphy@fedoraproject.org> - 5.0.2-1
- Update to new upstream version: Zsh 5.0.2

* 三 11月 21 2012 Dominic Hopf <dmaphy@fedoraproject.org> - 5.0.0-1
- Update to new upstream version: Zsh 5.0.0

* 日 7月 22 2012 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 4.3.17-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_18_Mass_Rebuild

* 日 3月 04 2012 Dominic Hopf <dmaphy@fedoraproject.org> - 4.3.17-1
- Update to new upstream version: Zsh 4.3.17

* 六 1月 14 2012 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 4.3.15-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_17_Mass_Rebuild

* 六 12月 24 2011 Dominic Hopf <dmaphy@fedoraproject.org> - 4.3.15-1
- Update to new upstream version: Zsh 4.3.15

* 六 12月 17 2011 Dominic Hopf <dmaphy@fedoraproject.org> - 4.3.14-2
- change the License field to MIT (RHBZ#768548)

* 六 12月 10 2011 Dominic Hopf <dmaphy@fedoraproject.org> - 4.3.14-1
- Update to new upstream version: Zsh 4.3.14

* 六 12月 03 2011 Dominic Hopf <dmaphy@fedoraproject.org> - 4.3.13-1
- Update to new upstream version: Zsh 4.3.13

* 六 8月 13 2011 Dominic Hopf <dmaphy@fedoraproject.org> - 4.3.12-1
- Update to new upstream version: Zsh 4.3.12

* 二 2月 08 2011 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 4.3.11-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_15_Mass_Rebuild

* 四 1月 20 2011 Christopher Ailon <caillon@redhat.com> - 4.3.11-1
- Rebase to upstream version 4.3.11

* 二 12月 07 2010 Toshio Kuratomi <toshio@fedoraproject.org> - 4.3.10-6
- Rebuild for FTBFS https://bugzilla.redhat.com/show_bug.cgi?id=631197
- Remove deprecated PreReq, the packages aren't needed at runtime and they're
  already in Requires(post,preun,etc): lines.

* 一 3月 22 2010 James Antill <james@fedoraproject.org> - 4.3.10-5
- Add pathmunge to our /etc/zshrc, for profile.d compat.
- Resolves: bug#548960

* 五 8月 07 2009 James Antill <james@fedoraproject.org> - 4.3.10-4
- Allow --excludedocs command to work!
- Resolves: bug#515986

* 一 7月 27 2009 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 4.3.10-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_12_Mass_Rebuild

* 一 7月 20 2009 James Antill <james@fedoraproject.org> - 4.3.10-1
- Import new upstream 4.3.10

* 三 6月 10 2009 Karsten Hopp <karsten@redhat.com> 4.3.9-4.1
- skip D02glob test on s390, too

* 一 3月 02 2009 James Antill <james@fedoraproject.org> - 4.3.9-4
- Remove D02glob testcase on ppc/ppc64, and hope noone cares

* 三 2月 25 2009 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 4.3.9-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_11_Mass_Rebuild

 

 
6、查询某包提供的capabilities;
rpm -q --provides PACKAGE_NAME;
 
# rpm -q --provides zsh
/bin/zsh  
config(zsh) = 5.1.1-3.fc24
zsh = 5.1.1-3.fc24
zsh(x86-64) = 5.1.1-3.fc24
 
7、查询某包所依赖的capabilities;
rpm -q --requires PACKAGE_NAME


# rpm -q --requires zsh
/bin/sh  
/bin/sh  
/bin/sh  
/bin/sh  
/bin/zsh  
config(zsh) = 5.1.1-3.fc24
coreutils  
grep  
grep  
info  
info  
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.7)(64bit)  
libdl.so.2()(64bit)  
libdl.so.2(GLIBC_2.2.5)(64bit)  
libm.so.6()(64bit)  
libm.so.6(GLIBC_2.2.5)(64bit)  
libncursesw.so.6()(64bit)  
librt.so.1()(64bit)  
librt.so.1(GLIBC_2.2.5)(64bit)  
libtinfo.so.6()(64bit)  
rpmlib(CompressedFileNames) <= 3.0.4-1
rpmlib(FileDigests) <= 4.6.0-1
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
rpmlib(PayloadIsXz) <= 5.2-1
rtld(GNU_HASH)

 

8、查询某包安装或卸载时执行脚本;
rpm -q --scripts PACKAGE_NAME

# rpm -q --scripts zsh
\postinstall scriptlet (using /bin/sh):
if [ "$1" = 1 ]; then
  if [ ! -f /etc/shells ] ; then
echo "/usr/bin/zsh" > /etc/shells
echo "/bin/zsh" >> /etc/shells
  else
grep -q "^/usr/bin/zsh$" /etc/shells || echo "/usr/bin/zsh" >> /etc/shells
grep -q "^/bin/zsh$" /etc/shells || echo "/bin/zsh" >> /etc/shells
  fi
fi

if [ -f /usr/share/info/zsh.info.gz ]; then
# This is needed so that --excludedocs works.
/sbin/install-info /usr/share/info/zsh.info.gz /usr/share/info/dir \
  --entry="* zsh: (zsh).An enhanced bourne shell."
fi
preuninstall scriptlet (using /bin/sh):
if [ "$1" = 0 ] ; then
if [ -f /usr/share/info/zsh.info.gz ]; then
# This is needed so that --excludedocs works.
/sbin/install-info --delete /usr/share/info/zsh.info.gz /usr/share/info/dir \
  --entry="* zsh: (zsh).An enhanced bourne shell."
fi
fi
postuninstall scriptlet (using /bin/sh):
if [ "$1" = 0 ] && [ -f /etc/shells ] ; then
  sed -i '\!^/usr/bin/zsh$!d' /etc/shells
  sed -i '\!^/bin/zsh$!d' /etc/shells
fi

 

脚本有四类:
preinstall:安装过程开始之前执行的脚本;
postinstall:安装过程后执行的脚本;
preuninstall:卸载前执行的脚本;
postuninstall:卸载过程完成之后执行的脚本;
 
5.5 校验
查询包安装之后生成的文件是否发生了改变
rpm {-V|--verify} [select-options] [verify-options]
 
# rpm -V zsh
S.5....T.  c /etc/zshrc
 
常见用法:rpm -V PACKAGE_NAME
S file Size differs
  M Mode differs (includes permissions and file type)
  5 digest (formerly MD5 sum) differs
  D Device major/minor number mismatch
  L readLink(2) path mismatch
  U User ownership differs
  G Group ownership differs
  T mTime differs
  P caPabilities differ
程序包的合法性验正:
来源合法:
由我们信任的制作者提供
 
依赖于:制作者的数字签名;签名是作者使用自己的私钥加密程序包的特性码进行的;
内容合法:
 
包未被二次修改;完整性校验成功
 
依赖于:制作者提供的程序特征码;
 
验正方式:安装者用同样的特征码提取算法提取程序包的特征码,并与原作者提供的相比较;
 
验正其光盘中程序包的来源及完整性:
rpm --import /path/to/RPM-GPG-KEY-FILE
例如:# rpm --import RPM-GPG-KEY-CentOS-6
 验正:rpm {-K|--checksig} PACKAGE_FILE
 
# rpm --import /misc/cd/RPM-GPG-KEY-CentOS-6 
# rpm -K zsh-4.3.10-7.el6.x86_64.rpm 
zsh-4.3.10-7.el6.x86_64.rpm: rsa sha1 (md5) pgp md5 OK
# rpm -K php-5.3.3-38.el6.x86_64.rpm 
php-5.3.3-38.el6.x86_64.rpm: rsa sha1 (md5) pgp md5 OK
--nosignature: 不检查来源合法性
--nodigest: 不检查完整性  
rpm管理器数据库:/var/lib/rpm
 
重建数据库:
rpm {--initdb|--rebuilddb} [-v] [--dbpath DIRECTORY]
  --initdb: 初始化数据库,即数据库完全不存时,可新建之;
例如:
我删除__db.001、__db.002、__db.003、__db.004
 
# rm -rf /var/lib/rpm/__db.00{1..4}
# ll /var/lib/rpm/
总用量 57208
-rw-r--r--. 1 root root  5083136 11月 19 15:32 Basenames
-rw-r--r--. 1 root root12288 11月 10 15:20 Conflictname
-rw-r--r--. 1 root root  1044480 11月 19 15:32 Dirnames
-rw-r--r--. 1 root root  5263360 11月 19 15:32 Filedigests
-rw-r--r--. 1 root root20480 11月 19 15:32 Group
-rw-r--r--. 1 root root20480 11月 19 15:32 Installtid
-rw-r--r--. 1 root root49152 11月 19 15:32 Name
-rw-r--r--. 1 root root24576 11月 19 15:07 Obsoletename
-rw-r--r--. 1 root root 46825472 11月 19 15:32 Packages
-rw-r--r--. 1 root root  1343488 11月 19 15:32 Providename
-rw-r--r--. 1 root root   696320 11月 19 15:32 Provideversion
-rw-r--r--. 1 root root12288 11月 16 15:07 Pubkeys
-rw-r--r--. 1 root root   446464 11月 19 15:32 Requirename
-rw-r--r--. 1 root root   253952 11月 19 15:32 Requireversion
-rw-r--r--. 1 root root90112 11月 19 15:32 Sha1header
-rw-r--r--. 1 root root86016 11月 19 15:32 Sigmd5
-rw-r--r--. 1 root root12288 11月 10 15:20 Triggername
# rpm --initdb /var/lib/rpm/
# ll /var/lib/rpm/
总用量 58048
-rw-r--r--. 1 root root  5083136 11月 19 15:32 Basenames
-rw-r--r--. 1 root root12288 11月 10 15:20 Conflictname
-rw-r--r--  1 root root24576 11月 19 15:38 __db.001
-rw-r--r--  1 root root   229376 11月 19 15:38 __db.002
-rw-r--r--  1 root root  1318912 11月 19 15:38 __db.003
-rw-r--r--  1 root root   753664 11月 19 15:38 __db.004
-rw-r--r--. 1 root root  1044480 11月 19 15:32 Dirnames
-rw-r--r--. 1 root root  5263360 11月 19 15:32 Filedigests
-rw-r--r--. 1 root root20480 11月 19 15:32 Group
-rw-r--r--. 1 root root20480 11月 19 15:32 Installtid
-rw-r--r--. 1 root root49152 11月 19 15:32 Name
-rw-r--r--. 1 root root24576 11月 19 15:07 Obsoletename
-rw-r--r--. 1 root root 46825472 11月 19 15:32 Packages
-rw-r--r--. 1 root root  1343488 11月 19 15:32 Providename
-rw-r--r--. 1 root root   696320 11月 19 15:32 Provideversion
-rw-r--r--. 1 root root12288 11月 16 15:07 Pubkeys
-rw-r--r--. 1 root root   446464 11月 19 15:32 Requirename
-rw-r--r--. 1 root root   253952 11月 19 15:32 Requireversion
-rw-r--r--. 1 root root90112 11月 19 15:32 Sha1header
-rw-r--r--. 1 root root86016 11月 19 15:32 Sigmd5
-rw-r--r--. 1 root root12288 11月 10 15:20 Triggername

 

  --rebuilddb: 无论当前数据存在与否,都会直接重建此库;
总结:
基本管理:安装、升级、卸载、查询和校验;
合法性验正;
数据库管理;

相关内容