您的位置:首页 > 产品设计 > 产品经理

RPM 程序包管理详解

2016-03-20 18:49 537 查看
CentOS系统上rpm命令管理程序包

一、rpm程序包管理分为安装、升级、卸载、查询和校验、数据库维护

rpm程序包的安装
rpm命令后加的选项参数有:
rpm -ivh ,程序包的安装工作,后面直接接要安装的程序包名称;例如:
[root@localhost Packages]# rpm -ivh zsh-5.0.2-14.el7.x86_64.rpm
准备中... ################################# [100%]
正在升级/安装...
1:zsh-5.0.2-14.el7 ################################# [100%]
-i , 安装程序包

-v , 显示详细信息。
-vv, 显示更详细的信息输出。
-h , 输出进度条,每个#表示2%的进度。

--test:测试安装,检查并报告依赖关系及冲突消息等:例如
[root@localhost Packages]# rpm -ivh --test zsh-html-5.0.2-14.el7.x86_64.rpm
准备中...此次操作只是测试,没有进行安装。
--nodeps:忽略依赖关系,在提示有安装有依赖关系时,可以用,但是一半不建议用:例如
[root@localhost Packages]# rpm -ivh --nodeps zziplib-0.13.62-5.el7.i686.rpm
准备中... ################################# [100%]
正在升级/安装...
1:zziplib-0.13.62-5.el7 ################################# [100%]
--replacepkgs:重新安装(再重新安装之前,将之前安装的程序先删除掉,然后在进行安装,不然的话,之前的配置文件改过,重新安装后也是没有用的,所以要先删除,然后重新安装)
[root@localhost Packages]# rpm -ivh --replacepkgs zsh-5.0.2-14.el7.x86_64.rpm
准备中... ################################# [100%]
正在升级/安装...
1:zsh-5.0.2-14.el7 ################################# [100%]

--nosignature:不检查包签名信息和不检查来源合法性,例如命令使用方法如下:
[root@localhost Packages]# rpm -ivh --replacepkgs --nosignature zsh-5.0.2-14.el7.x86_64.rpm
准备中... ################################# [100%]
正在升级/安装...
1:zsh-5.0.2-14.el7 ################################# [100%]
--nodigest:不检查包完整性信息;命令使用如下:
[root@localhost Packages]# rpm -ivh --replacepkgs --nodigest zsh-5.0.2-14.el7.x86_64.rpm
准备中... ################################# [100%]
正在升级/安装...
1:zsh-5.0.2-14.el7 ################################# [100%]
rpm程序包的升级:
rpm加选项参数
-U :升级或安装
-F : 升级
rpm -Uvh 升级或安装程序包
rpm -Fvh 升级程序包
rpm --oldpackage:降级程序包
rpm --force:强制升级程序包
rpm程序包的卸载:
-e 卸载程序包,卸载时参数后面只加卸载的程序包名。例如:
[root@localhost Packages]# rpm -e zsh

--allmatches:卸载所有匹配指定名称的程序包的各版本:例如:
[root@localhost ~]# rpm -e --allmatches zsh
--nodeps:忽略依赖关系:例如
[root@localhost Packages]# rpm -e --nodeps zsh
--test:测试卸载,dry run模式,就是查询,不卸载;例如
[root@localhost Packages]# rpm -evh --test zsh
准备中... ################################# [100%]
rpm程序包的查询:
rpm 后加参数选项:
-q:查询已经安装的单个程序包,参数后加程序包名例如:

[root@localhost Packages]# rpm -q zsh
zsh-5.0.2-14.el7.x86_64
-qa:查询所有已经安装的程序包,例如:
[root@localhost Packages]# rpm -qa
-qa;如果查询的程序包的数量太多的话,可以配合正则表达式进行查找:例如:
[root@localhost Packages]# rpm -qa | grep "^zsh"
zsh-html-5.0.2-14.el7.x86_64
zsh-5.0.2-14.el7.x86_64

