您的位置:首页 > 运维架构 > Linux

谢烟客---------Linux之程序包管理rpm使用

2017-08-15 14:50 323 查看
在CentOS系统上用rpm管理程序包,实现安装、卸载、查询、校验、升级、数据库维护

-ivh --replacepkgs

-e

-U 安装或升级 -F 仅安装

rpm -V file.rpm 校验程序包安装后是否发生改变

rpm --import GPG_FILE 将要安装某仓库的程序包,为了实现校验,必须事先导入GPG公钥
S:Size,5:MD5,T:Timestamp,U:user,G:Group

/var/lib/rpm rpm程序的状态信息

如果元数据损坏:
--rebuildb 直接重建元数据
--initdb 数据库不存在时,重建元数据。存在时,不重建元数据

注意:
1、对内核不能升级,对4.0版本之前的内核升级操作后需要重启,新的内核升级后可能重启不了。对内核执行安装即可。
2、对于原有程序包配置发生改变,新安装的程序包的配置名为rpmnew。如果没有变化,配置文件不会安装。
3、多个rpm命令不能同时使用,避免包的完整性

事务类操作:
1、原子性
2、隔离性
3、持久性
补充:
vim :wq 退出,会引起修改时间戳的变化(即使没有做任何操作)

安装、卸载、查询、校验、升级、数据库维护
rpm [OPTIONS....] PACKAGE_FILE ...
-v/-vv ## 显示安装的详细信息
-h ## 以hash格式显示安装的百分比
-i ## 安装程序包
-U/-F ## 安装或升级 或 仅安装程序包
-e ## 卸载程序包
-V ## 校验程序包
--import GPG_FILE ## 安装前,导入对应的公钥
--initdb ## 初始化数据库:存在数据库时不进行操作
--rebuildb ## 直接重建数据库

使用示例:
1、-v
[root@izpo45bh60h6bsz ~]# rpm -iv zsh-4.3.11-4.el6.centos.2.i686.rpm
警告:zsh-4.3.11-4.el6.centos.2.i686.rpm: 头V3 RSA/SHA1 Signature, 密钥 ID c105b9de: NOKEY
软件包准备中...
zsh-4.3.11-4.el6.centos.2.i686
[root@izpo45bh60h6bsz ~]#

2、-vv
[root@izpo45bh60h6bsz ~]# rpm -ivv --replacepkgs zsh-4.3.11-4.el6.centos.2.i686.rpm
软件包准备中...
D: computing file dispositions
D: 0x0000fd01     4096      5545114      2446367 /
D: ========== +++ zsh-5.0.2-25.el7_3.1 x86_64-linux 0x2
D: Expected size:      2494392 = lead(96)+sigs(1284)+pad(4)+data(2493008)
D:   Actual size:      2494392
D: zsh-5.0.2-25.el7_3.1.x86_64: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: OK
D:   install: zsh-5.0.2-25.el7_3.1 has 988 files
zsh-5.0.2-25.el7_3.1.x86_64
D: ========== Directories not explicitly included in package:
D:          0 /bin/
D:          1 /etc/skel/
D:          2 /etc/
D:          3 /etc/
D:          4 /usr/lib64/
D:          9 /usr/share/doc/
D:         11 /usr/share/info/
D:         12 /usr/share/man/man1/
D:         13 /usr/share/
D: ==========
......

3、-h
[root@izpo45bh60h6bsz ~]# rpm -ivh --replacepkgs zsh-4.3.11-4.el6.centos.2.i686.rpm
警告:zsh-4.3.11-4.el6.centos.2.i686.rpm: 头V3 RSA/SHA1 Signature, 密钥 ID c105b9de: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
1:zsh-4.3.11-4.el6.centos.2        ################################# [100%]

