9.3天程序包管理

0.1查看文件格式

[root@CentOS7 ~]# file /bin/ls
/bin/ls: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=aa7ff68f13de25936a098016243ce57c3c982e06, stripped

0.2光盘挂载

[root@CentOS7 ~]# mkdir /media/cdrom
[root@CentOS7 ~]# 
[root@CentOS7 ~]# mount /dev/cdrom /media/cdrom/
mount: /dev/sr0 is write-protected, mounting read-only
[root@CentOS7 ~]# df -lh
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda6        23G   56M   23G   1% /
devtmpfs        109M     0  109M   0% /dev
tmpfs           119M     0  119M   0% /dev/shm
tmpfs           119M  8.7M  110M   8% /run
tmpfs           119M     0  119M   0% /sys/fs/cgroup
/dev/sda5        30G  1.2G   29G   4% /usr
/dev/sda2        79G  152M   78G   1% /var
/dev/sda3        40G   33M   40G   1% /usr/local
/dev/sda7        10G   33M   10G   1% /home
/dev/sda9       6.9G   33M  6.8G   1% /tmp
/dev/md0        3.9G   16M  3.7G   1% /backup
/dev/sda1       197M  108M   90M  55% /boot
tmpfs            24M     0   24M   0% /run/user/0
/dev/sdc         40G   17M   38G   1% /mydata
/dev/sr0        3.7G  3.7G     0 100% /media/cdrom
[root@CentOS7 ~]# 

程序包管理

查看程序包的依赖关系

[root@CentOS7 Packages]# ldd /bin/ls
	linux-vdso.so.1 =>  (0x00007fffcc331000)  #库的入口,不是真正的库
	libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f4e29770000)   #前面试共享库,后面对应的是库名所对应的文件,数字是地址编址机制;
	libcap.so.2 => /lib64/libcap.so.2 (0x00007f4e2956b000)
	libacl.so.1 => /lib64/libacl.so.1 (0x00007f4e29361000)
	libc.so.6 => /lib64/libc.so.6 (0x00007f4e28fa0000)
	libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f4e28d3f000)
	liblzma.so.5 => /lib64/liblzma.so.5 (0x00007f4e28b19000)
	libdl.so.2 => /lib64/libdl.so.2 (0x00007f4e28915000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f4e2999e000)
	libattr.so.1 => /lib64/libattr.so.1 (0x00007f4e28710000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f4e284f3000)

查看运行在内存中的库文件及指向库文件的路径名称的映射关系