-f:file 查询指定的文件由哪个程序包安装生成:(这个命令语句就是查询一下fstab文件有哪个程序包安装生成)例如:
[root@localhost Packages]# rpm -qf /etc/fstab
setup-2.8.71-6.el7.noarch

-qpl, --package PACKAGE_FILE:用于实现对未安装的程序包执行查询操作;
[root@localhost Packages]# rpm -qpl zsh-5.0.2-14.el7.x86_64.rpm

--whatprovides CAPABILITY:查询指定的CAPABILITY由哪个程序包提供,例如:
[root@localhost Packages]# rpm -q --whatprovides bash
bash-4.2.46-19.el7.x86_64

--whatrequires CAPABILITY:查询指定的CAPABILITY被哪个包所依赖;例如:
[root@localhost Packages]# rpm -q --whatrequires bash
initscripts-9.49.30-1.el7.x86_64
rsyslog-7.4.7-12.el7.x86_64
bash-completion-2.1-6.el7.noarch
dracut-033-360.el7_2.x86_64
libguestfs-1.28.1-1.55.el7.centos.x86_64
autofs-5.0.7-54.el7.x86_64
lvm2-2.02.130-5.el7_2.1.x86_64
kpatch-0.3.1-1.el7_2.noarch
rpm -q --changelog:查询rpm包的changelog;(修改日)
[root@localhost Packages]# rpm -q --changelog zsh | less

-ql:查询程序安装生成的所有文件的列表:例如:
[root@localhost Packages]# rpm -ql bash | wc -l
-qi:查看程序包相关的信息,版本号、大小、所属的包组,等;
[root@localhost Packages]# rpm -qi bash
Name : bash
Version : 4.2.46
Release : 19.el7
Architecture: x86_64
Install Date: 2016年03月18日 星期五 00时24分53秒
Group : System Environment/Shells
Size : 3663618
License : GPLv3+
Signature : RSA/SHA256, 2015年11月25日 星期三 22时14分53秒, Key ID 24c6a8a7f4a80eb5
Source RPM : bash-4.2.46-19.el7.src.rpm
Build Date : 2015年11月20日 星期五 13时04分53秒
Build Host : worker1.bsys.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

