1、rpm升级、降级
- 升级安装
rpm -Uvh kernel-2.6.32-696.el6.x86_64.rpm ---升级安装
rpm -ivh kernel-2.6.32-642.el6.x86_64.rpm --oldpackage ---降级安装
rpm -ivh kernel-2.6.32-642.el6.x86_64.rpm ---重新安装
总结:降级安装和重新安装内核时不会把原有的内核也删掉,系统会并存两个内核,但升级安装时会把原有的内核也删除,建议生成中不要升级安装内核。
2、rpm2cpio
[root@centos6 app]#rpm2cpio /misc/cd/Packages/tree-1.5.3-3.el6.x86_64.rpm |cpio -ivt ---预览包内文件,可以看到包内的文件写的都是相对路径
-rwxr-xr-x 1 root root 41136 Jan 14 2015 ./usr/bin/tree
drwxr-xr-x 2 root root 0 Jan 14 2015 ./usr/share/doc/tree-1.5.3
-rw-r--r-- 1 root root 18009 Aug 13 2004 ./usr/share/doc/tree-1.5.3/LICENSE
-rw-r--r-- 1 root root 4167 Oct 20 2009 ./usr/share/doc/tree-1.5.3/README
-rw-r--r-- 1 root root 3375 Jan 14 2015 ./usr/share/man/man1/tree.1.gz
132 blocks
[root@centos6 app]#rpm2cpio /misc/cd/Packages/tree-1.5.3-3.el6.x86_64.rpm |cpio -iv ./usr/bin/tree ---只解包./usr/bin/tree这个文件,但是当前app这个目录下没有usr这个目录
cpio: ./usr/bin/tree: Cannot open: No such file or directory
./usr/bin/tree
132 blocks
[root@centos6 app]#ls
[root@centos6 app]#ls
[root@centos6 app]#rpm2cpio /misc/cd/Packages/tree-1.5.3-3.el6.x86_64.rpm |cpio -ivd ./usr/bin/tree ---用-d选项可以解包还原时自动生成目录,
./usr/bin/tree
132 blocks
[root@centos6 app]#ls --解包到当前的app目录下usr/bin/tree
usr
[root@centos6 app]#cd usr
[root@centos6 usr]#ls
bin
[root@centos6 usr]#cd bin
[root@centos6 bin]#ls
tree
总结:需要注意的是包内的文件写的都是相对路径,解包时只能解包到前期目录,所以解包时最好先进入指定目录,然后在解包,这样可以把这个文件正好解包到这个目录,并且不用-d选项,否则要在别的目录下创建之后在移动到目标目录。
3、破坏tree程序的一个文件,安装和重新安装的区别
[root@centos6 app]#rm -f /usr/bin/tree ---删除/usr/bin/tree 这个文件
[root@centos6 app]#tree --tree已经无法使用
-bash: /usr/bin/tree: No such file or directory
[root@centos6 app]#rpm -ivh /misc/cd/Packages/tree-1.5.3-3.el6.x86_64.rpm ---安装后显示安装成功了
warning: /misc/cd/Packages/tree-1.5.3-3.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing... ########################################### [100%]
package tree-1.5.3-3.el6.x86_64 is already installed
[root@centos6 app]#tree ---但tree仍然无法使用
-bash: /usr/bin/tree: No such file or directory
[root@centos6 app]#rpm -ivh /misc/cd/Packages/tree-1.5.3-3.el6.x86_64.rpm --force ---强制重新安装
warning: /misc/cd/Packages/tree-1.5.3-3.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing... ########################################### [100%]
1:tree ########################################### [100%]
[root@centos6 app]#tree ---tree可以使用
.
└── usr
└── bin
└── tree
2 directories, 1 file
总结:我们只是破坏了tree的一个文件,并没有破坏所有的文件,所有在安装时显示虽然是100%,但并没有重新安装,跟用rpm -e tree卸载不同,卸载相当于把tree所有的文件都卸载了,这个时候不用--force安装就可以,但如果只破坏了某一个文件只能用--force强制重新安装后。
4、rpm的查询
rpm -qp --scripts /misc/cd/Packages/mod_ssl-2.2.15-59.el6.centos.x86_64.rpm ---查询未安装的文件包中包含的脚本
rpm -q --scripts rpm ---查询已安装的包包含哪些脚本
[root@centos6 ~]#rpm -q tree ---查询tree包来源于哪个软件包
tree-1.5.3-3.el6.x86_64
rpm -qf /usr/bin/tree ---如果tree包没有安装,可以-f通过写路径查询
rpm -qi tree ---查询已安装的包的信息,也可以用-p加上路径,查看未安装的包的信息。
[root@centos6 ~]#rpm -ql tree ---查询安装包生成的文件,可以用-p加路径查看未安装的包安装后将生成的文件列表
/usr/bin/tree
/usr/share/doc/tree-1.5.3
/usr/share/doc/tree-1.5.3/LICENSE
/usr/share/doc/tree-1.5.3/README
/usr/share/man/man1/tree.1.gz
[root@centos6 ~]#rpm -qa |grep tre ---查询所有已安装的包,可以用grep过滤一下
gstreamer-python-0.10.16-1.1.el6.x86_64
gstreamer-plugins-bad-free-0.10.19-5.el6_8.x86_64
gstreamer-tools-0.10.29-1.el6.x86_64
libspectre-0.2.4-2.el6.x86_64
gstreamer-0.10.29-1.el6.x86_64
portreserve-0.0.4-11.el6.x86_64
phonon-backend-gstreamer-4.6.2-28.el6_5.x86_64
PackageKit-gstreamer-plugin-0.5.8-26.el6.x86_64
gstreamer-plugins-base-0.10.29-2.el6.x86_64
gstreamer-plugins-good-0.10.23-4.el6_8.x86_64
tree-1.5.3-3.el6.x86_64
5、包校验
[root@centos6 ~]#rpm -V tree
[root@centos6 ~]#rpm -ql tree
/usr/bin/tree
/usr/share/doc/tree-1.5.3
/usr/share/doc/tree-1.5.3/LICENSE
/usr/share/doc/tree-1.5.3/README
/usr/share/man/man1/tree.1.gz
[root@centos6 ~]#ll /usr/bin/tree
-rwxr-xr-x. 1 root root 41136 Jan 14 2015 /usr/bin/tree
[root@centos6 ~]#chown zhang /usr/bin/tree ---改变其中一个文件的所有者
[root@centos6 ~]#ll /usr/bin/tree
-rwxr-xr-x. 1 zhang root 41136 Jan 14 2015 /usr/bin/tree
[root@centos6 ~]#rpm -V tree ---可以检测出来所有者发生改变了
.....U... /usr/bin/tree
总结:检查包一些元数据信息是否改变,不需要导入钥匙也可以校验。
6、检查包的签名和完整性
[root@centos6 Packages]#rpm -ivh tree-1.5.3-3.el6.x86_64.rpm
warning: tree-1.5.3-3.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY ---有警报
Preparing... ########################################### [100%]
package tree-1.5.3-3.el6.x86_64 is already installed
[root@centos6 Packages]#cd /etc/pki/rpm-gpg/ ---进入这个目录下或者进入光盘/misc/cd
[root@centos6 rpm-gpg]#ls
RPM-GPG-KEY-CentOS-6 RPM-GPG-KEY-CentOS-Security-6
RPM-GPG-KEY-CentOS-Debug-6 RPM-GPG-KEY-CentOS-Testing-6
[root@centos6 rpm-gpg]#rpm --import RPM-GPG-KEY-CentOS-6 ---将公钥导入
[root@centos6 rpm-gpg]#cdpack
[root@centos6 Packages]#rpm -ivh tree-1.5.3-3.el6.x86_64.rpm ---再安装已经没有警报了
Preparing... ########################################### [100%]
package tree-1.5.3-3.el6.x86_64 is already installed
[root@centos6 Packages]#rpm -K tree-1.5.3-3.el6.x86_64.rpm
tree-1.5.3-3.el6.x86_64.rpm: rsa sha1 (md5) pgp md5 OK ---导入钥匙后检查包就ok
[root@centos6 Packages]#rpm -qa "gpg-pubkey" ---查询导入的公钥
gpg-pubkey-c105b9de-4e0fd3a3
[root@centos6 Packages]#rpm -e gpg-pubkey-c105b9de-4e0fd3a3 ---删除公钥
[root@centos6 Packages]#rpm -ivh tree-1.5.3-3.el6.x86_64.rpm
warning: tree-1.5.3-3.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY ---再次安装时又有警报了
Preparing... ########################################### [100%]
package tree-1.5.3-3.el6.x86_64 is already installed
[root@centos6 Packages]#rpm -K tree-1.5.3-3.el6.x86_64.rpm ---K可以检查包的完整性和签名,如果没有钥匙就无法检查。显示的是notok
tree-1.5.3-3.el6.x86_64.rpm: RSA sha1 ((MD5) PGP) md5 NOT OK (MISSING KEYS: (MD5) PGP#c105b9de) ---没有钥匙
[root@centos6 app]#echo >>tree-1.5.3-3.el6.x86_64.rpm ---更改包的内容加了个空格
[root@centos6 rpm-gpg]#rpm --import RPM-GPG-KEY-CentOS-6 ---将公钥导入
[root@centos6 app]#rpm -K tree-1.5.3-3.el6.x86_64.rpm ---发现文件的完整性不对,所以显示的是notok
tree-1.5.3-3.el6.x86_64.rpm: RSA sha1 (MD5) PGP MD5 NOT OK
总结:用rpm -K 可以检查包的签名和完整性,前提是要先导入公钥。