4、升级或安装
[root@izpo45bh60h6bsz ~]# rpm -Uvh zsh-5.0.2-25.el7_3.1.x86_64.rpm
准备中...                          ################################# [100%]
file /etc/zshrc from install of zsh-5.0.2-25.el7_3.1.x86_64 conflicts with file from package zsh-4.3.11-4.el6.centos.2.i686
file /usr/share/info/zsh.info-1.gz from install of zsh-5.0.2-25.el7_3.1.x86_64 conflicts with file from package zsh-4.3.11-4.el6.centos.2.i686
file /usr/share/info/zsh.info-2.gz from install of zsh-5.0.2-25.el7_3.1.x86_64 conflicts with file from package zsh-4.3.11-4.el6.centos.2.i686
file /usr/share/info/zsh.info-3.gz from install of zsh-5.0.2-25.el7_3.1.x86_64 conflicts with file from package zsh-4.3.11-4.el6.centos.2.i686
file /usr/share/info/zsh.info-4.gz from install of zsh-5.0.2-25.el7_3.1.x86_64 conflicts with file from package zsh-4.3.11-4.el6.centos.2.i686
file /usr/share/info/zsh.info-5.gz from install of zsh-5.0.2-25.el7_3.1.x86_64 conflicts with file from package zsh-4.3.11-4.el6.centos.2.i686
file /usr/share/info/zsh.info.gz from install of zsh-5.0.2-25.el7_3.1.x86_64 conflicts with file from package zsh-4.3.11-4.el6.centos.2.i686
file /usr/share/man/man1/zsh.1.gz from install of zsh-5.0.2-25.el7_3.1.x86_64 conflicts with file from package zsh-4.3.11-4.el6.centos.2.i686
file /usr/share/man/man1/zshall.1.gz from install of zsh-5.0.2-25.el7_3.1.x86_64 conflicts with file from package zsh-4.3.11-4.el6.centos.2.i686
file /usr/share/man/man1/zshbuiltins.1.gz from install of zsh-5.0.2-25.el7_3.1.x86_64 conflicts with file from package zsh-4.3.11-4.el6.centos.2.i686
file /usr/share/man/man1/zshcalsys.1.gz from install of zsh-5.0.2-25.el7_3.1.x86_64 conflicts with file from package zsh-4.3.11-4.el6.centos.2.i686
file /usr/share/man/man1/zshcompctl.1.gz from install of zsh-5.0.2-25.el7_3.1.x86_64 conflicts with file from package zsh-4.3.11-4.el6.centos.2.i686
file /usr/share/man/man1/zshcompsys.1.gz from install of zsh-5.0.2-25.el7_3.1.x86_64 conflicts with file from package zsh-4.3.11-4.el6.centos.2.i686
file /usr/share/man/man1/zshcompwid.1.gz from install of zsh-5.0.2-25.el7_3.1.x86_64 conflicts with file from package zsh-4.3.11-4.el6.centos.2.i686
file /usr/share/man/man1/zshcontrib.1.gz from install of zsh-5.0.2-25.el7_3.1.x86_64 conflicts with file from package zsh-4.3.11-4.el6.centos.2.i686
file /usr/share/man/man1/zshexpn.1.gz from install of zsh-5.0.2-25.el7_3.1.x86_64 conflicts with file from package zsh-4.3.11-4.el6.centos.2.i686
file /usr/share/man/man1/zshmisc.1.gz from install of zsh-5.0.2-25.el7_3.1.x86_64 conflicts with file from package zsh-4.3.11-4.el6.centos.2.i686
file /usr/share/man/man1/zshmodules.1.gz from install of zsh-5.0.2-25.el7_3.1.x86_64 conflicts with file from package zsh-4.3.11-4.el6.centos.2.i686
file /usr/share/man/man1/zshoptions.1.gz from install of zsh-5.0.2-25.el7_3.1.x86_64 conflicts with file from package zsh-4.3.11-4.el6.centos.2.i686
file /usr/share/man/man1/zshparam.1.gz from install of zsh-5.0.2-25.el7_3.1.x86_64 conflicts with file from package zsh-4.3.11-4.el6.centos.2.i686
file /usr/share/man/man1/zshroadmap.1.gz from install of zsh-5.0.2-25.el7_3.1.x86_64 conflicts with file from package zsh-4.3.11-4.el6.centos.2.i686
file /usr/share/man/man1/zshtcpsys.1.gz from install of zsh-5.0.2-25.el7_3.1.x86_64 conflicts with file from package zsh-4.3.11-4.el6.centos.2.i686
file /usr/share/man/man1/zshzftpsys.1.gz from install of zsh-5.0.2-25.el7_3.1.x86_64 conflicts with file from package zsh-4.3.11-4.el6.centos.2.i686
file /usr/share/man/man1/zshzle.1.gz from install of zsh-5.0.2-25.el7_3.1.x86_64 conflicts with file from package zsh-4.3.11-4.el6.centos.2.i686
[root@izpo45bh60h6bsz ~]#

5、仅升级
[root@izpo45bh60h6bsz ~]# rpm -e zsh
[root@izpo45bh60h6bsz ~]# rpm -Fvh zsh-5.0.2-25.el7_3.1.x86_64.rpm  ##没有zsh包,不能安装
[root@izpo45bh60h6bsz ~]#
[root@izpo45bh60h6bsz ~]# rpm -Uvh zsh-5.0.2-25.el7_3.1.x86_64.rpm ## 没有可安装
准备中...                          ################################# [100%]
正在升级/安装...
1:zsh-5.0.2-25.el7_3.1             ################################# [100%]
[root@izpo45bh60h6bsz ~]#

6、卸载
##修改配置文件
[root@izpo45bh60h6bsz ~]# echo "###" > /etc/zshrc
[root@izpo45bh60h6bsz ~]# rpm -e zsh
警告:/etc/zshrc 已另存为 /etc/zshrc.rpmsave
##不修改配置
[root@izpo45bh60h6bsz ~]# rpm -e zsh
[root@izpo45bh60h6bsz ~]#

7、校验程序包

##访问配置文件,不修改
[root@izpo45bh60h6bsz ~]# vim /etc/zshrc
[root@izpo45bh60h6bsz ~]# rpm -V zsh
.......T.  c /etc/zshrc
##修改配置文件
[root@izpo45bh60h6bsz ~]# echo "###" > /etc/zshrc
##访问doc文件,不修改
[root@izpo45bh60h6bsz ~]# vim /usr/share/doc/zsh-5.0.2/README
[root@izpo45bh60h6bsz ~]# rpm -V zsh
S.5....T.  c /etc/zshrc
.......T.  d /usr/share/doc/zsh-5.0.2/README

8、导入GPG再安装
##没有公钥
[root@izpo45bh60h6bsz ~]# rpm -ivh zsh-4.3.11-4.el6.centos.2.i686.rpm
警告:zsh-4.3.11-4.el6.centos.2.i686.rpm: 头V3 RSA/SHA1 Signature, 密钥 ID c105b9de: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
1:zsh-4.3.11-4.el6.centos.2        ################################# [100%]

##导入公钥
[root@izpo45bh60h6bsz ~]# rpm --import RPM-GPG-KEY-CentOS-6
[root@izpo45bh60h6bsz ~]# rpm -ivh zsh-4.3.11-4.el6.centos.2.i686.rpm
准备中...                          ################################# [100%]
正在升级/安装...
1:zsh-4.3.11-4.el6.centos.2        ################################# [100%]

9、初始化
##损坏数据库
[root@izpo45bh60h6bsz ~]# rm -rf /var/lib/rpm
[root@izpo45bh60h6bsz ~]# rpm -e zsh
错误:未安装软件包 zsh
[root@izpo45bh60h6bsz ~]# rpm -qa
[root@izpo45bh60h6bsz ~]#
##重建
[root@izpo45bh60h6bsz ~]# rpm --initdb
[root@izpo45bh60h6bsz ~]# ls /var/lib/rpm
Basenames  Conflictname  __db.001  __db.002  __db.003  Dirnames  Group  Installtid  Name  Obsoletename  Packages  Providename  Requirename  Sha1header  Sigmd5  Triggername
[root@izpo45bh60h6bsz ~]# rpm -e zsh
错误:未安装软件包 zsh
[root@izpo45bh60h6bsz ~]# rpm -qa
[root@izpo45bh60h6bsz ~]#