-qc:查询指定的程序包提供的配置文件:例如:
[root@localhost Packages]# rpm -qc bash
/etc/skel/.bash_logout
/etc/skel/.bash_profile
/etc/skel/.bashrc
-qd:查询指定的程序包提供的帮助文档:例如:
[root@localhost Packages]# rpm -qd bash
/usr/share/doc/bash-4.2.46/COPYING
/usr/share/info/bash.info.gz
/usr/share/man/man1/..1.gz
/usr/share/man/man1/:.1.gz
/usr/share/man/man1/[.1.gz
/usr/share/man/man1/alias.1.gz
/usr/share/man/man1/bash.1.gz
/usr/share/man/man1/bashbug-64.1.gz
/usr/share/man/man1/bashbug.1.gz
/usr/share/man/man1/bg.1.gz
/usr/share/man/man1/bind.1.gz
/usr/share/man/man1/break.1.gz
/usr/share/man/man1/builtin.1.gz
/usr/share/man/man1/builtins.1.gz
/usr/share/man/man1/caller.1.gz
/usr/share/man/man1/cd.1.gz
/usr/share/man/man1/command.1.gz
/usr/share/man/man1/compgen.1.gz
/usr/share/man/man1/complete.1.gz
/usr/share/man/man1/compopt.1.gz
/usr/share/man/man1/continue.1.gz
/usr/share/man/man1/declare.1.gz
/usr/share/man/man1/dirs.1.gz
/usr/share/man/man1/disown.1.gz
/usr/share/man/man1/enable.1.gz
/usr/share/man/man1/eval.1.gz
/usr/share/man/man1/exec.1.gz
/usr/share/man/man1/exit.1.gz
/usr/share/man/man1/export.1.gz
/usr/share/man/man1/fc.1.gz
/usr/share/man/man1/fg.1.gz
/usr/share/man/man1/getopts.1.gz
/usr/share/man/man1/hash.1.gz
/usr/share/man/man1/help.1.gz
/usr/share/man/man1/history.1.gz
/usr/share/man/man1/jobs.1.gz
/usr/share/man/man1/let.1.gz
/usr/share/man/man1/local.1.gz
/usr/share/man/man1/logout.1.gz
/usr/share/man/man1/mapfile.1.gz
/usr/share/man/man1/popd.1.gz
/usr/share/man/man1/pushd.1.gz
/usr/share/man/man1/read.1.gz
/usr/share/man/man1/readonly.1.gz
/usr/share/man/man1/return.1.gz
/usr/share/man/man1/set.1.gz
/usr/share/man/man1/sh.1.gz
/usr/share/man/man1/shift.1.gz
/usr/share/man/man1/shopt.1.gz
/usr/share/man/man1/source.1.gz
/usr/share/man/man1/suspend.1.gz
/usr/share/man/man1/times.1.gz
/usr/share/man/man1/trap.1.gz
/usr/share/man/man1/type.1.gz
/usr/share/man/man1/typeset.1.gz
/usr/share/man/man1/ulimit.1.gz
/usr/share/man/man1/umask.1.gz
/usr/share/man/man1/unalias.1.gz
/usr/share/man/man1/unset.1.gz
/usr/share/man/man1/wait.1.gz
--provides:列出指定的程序包提供的所有的CAPABILITY,例如;
[root@localhost Packages]# 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
-R:查询指定的程序包的依赖关系

[root@localhost Packages]# rpm -q -R bash
/bin/sh
config(bash) = 4.2.46-19.el7
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

--scripts: 查看程序包自带的脚本片段:例如
[root@localhost Packages]# 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
rpm程序包的校验:
rpm后加参数选项:
-V:校验程序文件是否被改动:
[root@localhost Packages]# file /usr/share/zsh/5.0.2/functions/ztodo
/usr/share/zsh/5.0.2/functions/ztodo: ASCII text
[root@localhost Packages]# vim /usr/share/zsh/5.0.2/functions/ztodo[root@localhost Packages]# rpm -V zsh
S.5....T. /usr/share/zsh/5.0.2/functions/ztodo

获取并导入信任的包制作者的密钥:
centos7的公钥房子ls /etc/pki/rpm-gpg中。
对于CentOS发行版来说:rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
数据库重建:
rpm管理器数据库路径:/var/lib/rpm/
查询操作:通过此处的数据库进行:
获取帮助:
CentOS 6: man rpm
CentOS 7: man rpmdb
rpm {--initdb|--rebuilddb} [--dbpath DIRECTORY] [--root DIRECTORY]
--initdb:初始化数据库,当前无任何数据库可初始化创建一个新的;当前有时不执行任何操作;
--rebuilddb:重新构建,通过读取当前系统上所有已经安装过的程序包进行重新创建;例如:

[root@localhost Packages]# mkdir /tmp/rpm
[root@localhost Packages]# rpm --initdb --dbpath=/tmp/rpm
[root@localhost Packages]# ls /tmp/rpm
Basenames __db.003 Name Requirename
Conflictname Dirnames Obsoletename Sha1header
__db.001 Group Packages Sigmd5
__db.002 Installtid Providename Triggername
[root@localhost Packages]# rpm --rebuilddb --dbpath=/tmp/rpm
[root@localhost Packages]# ls /tmp/rpm
Basenames Group Obsoletename Requirename Triggername
Conflictname Installtid Packages Sha1header
Dirnames Name Providename Sigmd5

以上就是rpm 命令管理程序包的操作详解,希望再加再励,继续努力。
本文出自 “李文明的博客” 博客,请务必保留此出处http://liwenming18.blog.51cto.com/11068518/1753185
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: