一、Linux下软件包的命名格式:
1.源码包
name-version.tar.[gz|bz2|xz]
version:major.minor.release
如:bash-4.1.2.tar.gz
2.rpm包
name-version-release.arch.rpm
version:major.minor.release #此release号是源码包的release号
release:rpm包的release号,可能会包含所适用的操作系统
el6:rhel6
el5:rhel5
centos6
suse11
......
arch:平台
x86:i386,i686
x86_64:redhat系列的软件包
amd64:debian系统的软件包
ppc:基于powerpc的软件包
noarch:不依赖于平台的软件包
如:bash-4.1.2.el6.x86_64.rpm
二、软件包的组成
1.二进制程序:/bin,/sbin,/usr/bin,/usr/sbin,/usr/local/bin,/usr/local/sbin
2.配置文件:/etc:纯文本、xml格式的配置文件
3.库文件:/lib,/usr/lib,/usr/local/lib
4.帮助手册:/usr/share/man, /usr/loacl/share/man
/usr/share/doc
三、软件包的获取方式
安装光盘
.....
四、RPM管理软件包
下面以光盘中的rpm包为例:
1.验证
验证我们使用的rpm包的合法性和完整性
[root@wsh /]# mount /dev/cdrom /media/cdrom/ #挂在光盘 mount: block device /dev/sr0 is write-protected, mounting read-only [root@wsh /]# cd /media/cdrom/ [root@wsh cdrom]# ls CentOS_BuildTag GPL RPM-GPG-KEY-CentOS-6 RPM-GPG-KEY-CentOS-Testing-6 isolinux EFI Packages RPM-GPG-KEY-CentOS-Debug-6 TRANS.TBL repodata EULA RELEASE-NOTES-en-US.html RPM-GPG-KEY-CentOS-Security-6 p_w_picpaths [root@wsh cdrom]# cd Packages/ [root@wsh Packages]# rpm --import /media/cdrom/RPM-GPG-KEY-CentOS-6 #--import导入光盘中的公钥;在/etc/pki/rpm-gpg/下也会有公钥 [root@wsh Packages]# rpm -K zsh-4.3.10-5.el6.x86_64.rpm #-K验证rpm包的合法性 zsh-4.3.10-5.el6.x86_64.rpm: rsa sha1 (md5) pgp md5 OK [root@wsh Packages]# rpm --checksig zsh-4.3.10-5.el6.x86_64.rpm #--checksig和-K一样 zsh-4.3.10-5.el6.x86_64.rpm: rsa sha1 (md5) pgp md5 OK
2.安装
-i:安装
-v:详细详细信息,-vv:比-v更详细
-h:显示安装进度条,一个#代表2%
-ivh:一般组合使用
-ivh --nodeps:忽略依赖关系
-ivh --test:测试安装
-ivh --replacepkgs:重新安装已经安装的rpm包
[root@wsh Packages]# pwd /media/cdrom/Packages #此目录下存放的就是rpm包 [root@wsh Packages]# ls | less 389-ds-base-1.2.10.2-15.el6.x86_64.rpm 389-ds-base-libs-1.2.10.2-15.el6.i686.rpm 389-ds-base-libs-1.2.10.2-15.el6.x86_64.rpm ....... [root@wsh Packages]# [root@wsh Packages]# rpm -ivh bind-dyndb-ldap-1.1.0-0.9.b1.el6.x86_64.rpm error: Failed dependencies: bind >= 32:9.6.1-0.3.b1 is needed by bind-dyndb-ldap-1.1.0-0.9.b1.el6.x86_64 #有的rpm包的安装,依赖于其他rpm包,这时就需要先安装其依赖的包 [root@wsh Packages]# rpm -ivh bind-9.8.2-0.10.rc1.el6.x86_64.rpm #安装依赖的包 Preparing... ########################################### [100%] 1:bind ########################################### [100%] [root@wsh Packages]# rpm -ivh bind-dyndb-ldap-1.1.0-0.9.b1.el6.x86_64.rpm #再次安装,成功 Preparing... ########################################### [100%] 1:bind-dyndb-ldap ########################################### [100%] [root@wsh Packages]# rpm -ivh --test zsh-4.3.10-5.el6.x86_64.rpm #只是测试,没有真正安装 Preparing... ########################################### [100%]
3.查询:
查询已安装的软件包信息:
-q name:
[root@wsh Packages]# rpm -q bind #查询bind是否安装 bind-9.8.2-0.10.rc1.el6.x86_64 [root@wsh Packages]# rpm -q bind-dyndb-ldap bind-dyndb-ldap-1.1.0-0.9.b1.el6.x86_64
-qa:查询所有已安装的包
[root@wsh Packages]# rpm -qa | grep "bind" #rpm -qa列出所有安装的包,grep匹配出你想查询的包 samba-winbind-clients-3.6.9-164.el6.x86_64 bind-dyndb-ldap-1.1.0-0.9.b1.el6.x86_64 rpcbind-0.2.0-11.el6.x86_64 bind-libs-9.8.2-0.10.rc1.el6.x86_64 bind-9.8.2-0.10.rc1.el6.x86_64 samba-winbind-3.6.9-164.el6.x86_64 ypbind-1.20.4-30.el6.x86_64 PackageKit-device-rebind-0.5.8-21.el6.x86_64
-qi name:查询包的摘要信息
[root@wsh Packages]# rpm -qi bind Name : bind Relocations: (not relocatable) Version : 9.8.2 Vendor: CentOS Release : 0.10.rc1.el6 Build Date: Fri Jun 22 23:24:10 2012 Install Date: Fri May 23 09:17:34 2014 Build Host: c6b7.bsys.dev.centos.org Group : System Environment/Daemons Source RPM: bind-9.8.2-0.10.rc1.el6.src.rpm Size : 7580392 License: ISC Signature : RSA/SHA1, Mon Jun 25 06:18:46 2012, Key ID 0946fca2c105b9de Packager : CentOS BuildSystem <http://bugs.centos.org> URL : http://www.isc.org/products/BIND/ Summary : The Berkeley Internet Name Domain (BIND) DNS (Domain Name System) server Description : BIND (Berkeley Internet Name Domain) is an implementation of the DNS (Domain Name System) protocols. BIND includes a DNS server (named), which resolves host names to IP addresses; a resolver library (routines for applications to use when interfacing with DNS); and tools for verifying that the DNS server is operating properly.
-ql name:查询安装生成文件清单
[root@wsh Packages]# rpm -ql bind /etc/NetworkManager/dispatcher.d/13-named /etc/logrotate.d/named /etc/named /etc/named.conf /etc/named.iscdlv.key /etc/named.rfc1912.zones /etc/named.root.key /etc/portreserve/named /etc/rc.d/init.d/named /etc/rndc.conf /etc/rndc.key /etc/sysconfig/named /usr/lib64/bind /usr/sbin/arpaname /usr/sbin/ddns-confgen /usr/sbin/dnssec-dsfromkey ...............
-qc name:查询生成的配置文件
[root@wsh Packages]# rpm -qc man #man的配置文件 /etc/man.config
-qd name:查询生成的帮助文档
[root@wsh Packages]# rpm -qd grep #grep的帮助文档 /usr/share/doc/grep-2.6.3/ABOUT-NLS /usr/share/doc/grep-2.6.3/AUTHORS /usr/share/doc/grep-2.6.3/COPYING /usr/share/doc/grep-2.6.3/ChangeLog /usr/share/doc/grep-2.6.3/NEWS /usr/share/doc/grep-2.6.3/README /usr/share/doc/grep-2.6.3/THANKS /usr/share/doc/grep-2.6.3/TODO /usr/share/info/grep.info.gz /usr/share/man/man1/egrep.1.gz /usr/share/man/man1/fgrep.1.gz /usr/share/man/man1/grep.1.gz
-qf /path/to/file_name:查询文件是由哪个软件生成的
[root@wsh Packages]# rpm -qf /etc/man.config #man.config是由man.-1.6f-32.el6.x86_64生成的 man-1.6f-32.el6.x86_64
-q --scripts name:查询安装
[root@wsh Packages]# rpm -q --scripts bind #preinstall,安装前脚本 #postinstall,安装后脚本 #preuninstall,卸载前脚本 #postuninstall,卸载后脚本 preinstall scriptlet (using /bin/sh): if [ "$1" -eq 1 ]; then /usr/sbin/groupadd -g 25 -f -r named >/dev/null 2>&1 || :; /usr/sbin/useradd -u 25 -r -N -M -g named -s /sbin/nologin -d /var/named -c Named named >/dev/null 2>&1 || :; fi; :; postinstall scriptlet (using /bin/sh): /sbin/ldconfig /sbin/chkconfig --add named if [ "$1" -eq 1 ]; then [ -x /sbin/restorecon ] && /sbin/restorecon /etc/rndc.* /etc/named.* >/dev/null 2>&1 ; # rndc.key has to have correct perms and ownership, CVE-2007-6283 [ -e /etc/rndc.key ] && chown root:named /etc/rndc.key [ -e /etc/rndc.key ] && chmod 0640 /etc/rndc.key fi :; preuninstall scriptlet (using /bin/sh): if [ "$1" -eq 0 ]; then /sbin/service named stop >/dev/null 2>&1 || :; /sbin/chkconfig --del named || :; fi; :; postuninstall scriptlet (using /bin/sh): /sbin/ldconfig if [ "$1" -ge 1 ]; then /sbin/service named try-restart >/dev/null 2>&1 || :; fi; :;
查询未安装的rpm包的相关信息,加入-p选项即可:
rpm -qp[i|l|c|d|--scripts] name-version.release.arch.rpm
4.卸载
-e : 卸载
--nodeps:忽略依赖关系
[root@wsh Packages]# rpm -q bind #查询bind包已安装 bind-9.8.2-0.10.rc1.el6.x86_64 [root@wsh Packages]# rpm -e bind #-e卸载提示有依赖关系 error: Failed dependencies: bind >= 32:9.6.1-0.3.b1 is needed by (installed) bind-dyndb-ldap-1.1.0-0.9.b1.el6.x86_64 [root@wsh Packages]# rpm -e --nodeps bind #忽略依赖关系卸载 [root@wsh Packages]# rpm -q bind #查询已经卸载 package bind is not installed
5.升级
-U:升级或安装,如果软件包没有安装则安装;否则,升级
-F:升级,只能升级,即需要升级的软件包必须已经安装
常用组合:
-Uvh
-Fvh
--force:
--nodeps:
注意:内核不应该升级,尽可能安装,因为内核允许多版本并存。
6.校验
rpm -V name
[root@wsh ~]# vim /usr/share/doc/man-1.6f/README #README的最后一行加入内容 [root@wsh ~]# rpm -V man S.5....T. d /usr/share/doc/man-1.6f/README #校验出改变的README #校验已安装的包的文件与保存在rpm数据库里的包的元数据,如果相同则无任何显示,如果不用则标# #示出改变的地方,如下是每个字符代表的意义: # S file Size differs # M Mode differs (includes permissions and file type) # 5 digest (formerly MD5 sum) differs # 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
7.rpm包的数据库
/var/lib/rpm
如果rpm的数据库损坏,会导致查询等相关操作无法正常进行,这时就需要重建数据库
数据库重建:
--initdb:新建,不会覆盖原有数据库
--rebuilddb:重建,覆盖原有数据库,常用