##重建
[root@izpo45bh60h6bsz ~]# rpm --rebuilddb
重新配置yum源
1145  yum-config-manager --disable extras
1147  yum-config-manager --disable updates
yum安装程序包


安装程序包
rpm -ivh [OOPTIONS...] PACKAGE_FILE ...
-test ## dryrun模式,测试安装
-nodeps ## 忽略包的依赖性,进行安装
-nodigest ## 不检查包的完整性,进行安装
-nosignature ## 不检查包的来源合法性,进行安装

--force ## 强制安装
--replacepkgs ## 重新安装

--ignoreos ## 安装不同平台的程序包,忽略平台

--notriggers ## 不执行触发器

--noscripts ## 安装时,不执行安装脚本
--nopre ## 安装时,不执行安装前脚本
--nopost ## 安装后脚本
--nopreun
--nopostun

使用示例
1、测试安装
[root@izpo45bh60h6bsz ~]# rpm -q zsh
zsh-5.0.2-25.el7.x86_64
[root@izpo45bh60h6bsz ~]# rpm -e zsh
警告:/etc/zshrc 已另存为 /etc/zshrc.rpmsave
[root@izpo45bh60h6bsz ~]# rm /etc/zshrc.rpmsave
rm:是否删除普通文件 "/etc/zshrc.rpmsave"?y

[root@izpo45bh60h6bsz ~]# rpm -ivh --test zsh-4.3.11-4.el6.centos.2.i686.rpm
警告:zsh-4.3.11-4.el6.centos.2.i686.rpm: 头V3 RSA/SHA1 Signature, 密钥 ID c105b9de: NOKEY
错误:依赖检测失败:
libc.so.6 被 zsh-4.3.11-4.el6.centos.2.i686 需要
libc.so.6(GLIBC_2.0) 被 zsh-4.3.11-4.el6.centos.2.i686 需要
libc.so.6(GLIBC_2.1) 被 zsh-4.3.11-4.el6.centos.2.i686 需要
libc.so.6(GLIBC_2.1.3) 被 zsh-4.3.11-4.el6.centos.2.i686 需要
libc.so.6(GLIBC_2.11) 被 zsh-4.3.11-4.el6.centos.2.i686 需要
libc.so.6(GLIBC_2.2) 被 zsh-4.3.11-4.el6.centos.2.i686 需要
libc.so.6(GLIBC_2.3) 被 zsh-4.3.11-4.el6.centos.2.i686 需要
libc.so.6(GLIBC_2.3.4) 被 zsh-4.3.11-4.el6.centos.2.i686 需要
libc.so.6(GLIBC_2.4) 被 zsh-4.3.11-4.el6.centos.2.i686 需要
libc.so.6(GLIBC_2.7) 被 zsh-4.3.11-4.el6.centos.2.i686 需要
libdl.so.2 被 zsh-4.3.11-4.el6.centos.2.i686 需要
libdl.so.2(GLIBC_2.0) 被 zsh-4.3.11-4.el6.centos.2.i686 需要
libdl.so.2(GLIBC_2.1) 被 zsh-4.3.11-4.el6.centos.2.i686 需要
libm.so.6 被 zsh-4.3.11-4.el6.centos.2.i686 需要
libm.so.6(GLIBC_2.0) 被 zsh-4.3.11-4.el6.centos.2.i686 需要
libncursesw.so.5 被 zsh-4.3.11-4.el6.centos.2.i686 需要
libtinfo.so.5 被 zsh-4.3.11-4.el6.centos.2.i686 需要
[root@izpo45bh60h6bsz ~]# rpm -ivh --test zsh-5.0.2-25.el7_3.1.x86_64.rpm
准备中...                          ################################# [100%]
[root@izpo45bh60h6bsz ~]# rpm -q zsh
未安装软件包 zsh