[root@CentOS7 Packages]# ldconfig -p
403 libs found in cache `/etc/ld.so.cache'
	p11-kit-trust.so (libc6,x86-64) => /lib64/p11-kit-trust.so
	libz.so.1 (libc6,x86-64) => /lib64/libz.so.1
	libyajl.so.2 (libc6,x86-64) => /lib64/libyajl.so.2
	libxtables.so.10 (libc6,x86-64) => /lib64/libxtables.so.10
	libxslt.so.1 (libc6,x86-64) => /lib64/libxslt.so.1
	libxshmfence.so.1 (libc6,x86-64) => /lib64/libxshmfence.so.1
	libxml2.so.2 (libc6,x86-64) => /lib64/libxml2.so.2
	libxmlrpc_util.so.3 (libc6,x86-64) => /lib64/libxmlrpc_util.so.3
	libxmlrpc_server_cgi.so.3 (libc6,x86-64) => /lib64/libxmlrpc_server_cgi.so.3
	libxmlrpc_server_abyss.so.3 (libc6,x86-64) => /lib64/libxmlrpc_server_abyss.so.3
	libxmlrpc_server.so.3 (libc6,x86-64) => /lib64/libxmlrpc_server.so.3
	libxmlrpc_client.so.3 (libc6,x86-64) => /lib64/libxmlrpc_client.so.3
	libxmlrpc_abyss.so.3 (libc6,x86-64) => /lib64/libxmlrpc_abyss.so.3
	libxmlrpc.so.3 (libc6,x86-64) => /lib64/libxmlrpc.so.3
……后面输出省略

统计运行在内存中的库文件个数

[root@CentOS7 Packages]# ldconfig -p | wc -l
404

9.4天程序包管理

9.4.1安装

安装软件包,并显示过程

[root@CentOS7 Packages]# rpm -ivh zsh-4.3.11-4.el6.centos.2.x86_64.rpm
warning: zsh-4.3.11-4.el6.centos.2.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:zsh-4.3.11-4.el6.centos.2        ################################# [100%]

安装包出错,显示需要依赖关系

[root@CentOS7 Packages]# rpm -ivh php-odbc-5.3.3-47.el6.x86_64.rpm
warning: php-odbc-5.3.3-47.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
error: Failed dependencies:
	libodbc.so.2()(64bit) is needed by php-odbc-5.3.3-47.el6.x86_64
	php-common(x86-64) = 5.3.3-47.el6 is needed by php-odbc-5.3.3-47.el6.x86_64
	php-pdo(x86-64) is needed by php-odbc-5.3.3-47.el6.x86_64

安装测试,不真正安装

	[root@CentOS7 Packages]# rpm -ivh --test php-odbc-5.3.3-47.el6.x86_64.rpm
warning: php-odbc-5.3.3-47.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
error: Failed dependencies:
	libodbc.so.2()(64bit) is needed by php-odbc-5.3.3-47.el6.x86_64
	php-common(x86-64) = 5.3.3-47.el6 is needed by php-odbc-5.3.3-47.el6.x86_64
	php-pdo(x86-64) is needed by php-odbc-5.3.3-47.el6.x86_64

忽略依赖关系安装,不建议

[root@CentOS7 Packages]# rpm -ivh php-odbc-5.3.3-47.el6.x86_64.rpm --nodeps
warning: php-odbc-5.3.3-47.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:php-odbc-5.3.3-47.el6            ################################# [100%]

重新安装,覆盖安装系统上已经有的包

[root@CentOS7 Packages]# rpm -ivh --replacepkgs zsh-4.3.11-4.el6.centos.2.x86_64.rpm
warning: zsh-4.3.11-4.el6.centos.2.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:zsh-4.3.11-4.el6.centos.2        ################################# [100%]

重装文件包并检查来源签名和包头的完整性

[root@CentOS7 Packages]# rpm -ivh --replacepkgs zsh-4.3.11-4.el6.centos.2.x86_64.rpm --nodigest --nosignature
Preparing...                          ################################# [100%]
Updating / installing...
   1:zsh-4.3.11-4.el6.centos.2        ################################# [100%]

查看内核版本

[root@CentOS7 Packages]# uname -r
3.10.0-327.el7.x86_64

9.4.2升级

9.4.3查询

查询系统上安装的所有程序包

[root@CentOS7 Packages]# rpm -qa
man-pages-overrides-7.2.4-1.el7.x86_64
rpm-libs-4.11.3-17.el7.x86_64
filesystem-3.2-20.el7.x86_64
iwl6000g2b-firmware-17.168.5.2-43.el7.noarch
libreport-python-2.1.11-32.el7.centos.x86_64
langtable-data-0.0.31-3.el7.noarch
iwl6000-firmware-9.221.4.1-43.el7.noarch
libreport-web-2.1.11-32.el7.centos.x86_64
quota-nls-4.01-11.el7.noarch
iwl135-firmware-18.168.6.1-43.el7.noarch
dhcp-common-4.2.5-42.el7.centos.x86_64
tzdata-java-2015g-1.el7.noarch
iwl7260-firmware-22.0.7.0-43.el7.noarch
libreport-plugin-rhtsupport-2.1.11-32.el7.centos.x86_64
glibc-2.17-105.el7.x86_64
zabbix-2.4.8-1.el6.x86_64
gsm-1.0.13-11.el7.x86_64
……后面省略

通过grep筛选查看哪些文件包是否安装

[root@CentOS7 Packages]# rpm -qa | grep "php"
php-odbc-5.3.3-47.el6.x86_64
[root@CentOS7 Packages]# rpm -qa php*

查询文件是由哪个文件包生成

[root@CentOS7 Packages]# rpm -qf /etc/issue
centos-release-7-2.1511.el7.centos.2.10.x86_64
[root@CentOS7 Packages]# rpm -qf /etc/fstab
setup-2.8.71-6.el7.noarch
[root@CentOS7 Packages]# rpm -qf /bin/ls
coreutils-8.22-15.el7.x86_64

查询rpm包历史的更新,修复信息

[root@CentOS7 Packages]# rpm -q --changelog zsh
* Tue Mar 01 2016 Kamil Dudka <kdudka@redhat.com> - 4.3.11-5.el6_7.2
- signal-handling related fixes collected from upstream (#1316945)

* Tue Oct 20 2015 Kamil Dudka <kdudka@redhat.com> - 4.3.11-4.el6_7.1
- fix malloc() signal leak in lexsave() (#1267903)

* Mon May 18 2015 Kamil Dudka <kdudka@redhat.com> - 4.3.11-4
- signal safety when updating global state (#978613)

* Mon Feb 23 2015 Kamil Dudka <kdudka@redhat.com> - 4.3.11-3
- signal safety when updating global state in execshfunc() (#978613)

* Tue Jan 13 2015 Kamil Dudka <kdudka@redhat.com> - 4.3.11-2
- fix defects found by GCC and Coverity Analysis (#1181608)

* Thu Nov 20 2014 Kamil Dudka <kdudka@redhat.com> - 4.3.11-1
- rebase to 4.3.11 (#1132710)
……

查询程序包的配置文件

[root@CentOS7 Packages]# rpm -q -c zsh
/etc/skel/.zshrc
/etc/zlogin
/etc/zlogout
/etc/zprofile
/etc/zshenv
/etc/zshrc

查看这个程序包与其相冲突的选项

[root@CentOS7 Packages]# rpm -q --conflicts zsh

查看程序包的帮助文档

[root@CentOS7 Packages]# rpm -q -d zsh
/usr/share/doc/zsh-4.3.11/BUGS
/usr/share/doc/zsh-4.3.11/CONTRIBUTORS
/usr/share/doc/zsh-4.3.11/FAQ
/usr/share/doc/zsh-4.3.11/FEATURES
/usr/share/doc/zsh-4.3.11/LICENCE
/usr/share/doc/zsh-4.3.11/MACHINES
/usr/share/doc/zsh-4.3.11/NEWS
/usr/share/doc/zsh-4.3.11/README
/usr/share/doc/zsh-4.3.11/completion-style-guide
/usr/share/doc/zsh-4.3.11/zsh-development-guide

查看包的简要信息

[root@CentOS7 Packages]# rpm -q -i zsh
Name        : zsh						#名称
Version     : 4.3.11					#版本
Release     : 4.el6.centos.2			#发行号
Architecture: x86_64					#支持平台
Install Date: Tue 19 Jul 2016 04:48:07 AM CST	#安装日期时间
Group       : System Environment/Shells	#所属包组
Size        : 5298977					#包大小
License     : BSD						#许可证,MIT=麻省理工
Signature   : RSA/SHA1, Wed 23 Mar 2016 03:39:32 AM CST, Key ID 0946fca2c105b9de  #签名信息,RSA能检查包来源合法性,SHA能检查包完整性
Source RPM  : zsh-4.3.11-4.el6.centos.2.src.rpm #包制作时,还提供了源码格式包
Build Date  : Wed 23 Mar 2016 02:57:38 AM CST 		#包制作时间
Build Host  : c6b8.bsys.dev.centos.org		 		#在哪个服务器制作
Relocations : (not relocatable)			#有没有被重新分布,定位;不能指定新位置安装,只能默认安装;
Packager    : CentOS BuildSystem <http:// bugs.centos.org>   #谁制作了这个包
Vendor      : CentOS  					#提供商
URL         : http://zsh.sunsite.dk/   	#包的官方站点
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.

单独列出包的许可协议

[root@CentOS7 Packages]# rpm -qL zsh

查看指定程序包安装后生成的所有文件

[root@CentOS7 Packages]# rpm -ql zsh
/bin/zsh
/etc/skel/.zshrc
/etc/zlogin
/etc/zlogout
/etc/zprofile
/etc/zshenv
/etc/zshrc
/usr/lib64/zsh
/usr/lib64/zsh/4.3.11
/usr/lib64/zsh/4.3.11/zsh
/usr/lib64/zsh/4.3.11/zsh/attr.so
/usr/lib64/zsh/4.3.11/zsh/cap.so
……

查看程序包内含的所有脚本

[root@CentOS7 Packages]# rpm -q --scripts zsh
postinstall scriptlet (using /bin/sh):
if [ ! -f /etc/shells ] ; then
    echo "/bin/zsh" > /etc/shells
else
    grep -q "^/bin/zsh$" /etc/shells || echo "/bin/zsh" >> /etc/shells
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 ] ; then
    if [ -f /etc/shells ] ; then
        TmpFile=`/bin/mktemp /tmp/.zshrpmXXXXXX`
        grep -v '^/bin/zsh$' /etc/shells > $TmpFile
        cp -f $TmpFile /etc/shells
        rm -f $TmpFile
    fi
fi
[root@CentOS7 Packages]# 

9.4.3 卸载

rpm -e zsh

9.4.4 校验

校验安装的文件是否被用户修改过配置

[root@CentOS7 ~]# rpm -V zsh
S.5....T.    /usr/share/zsh/4.3.11/functions/zmv

导入密钥,然后安装光盘里的文件包将不会提示校验码检验不过

[root@CentOS7 cdrom]# rpm --import RPM-GPG-KEY-CentOS-6
[root@CentOS7 Packages]# ls | grep zsh
zsh-4.3.11-4.el6.centos.2.x86_64.rpm    #下面已经没有提示检验有问题
[root@CentOS7 Packages]# rpm -ivh --replacepkgs zsh-4.3.11-4.el6.centos.2.x86_64.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:zsh-4.3.11-4.el6.centos.2        ################################# [100%]
[root@CentOS7 Packages]# 

查看rpm数据库目录

[root@CentOS7 Packages]# cd /var/lib/rpm
[root@CentOS7 rpm]# ll
total 37844
-rw-r--r--. 1 root root  1855488 Jul 19 09:04 Basenames
-rw-r--r--. 1 root root     8192 Jun 16 10:01 Conflictname
-rw-r--r--. 1 root root   270336 Jul 19 09:04 __db.001
-rw-r--r--. 1 root root    81920 Jul 19 09:04 __db.002
-rw-r--r--. 1 root root  1318912 Jul 19 09:04 __db.003
-rw-r--r--. 1 root root   430080 Jul 19 09:04 Dirnames
-rw-r--r--. 1 root root    12288 Jul 19 09:04 Group
-rw-r--r--. 1 root root    16384 Jul 19 09:04 Installtid
-rw-r--r--. 1 root root    36864 Jul 19 09:04 Name
-rw-r--r--. 1 root root    16384 Jul 19 04:32 Obsoletename
-rw-r--r--. 1 root root 32968704 Jul 19 09:04 Packages
-rw-r--r--. 1 root root  1560576 Jul 19 09:04 Providename
-rw-r--r--. 1 root root   180224 Jul 19 09:04 Requirename
-rw-r--r--. 1 root root    61440 Jul 19 09:04 Sha1header
-rw-r--r--. 1 root root    40960 Jul 19 09:04 Sigmd5
-rw-r--r--. 1 root root     8192 Jun 16 10:00 Triggername
[root@CentOS7 rpm]#