1. 程式人生 > >rpm管理程序包雜記

rpm管理程序包雜記

rpm linux 命令 基礎 雜記

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 <[email protected]> - 4.3.11-5.el6_7.2
- signal-handling related fixes collected from upstream (#1316945)

* Tue Oct 20 2015 Kamil Dudka <[email protected]> - 4.3.11-4.el6_7.1
- fix malloc() signal leak in lexsave() (#1267903)

* Mon May 18 2015 Kamil Dudka <[email protected]> - 4.3.11-4
- signal safety when updating global state (#978613)

* Mon Feb 23 2015 Kamil Dudka <[email protected]> - 4.3.11-3
- signal safety when updating global state in execshfunc() (#978613)

* Tue Jan 13 2015 Kamil Dudka <[email protected]> - 4.3.11-2
- fix defects found by GCC and Coverity Analysis (#1181608)

* Thu Nov 20 2014 Kamil Dudka <[email protected]> - 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]# 

rpm管理程序包雜記