**通过test选项知道安装此程序包是否有依赖关系,且不会安装
2、忽略依赖关系
1)、安装
[root@izpo45bh60h6bsz ~]# rpm -ivh --nodeps zsh-4.3.11-4.el6.centos.2.i686.rpm
警告:zsh-4.3.11-4.el6.centos.2.i686.rpm: 头V3 RSA/SHA1 Signature, 密钥 ID c105b9de: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
1:zsh-4.3.11-4.el6.centos.2        ################################# [100%]
[root@izpo45bh60h6bsz ~]#
2、卸载
[root@izpo45bh60h6bsz ~]# rpm -e zsh
[root@izpo45bh60h6bsz ~]#


3、不检查包的完整性
[root@izpo45bh60h6bsz ~]# rpm -ivh --nodeps --nodigest zsh-4.3.11-4.el6.centos.2.i686.rpm
警告:zsh-4.3.11-4.el6.centos.2.i686.rpm: 头V3 RSA/SHA1 Signature, 密钥 ID c105b9de: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
1:zsh-4.3.11-4.el6.centos.2        ################################# [100%]


4、不检查包的来源合法性
[root@izpo45bh60h6bsz ~]# rpm -ivh --nodeps --nodigest --nosignature zsh-4.3.11-4.el6.centos.2.i686.rpm
准备中...                          ################################# [100%]
正在升级/安装...
1:zsh-4.3.11-4.el6.centos.2        ################################# [100%]
5、强制安装
[root@izpo45bh60h6bsz ~]# rpm -ivh --nodeps --nodigest --nosignature zsh-4.3.11-4.el6.centos.2.i686.rpm
准备中...                          ################################# [100%]
软件包 zsh-4.3.11-4.el6.centos.2.i686 已经安装

在已经安装的情况下在次安装
[root@izpo45bh60h6bsz ~]# rpm -ivh --force --nodeps --nodigest --nosignature zsh-4.3.11-4.el6.centos.2.i686.rpm
准备中...                          ################################# [100%]
正在升级/安装...
1:zsh-4.3.11-4.el6.centos.2        ################################# [100%]
6、重新安装
[root@izpo45bh60h6bsz ~]# rpm -ivh --nodeps --nodigest --nosignature zsh-4.3.11-4.el6.centos.2.i686.rpm
准备中...                          ################################# [100%]
软件包 zsh-4.3.11-4.el6.centos.2.i686 已经安装

在已经安装的情况下重新安装
[root@izpo45bh60h6bsz ~]# rpm -ivh --replacepkgs --nodeps --nodigest --nosignature zsh-4.3.11-4.el6.centos.2.i686.rpm
准备中...                          ################################# [100%]
正在升级/安装...
1:zsh-4.3.11-4.el6.centos.2        ################################# [100%]
7、安装不同平台的程序包
X86安装x64平台的程序包
8、不执行触发器
[root@izpo45bh60h6bsz ~]# rpm -ivh --replacepkgs --notriggers --nodeps --nodigest --nosignature zsh-4.3.11-4.el6.centos.2.i686.rpm
准备中...                          ################################# [100%]
正在升级/安装...
1:zsh-4.3.11-4.el6.centos.2        ################################# [100%]
9、不执行脚本
1、查看脚本
[root@izpo45bh60h6bsz ~]# rpm -qp --scripts zsh-5.0.2-25.el7_3.1.x86_64.rpm
postinstall scriptlet (using /bin/sh):
if [ ! -f /etc/shells ] ; then  ## 安装后,判断/etc/shells是否不存在或不是普通文件
echo "/bin/zsh" > /etc/shells ##执行状态为0时,追加
else
grep -q "^/bin/zsh$" /etc/shells || echo "/bin/zsh" >> /etc/shells ## 表明存在且为普通文件,就查看文件中是否有/bin/zsh否则追加内容
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

