[root@localhost ~]# mount /dev/cdrom /media #掛載centos官網發行的光盤 [root@localhost ~]# ls /media #centos光盤中自帶了許多rpm包,位於Packages目錄中 CentOS_BuildTag EULA imagesPackagesrepodata RPM-GPG-KEY-CentOS-Debug-6 RPM-GPG-KEY-CentOS-Testing-6 EFI GPL isolinux RELEASE-NOTES-en-US.html RPM-GPG-KEY-CentOS-6 RPM-GPG-KEY-CentOS-Security-6 TRANS.TBL [root@localhost ~]# cd /media/Packages/ [root@localhost Packages]# ls ... libreoffice-langpack-et-4.0.4.2-9.el6.x86_64.rpm zlib-devel-1.2.3-29.el6.x86_64.rpm libreoffice-langpack-eu-4.0.4.2-9.el6.x86_64.rpm zsh-4.3.10-7.el6.x86_64.rpm [root@localhost Packages]# rpm -ivh --test samba-3.6.9-164.el6.x86_64.rpm #測試安裝 warning: samba-3.6.9-164.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY #警告:沒有公鑰,無法驗證包的合法性 Preparing...########################################### [100%] [root@localhost Packages]# rpm --import ../RPM-GPG-KEY-CentOS-6 #導入光盤中提供的公鑰 [root@localhost Packages]# rpm -ivh --test samba-3.6.9-164.el6.x86_64.rpm #可以看到警告信息已消除,驗證通過 Preparing...########################################### [100%] [root@localhost Packages]# rpm -K samba-3.6.9-164.el6.x86_64.rpm #還可手動檢查 samba-3.6.9-164.el6.x86_64.rpm: rsa sha1 (md5) pgp md5 OK [root@localhost Packages]# rpm -qa gpg-pubkey* #查看已導入的所有公鑰 gpg-pubkey-c105b9de-4e0fd3a3 [root@localhost Packages]# rpm -qi gpg-pubkey-c105b9de-4e0fd3a3 #查看指定公鑰的詳細信息 Name : gpg-pubkey Relocations: (not relocatable) Version : c105b9de Vendor: (none) Release : 4e0fd3a3Build Date: Wed 28 Oct 2015 08:31:40 PM CST Install Date: Wed 28 Oct 2015 08:31:40 PM CSTBuild Host: localhost Group : Public Keys Source RPM: (none) Size : 0 License: pubkey Signature : (none) Summary : gpg(CentOS-6 Key (CentOS 6 Official Signing Key) <[email protected]>) Description : -----BEGIN PGP PUBLIC KEY BLOCK----- Version: rpm-4.8.0 (NSS-3) mQINBE4P06MBEACqn48FZgYkG2QrtUAVDV58H6LpDYEcTcv4CIFSkgs6dJ9TavCW ...
㈡安裝程序包 rpm -i [option] /path/to/package_file 常用選項: -i:install -h:安裝時顯示hash碼,用來表示安裝進度 -v:顯示執行過程 -vv:詳細顯示執行過程 --test:僅作測試,並不真正安裝 --nodeps:忽略依賴關系 --replacepkgs:重新安裝。如果原有的配置文件作了修改,重裝可能不執行替換,而是將新生成的配置文件重命名為X.rpmnew 常用組合選項:-ivh 如果依賴於其它包: ①解決依賴關系 ②使用--nodeps選項忽略依賴關系,能安裝上,但可能無法運行
[root@localhost Packages]# rpm -ivh samba-3.6.9-164.el6.x86_64.rpm Preparing...########################################### [100%] 1:samba########################################### [100%] [root@localhost Packages]# rpm -ivh --test mysql-5.1.71-1.el6.x86_64.rpm error: Failed dependencies:提示需要先解決依賴關系 libmysqlclient.so.16()(64bit) is needed by mysql-5.1.71-1.el6.x86_64 libmysqlclient.so.16(libmysqlclient_16)(64bit) is needed by mysql-5.1.71-1.el6.x86_64 libmysqlclient_r.so.16()(64bit) is needed by mysql-5.1.71-1.el6.x86_64 libmysqlclient_r.so.16(libmysqlclient_16)(64bit) is needed by mysql-5.1.71-1.el6.x86_64 mysql-libs = 5.1.71-1.el6 is needed by mysql-5.1.71-1.el6.x86_64 [root@localhost Packages]# rpm -ivh mysql-libs-5.1.71-1.el6.x86_64.rpm #安裝被依賴的包 Preparing...########################################### [100%] 1:mysql-libs ########################################### [100%] [root@localhost Packages]# rpm -ivh mysql-5.1.71-1.el6.x86_64.rpm Preparing...########################################### [100%] 1:mysql########################################### [100%]
㈢卸載程序包 rpm -e [option] pkg_name 常用選項: -e:erase -v,-vv,--test,--nodeps 如果被其它包依賴: ①將依賴於此包的所有包都卸載 ②忽略依賴關系,能卸載,但可能造成其它包無法正常使用 如果包的配置文件被修改,卸載時此文件將會被重命名(X.rpmsave)並保留
[root@localhost Packages]# rpm -e mysql-libs #卸載指定的包 error: Failed dependencies: #提示該包被mysql包依賴,無法卸載 libmysqlclient.so.16()(64bit) is needed by (installed) mysql-5.1.71-1.el6.x86_64 libmysqlclient.so.16(libmysqlclient_16)(64bit) is needed by (installed) mysql-5.1.71-1.el6.x86_64 libmysqlclient_r.so.16()(64bit) is needed by (installed) mysql-5.1.71-1.el6.x86_64 libmysqlclient_r.so.16(libmysqlclient_16)(64bit) is needed by (installed) mysql-5.1.71-1.el6.x86_64 mysql-libs = 5.1.71-1.el6 is needed by (installed) mysql-5.1.71-1.el6.x86_64 [root@localhost Packages]# rpm -e --nodeps mysql-libs #忽略依賴關系強制卸載 [root@localhost Packages]# mysql #可以看到mysql已無法使用了 mysql: error while loading shared libraries: libmysqlclient.so.16: cannot open shared object file: No such file or directory [root@localhost Packages]# vim /etc/samba/smbusers [root@localhost Packages]# rpm -e samba #卸載samba warning: /etc/samba/smbusers saved as /etc/samba/smbusers.rpmsave #可以看到,修改後的配置文件在程序卸載後會保留
㈣升級程序包:新版本取代老版本 rpm -U/-F [option] /path/to/package_file 常用選項: -U:升級或安裝。不管有無老版本,都安裝新版本 -F:純升級。有老版本才安裝新版本,沒有的話就不安裝 --force:強制升級,可能導致依賴此包的程序無法正常運行 -v,-h 常用組合選項:-Uvh,-Fvh 注意:不應該對內核執行升級操作,對於新內核應該直接安裝,系統支持多內核並存,新內核若有兼容性問題還能用回老內核。
[root@localhost ~]# rpm -q zsh package zsh is not installed #顯示zsh沒有安裝 [root@localhost ~]# rpm -Fvh /media/Packages/zsh-4.3.10-7.el6.x86_64.rpm #沒有老版本,不安裝 [root@localhost ~]# rpm -Uvh /media/Packages/zsh-4.3.10-7.el6.x86_64.rpm #不管有無老版本,都安裝新版本 Preparing...########################################### [100%] 1:zsh ########################################### [100%] [root@localhost ~]# rpm -q mysql mysql-5.1.71-1.el6.x86_64 [root@localhost ~]# rpm -Fvh mysql-5.1.73-5.el6_6.x86_64.rpm #安裝新版本的mysql error: Failed dependencies:提示依賴新版本的mysql-libs包 mysql-libs = 5.1.73-5.el6_6 is needed by mysql-5.1.73-5.el6_6.x86_64 [root@localhost ~]# rpm -Fvh mysql-libs-5.1.73-5.el6_6.x86_64.rpm error: Failed dependencies: mysql-libs = 5.1.71-1.el6 is needed by (installed) mysql-5.1.71-1.el6.x86_64 # 這裡出現了一個問題:要升級mysql包,需要先升級其所依賴的mysql-libs包,而mysql-libs包無法升級,因為它被現有mysql包依賴,故這裡只能先卸載 [root@localhost ~]# rpm -e --nodeps mysql-libs [root@localhost ~]# rpm -ivh mysql-libs-5.1.73-5.el6_6.x86_64.rpm Preparing...########################################### [100%] 1:mysql-libs ########################################### [100%] [root@localhost ~]# rpm -Fvh mysql-5.1.73-5.el6_6.x86_64.rpm Preparing...########################################### [100%] 1:mysql########################################### [100%] [root@localhost ~]# rpm -q mysql mysql-5.1.73-5.el6_6.x86_64 #已升級至新版本
㈤查詢操作 rpm -q [option] [pkg_name] 常用查詢操作: ①查詢某包是否已安裝:rpm -q pkg_name ②查詢所有已安裝的包:rpm -qa 可結合grep命令使用,查詢符合指定范式的包:rpm -qa | grep 'PATTERN' ③查詢包的描述信息:rpm -qi pkg_name ④查詢某包生成了哪些文件:rpm -ql pkg_name 查詢某包生成了哪些配置文件:rpm -qc pkg_name 查詢某包生成了哪些幫助文件:rpm -qd pkg_name 查詢程序包相關的腳本:rpm -q --scripts pkg_name 腳本有四類: preinstall:安裝前腳本 postinstall:安裝後腳本 preuninstall:卸載前腳本 postuninstall:卸載後腳本 ⑤查詢某個文件由哪個包安裝生成:rpm -qf /path/to/somefile ⑥對尚未安裝的包進行查詢:rpm [option] /path/to/pkg_file,可用組合選項有-qpi,-qpl,-qpc,-qpd等
[root@localhost Packages]# rpm -q samba #查詢samba是否已安裝 samba-3.6.9-164.el6.x86_64 [root@localhost Packages]# rpm -qa #查詢所有已安裝的包 pulseaudio-module-gconf-0.9.21-14.el6_3.x86_64 db4-devel-4.7.25-18.el6_4.x86_64 libxklavier-4.0-9.el6.x86_64 ... [root@localhost Packages]# rpm -qa | grep 'mysql' mysql-libs-5.1.71-1.el6.x86_64 mysql-5.1.71-1.el6.x86_64 [root@localhost Packages]# rpm -ql samba #查看samba包生成了哪些文件 /etc/logrotate.d/samba /etc/openldap/schema /etc/openldap/schema/samba.schema /etc/pam.d/samba /etc/rc.d/init.d/nmb /etc/rc.d/init.d/smb /etc/samba/smbusers /usr/bin/eventlogadm /usr/bin/mksmbpasswd.sh /usr/bin/smbstatus /usr/lib64/samba/auth ... [root@localhost Packages]# rpm -qc samba #查看samba包生成了哪些配置文件 /etc/logrotate.d/samba /etc/pam.d/samba /etc/samba/smbusers [root@localhost Packages]# rpm -qd samba #查看samba包生成了哪些幫助文件 /usr/share/doc/samba-3.6.9/LDAP/README ... /usr/share/man/man7/samba.7.gz ... [root@localhost Packages]# rpm -qf /etc/openldap/schema #查詢指定文件由哪個包安裝生成 samba-3.6.9-164.el6.x86_64 [root@localhost Packages]# rpm -qpi httpd-2.2.15-29.el6.centos.x86_64.rpm #安裝httpd包前查看其詳細信息 Name : httpdRelocations: (not relocatable) Version : 2.2.15Vendor: CentOS
㈥校驗程序包:用於檢查包安裝生成的文件屬性是否發生變化 rpm -V pkg_name [root@localhost ~]# vim /etc/httpd/conf/httpd.conf [root@localhost ~]# rpm -V httpd S.5....T. c /etc/httpd/conf/httpd.conf #我們修改了httpd配置文件,可以看到其大小、MD5校驗碼及修改時間均發生了改變,其它屬性無變化 見上方命令行中的"S.5....T.",rpm用七個段位分別表示文件七種不同屬性的變化狀態,這七種屬性分別為: S file Size differs #大小 M Mode differs (includes permissions and file type) #權限 5 digest (formerly MD5 sum) differs #MD5校驗碼 D Device major/minor number mismatch #設備文件的主次設備號 L readLink(2) path mismatch U User ownership differs #屬主 G Group ownership differs #屬組 T mTime differs #修改時間 P caPabilities differ 若對應段位的屬性有改變,則顯示為對應字母標識;無變化則顯示為【.】 ㈦rpm包管理器的數據庫重建 ①rpm包管理器的數據庫目錄:/var/lib/rpm ②rpm --initdb:初始化。如果事先沒有庫,會新建一個,有庫的話就不新建 rpm --rebuilddb:重建。直接重建,覆蓋原有的數據庫
[root@localhost ~]# ls /var/lib/rpm Basenames __db.001 __db.003 Dirnames Group NamePackages Provideversion Requirename Sha1header Triggername Conflictname __db.002 __db.004 Filedigests Installtid Obsoletename Providename Pubkeys Requireversion Sigmd5 [root@localhost ~]# rpm --initdb #已有庫,則不會新建 [root@localhost ~]# rpm --rebuilddb [root@localhost ~]# ls /var/lib/rpm Basenames Dirnames Group NamePackages Provideversion Requirename Sha1header Triggername Conflictname Filedigests Installtid Obsoletename Providename Pubkeys Requireversion