postuninstall scriptlet (using /bin/sh):
if [ "$1" = 0 ] ; then
if [ -f /etc/shells ] ; then
TmpFile=`/bin/mktemp /tmp/.zshrpmXXXXXX`    ##将临时文件保存于/tmp下
grep -v '^/bin/zsh$' /etc/shells > $TmpFile ##将非匹配到的行保存至临时目录
cp -f $TmpFile /etc/shells  ## 非交互式复制非匹配的行至/etc/shells文件中
rm -f $TmpFile              ## 非交互式删除生成的文件
fi
fi

2、不执行脚本
[root@izpo45bh60h6bsz ~]# rpm -e --nopostun zsh
由以上脚本可知,传递的$1不为0
不会将/etc/shells目录中的/bin/zsh删除
[root@izpo45bh60h6bsz ~]# cat /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/usr/bin/sh
/usr/bin/bash
/usr/sbin/nologin

/bin/zsh


升级程序包
rpm -Uvh [OPTIONS...] PACKAGE_FILE
rpm -Fvh [OPTIONS...] PACKAGE_FILE
--oldpackage ## 用旧版程序包替换新版本的程序包

--force ## 强行升级

查询程序包(默认对已经安装的程序包进行操作)
rpm -q [select_option]
select_option:查询结果为程序包
-a ## 查询所有已安装的程序包
-f filepath ## 查询文件由哪个程序包生成
-g groupname ## 查询指定包组内相关的程序包

--whatprovide CAPABILITY ## CAPABILITY(文件或功能)由哪个程序包所提供
--whatrequire CAPABILITY ## CAPABILITY被哪个程序包所依赖

   rpm -q [query_option] PACKAGE_FILE
query_option:查询程序包中的文件内容或列表
查询包中文件列表:(默认对已安装的程序包的查询可缩写:zsh-5.0.2-25.el7_3.1.x86_64.rpm zsh)
-p ## 查询未安装的程序包
-l ## 列出程序包内的文件列表

-c ## 包内的配置文件列表
-d ## doc列表
查询包中文件内容:
--changelog   ## 列出程序包的changelog,而非程序的changelog
-i, information ## 查询包的Information

-L       ## 包的Lisence

-scripts    ## 包的脚本段

--triggers   ## 包的触发器

    -provides ## 包提供的CAPABILITY

-R ## 包所依赖的CAPABITY

--conflicts 程序包冲突

使用示例
1、查询所有已经安装的程序包: rpm -qa
2、查询文件由哪个程序包所提供: rpm -qf /bin/ls
3、查询组内相关的程序包:  rpm -q -g "System Environment/Shells"
4、程序包与哪些程序包冲突 :
5、CAPABILITY(文件或功能)由哪个程序包所提供: rpm -q --whatprovides /bin/ls
6、CAPABILITY(文件或功能)被哪个程序包所依赖: rpm -q --whatrequires /bin/ls
1、查询已经安装的程序包: rpm -q zsh
2、查询程序包的文件列表: rpm -ql zsh
未安装: rpm -qpl zsh-5.0.2-25.el7_3.1.x86_64.rpm
3、包中配置文件列表: rpm -qc zsh
未安装: rpm -qcp zsh-5.0.2-25.el7_3.1.x86_64.rpm
4、文档列表: rpm -qd zsh
未安装: rpm -qpd zsh-5.0.2-25.el7_3.1.x86_64.rpm
8、查询程序包中changelog内容: rpm -q --changelog zsh
未安装: rpm -qp --changelog zsh-4.3.11-4.el6.centos.2.i686.rpm
9、查询信息: rpm -qi zsh
未安装: rpm -qp -i zsh-4.3.11-4.el6.centos.2.i686.rpm
10、查询lisense: rpm -qL zsh
未安装;rpm -qp -L zsh-4.3.11-4.el6.centos.2.i686.rpm
11、查询脚本: rpm -q --scripts zsh
查询未安装:  rpm -qp --scripts zsh-4.3.11-4.el6.centos.2.i686.rpm
12、查询trigger: rpm -q --triggers zsh
未安装: rpm -qp --triggers zsh-4.3.11-4.el6.centos.2.i686.rpm

13、查询包提供的功能和文件: rpm -q --provides zsh
未安装:rpm -qp --provides zsh-4.3.11-4.el6.centos.2.i686.rpm

14、查询包所依赖的功能和文件: rpm -q -R zsh
未安装: rpm -qp -R zsh-4.3.11-4.el6.centos.2.i686.rpm
[root@izpo45bh60h6bsz ~]# rpm -qp -i zsh-4.3.11-4.el6.centos.2.i686.rpm
警告:zsh-4.3.11-4.el6.centos.2.i686.rpm: 头V3 RSA/SHA1 Signature, 密钥 ID c105b9de: NOKEY
Name        : zsh
Version     : 4.3.11
Release     : 4.el6.centos.2 (程序包的release号码.操作系统平台.)
Architecture: i686  (CPU平台)
Install Date: (not installed)
Group       : System Environment/Shells
Size        : 5055025
License     : BSD
Signature   : RSA/SHA1, 2016年03月23日 星期三 03时39分31秒, Key ID 0946fca2c105b9de
Source RPM  : zsh-4.3.11-4.el6.centos.2.src.rpm   ## 源码文件名
Build Date  : 2016年03月23日 星期三 02时54分00秒  ## rpm包创建时间
Build Host  : c6b8.bsys.dev.centos.org            ## 地点
Relocations : (not relocatable)                   ## 是否能自定义安装的位置
Packager    : CentOS BuildSystem <   ## 制作者
Vendor      : CentOS                          ## 发行商
URL         :           ##  (程序包的官方站点
Summary     : A 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.

** 创建rpm时,以上信息,自己定义


卸载程序包

rpm {-e|--erase} [--nodeps] [--noscripts] [--notriggers] [--test] PACKAGE_NAME ...
1)如果配置改变,卸载时,配置文件保存为.rpmsave。覆盖安装时,配置文件名为rpmnew
2)配置文件不变,安装时,不会安装配置文件

1、卸载时保留修改过的配置文件,名字为: rpmsave
[root@izpo45bh60h6bsz ~]# rpm -ivh zsh-5.0.2-25.el7_3.1.x86_64.rpm
准备中...                          ################################# [100%]
正在升级/安装...
1:zsh-5.0.2-25.el7_3.1             ################################# [100%]
[root@izpo45bh60h6bsz ~]# rpm -qc zsh
/etc/skel/.zshrc
/etc/zlogin
/etc/zlogout
/etc/zprofile
/etc/zshenv
/etc/zshrc
[root@izpo45bh60h6bsz ~]# echo "#" >> /etc/zshenv
[root@izpo45bh60h6bsz ~]# rpm -e zsh
警告:/etc/zshenv 已另存为 /etc/zshenv.rpmsave

2、安装时
[root@izpo45bh60h6bsz ~]# rpm -ivh zsh-5.0.2-25.el7_3.1.x86_64.rpm
准备中...                          ################################# [100%]
软件包 zsh-5.0.2-25.el7_3.1.x86_64 已经安装
[root@izpo45bh60h6bsz ~]# rpm -ivh --repalcepkgs  zsh-5.0.2-25.el7_3.1.x86_64.rpm
rpm: --repalcepkgs: 未知的选项
[root@izpo45bh60h6bsz ~]# rpm -ivh --replacepkgs  zsh-5.0.2-25.el7_3.1.x86_64.rpm
准备中...                          ################################# [100%]
正在升级/安装...
1:zsh-5.0.2-25.el7_3.1             ################################# [100%]
[root@izpo45bh60h6bsz ~]# ls /etc/zsh*
/etc/zshenv  /etc/zshenv.rpmsave  /etc/zshrc  /etc/zshrc.rpmnew


校验程序包
rpm -V [selection-option] [verify-options] [PACKAGE_FILE...]

不校验的选项启用
--nodeps
--nodigest
--nofiles
--noscripts
--nosignature
--nolinkto
--nofiledigest (formerly --nomd5)
--nosize
--nouser
--nogroup
--nomtime
--nomode
--nordev
校验的内容
S:大小改变
5:md5
T: modify timestamp
D:device,主次设备号不匹配
L:link路径
U:user
G:group

使用示例
1、安装,验证文件,
[root@izpo45bh60h6bsz ~]# rpm -ivh zsh-5.0.2-25.el7_3.1.x86_64.rpm
准备中...                          ################################# [100%]
正在升级/安装...
1:zsh-5.0.2-25.el7_3.1             ################################# [100%]

2、安装后验证
[root@izpo45bh60h6bsz ~]# rpm -V zsh

3、改变访问时间戳
[root@izpo45bh60h6bsz ~]# touch -a /etc/zshrc
[root@izpo45bh60h6bsz ~]# rpm -V zsh

4、改变修改时间戳
[root@izpo45bh60h6bsz ~]# touch -m /etc/zshrc
[root@izpo45bh60h6bsz ~]# rpm -V zsh
.......T.  c /etc/zshrc

## cat 不会引起任何时间戳的变化
## vim 会引起所有时间戳的变化
[root@izpo45bh60h6bsz ~]# stat /etc/zshrc  ## 初始时间戳
文件:"/etc/zshrc"
大小:1135      	块:8          IO 块:4096   普通文件
设备:fd01h/64769d	Inode:541815      硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
最近访问:2017-08-15 14:39:37.409558642 +0800
最近更改:2017-08-15 14:39:35.729558698 +0800
最近改动:2017-08-15 14:39:35.729558698 +0800
创建时间:-

[root@izpo45bh60h6bsz ~]# vim /etc/zshrc  ## :wq
[root@izpo45bh60h6bsz ~]# stat /etc/zshrc
文件:"/etc/zshrc"
大小:1135      	块:8          IO 块:4096   普通文件
设备:fd01h/64769d	Inode:541818      硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
最近访问:2017-08-15 14:42:46.131552417 +0800
最近更改:2017-08-15 14:42:46.131552417 +0800
最近改动:2017-08-15 14:42:46.135552416 +0800
创建时间:-

[root@izpo45bh60h6bsz ~]# vim /etc/zshrc  ## :q
[root@izpo45bh60h6bsz ~]# stat /etc/zshrc
文件:"/etc/zshrc"
大小:1135      	块:8          IO 块:4096   普通文件
设备:fd01h/64769d	Inode:541818      硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
最近访问:2017-08-15 14:43:03.997551827 +0800  ##访问时间戳都变化了
最近更改:2017-08-15 14:42:46.131552417 +0800
最近改动:2017-08-15 14:42:46.135552416 +0800  ##为什么改变时间戳不变呢
创建时间:-

再试一次
[root@izpo45bh60h6bsz ~]# rpm -V zsh
S.5....T.  c /etc/zprofile
[root@izpo45bh60h6bsz ~]# rpm -V --nosize zsh ##不校验大小
..5....T.  c /etc/zprofile

[root@izpo45bh60h6bsz ~]# rpm -V --nofiledigest zsh   ## 不校验MD5值
S......T.  c /etc/zprofile

[root@izpo45bh60h6bsz ~]# rpm -V --nomtime zsh  ## 不校验修改时间戳
S.5......  c /etc/zprofile


在程序包安装前对包的来源合法性及完整性验正
完整性验正: md5,sha1,sha128,sha256,sha384,sh512
来源合法性: RSA
对来源合法性和完整性验正: GPG

加密类型:

对称加密:加解密同一密钥
非对称加密 加解密不同密钥,pk(public key) sk(secre key)
1、用一个密钥加密,只能用与之匹配的另一个密钥解密

2、私钥不能公开,公钥公开

对将要安装的程序包的校验
1、程序包提供的公钥导入至系统: rpm -import RPM-GPG-KEY-CentOS-7
2、程序包安装时,不再出现错误信息

数据库维护

位置;/var/lib 程序的状态信息
当数据库损坏时,重建数据库
--rebuildb 直接重建
--initdb 存在数据库不会重建,不存在时,重建
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux