linux程序包管理:rpm 、yum

时间:2023-02-14 18:30:24

软件包的组成部分:二进制程序、库、配置文件、帮助文件

二进制程

序:/bin,/sbin,/usr/bin,/usr/sbin,/usr/local/bin,/usr/local/sbin

      应用程序:/usr/local/nginx

库:/lib,/usr/lib,/lib64,/usr/lib64,/usr/local/lib,/usr/local/lib64

      应用程序:/usr/local/nginx

      定义库文件的位置:/etc/ld.so.conf,/etc/ld.so.conf.d/*.conf

配置文件: /etc/

帮助文件:man文件,info文件,README,INSTALL,ChangeLog

             man文件的使用:

                      1,man �CM /usr/local/nginx/man httpd

                      2,vim /etc/man.config

                         MANPATH /usr/local/nginx/man

 

ldd命令

查看应用程序所依赖的共享库

# ldd `which ifconfig`

linux-vdso.so.1 =>  (0x00007fffd4dff000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x0000003cf4400000)
libc.so.6 => /lib64/libc.so.6 (0x0000003cf2800000)
libdl.so.2 => /lib64/libdl.so.2 (0x0000003cf3000000)
/lib64/ld-linux-x86-64.so.2 (0x0000003cf2400000)

 

程序包管理器使用

程序包管理器的基本功能:

打包,安装,查询,升级,卸载,校验,数据库管理

centos的两个应用程序管理器:rpm  ,   yum

    

rpm包使用

安装: rpm �Civh rpm_package

         #rpm �Civh zsh-4.3.10-5.el6.x86_64.rpm

Preparing...                ########################################### [100%]
   1:zsh                    ########################################### [100%]

-i:  安装

-v: 显示详细信息

-h: 以#的个数显示安装进度,一个#代表2%的进度

 

重新安装: rpm �Civh �Creplacepkgs rpm_package

               #rpm -ivh --replacepkgs zsh-4.3.10-5.el6.x86_64.rpm

 

卸载: rpm �Ce package_name

        #rpm �Ce zsh

        #rpm �Ce �Cnodeps mysql

                忽略依赖性关系卸载

 

查询: rpm �Cq

        查询单个安装包: rpm �Cq zsh

        查询所有已经安装的包: rpm �Cqa

        查询包的描述信息: rpm �Cqi tcpdump

Name        : tcpdump                      Relocations: (not relocatable)
Version     : 4.0.0                             Vendor: CentOS
Release     : 3.20090921gitdf3cb4.2.el6     Build Date: Mon 26 Mar 2012 08:56:48 PM CST
Install Date: Tue 11 Feb 2014 01:40:32 PM CST      Build Host: c6b6.bsys.dev.centos.org
Group       : Applications/Internet         Source RPM: tcpdump-4.0.0-3.20090921gitdf3cb4.2.el6.src.rpm
Size        : 832443                           License: BSD with advertising
Signature   : RSA/SHA1, Mon 26 Mar 2012 09:32:34 PM CST, Key ID 0946fca2c105b9de
Packager    : CentOS BuildSystem <http://bugs.centos.org>
URL         : http://www.tcpdump.org
Summary     : A network traffic monitoring tool
Description :
Tcpdump is a command-line tool for monitoring network traffic.
Tcpdump can capture and display the packet headers on a particular
network interface or on all interfaces.  Tcpdump can display all of
the packet headers, or just the ones that match particular criteria.

Install tcpdump if you need a program to monitor network traffic.

 

        查询安装包在当前系统生成的文件列表: rpm �Cql tcpdump

/usr/sbin/tcpdump
/usr/sbin/tcpslice
/usr/share/doc/tcpdump-4.0.0
/usr/share/doc/tcpdump-4.0.0/CHANGES
/usr/share/doc/tcpdump-4.0.0/CREDITS
/usr/share/doc/tcpdump-4.0.0/LICENSE
/usr/share/doc/tcpdump-4.0.0/README
/usr/share/man/man8/tcpdump.8.gz
/usr/share/man/man8/tcpslice.8.gz

 

        查询某文件是由哪个包安装生成的: rpm -qf `which ifconfig`

net-tools-1.60-110.el6_2.x86_64

 

                 查询包安装之后生成的帮助文档: rpm �Cqd tcpdump

/usr/share/doc/tcpdump-4.0.0/CHANGES
/usr/share/doc/tcpdump-4.0.0/CREDITS
/usr/share/doc/tcpdump-4.0.0/LICENSE
/usr/share/doc/tcpdump-4.0.0/README
/usr/share/man/man8/tcpdump.8.gz
/usr/share/man/man8/tcpslice.8.gz

                  查询包安装之后生成的配置文件: rpm �Cqc bash

/etc/skel/.bash_logout
/etc/skel/.bash_profile
/etc/skel/.bashrc

 

          查询包安装过程中执行的脚本: rpm �Cq �Cscripts httpd

preinstall scriptlet (using /bin/sh):
# Add the "apache" user
getent group apache >/dev/null || groupadd -g 48 -r apache
getent passwd apache >/dev/null || \
  useradd -r -u 48 -g apache -s /sbin/nologin \
    -d /var/www -c "Apache" apache
exit 0
postinstall scriptlet (using /bin/sh):
# Register the httpd service
/sbin/chkconfig --add httpd
/sbin/chkconfig --add htcacheclean
preuninstall scriptlet (using /bin/sh):
if [ $1 = 0 ]; then
        /sbin/service httpd stop > /dev/null 2>&1
        /sbin/chkconfig --del httpd
        /sbin/service htcacheclean stop > /dev/null 2>&1
        /sbin/chkconfig --del htcacheclean
fi
posttrans scriptlet (using /bin/sh):
test -f /etc/sysconfig/httpd-disable-posttrans || \
/sbin/service httpd condrestart >/dev/null 2>&1 || :

 

升级:

       rpm �CU: 升级或安装

       rpm �CF: 升级

       rpm �CUvh package_rpm

       rpm �CFvh package_rpm

      

校验:

        rpm �CV httpd

S.5....T.  c /etc/httpd/conf/httpd.conf
.......T.  c /etc/sysconfig/httpd

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 �Cimport /path/to/gpg-key-file

      #gpg-key-file位于光盘根目录下

#rpm �Cimport RPM-GPG-KEY-CentOS-6

#rpm �CK rpm -K zsh-4.3.10-5.el6.x86_64.rpm

 

包管理数据库:

          数据库位置:  /var/lib/rpm

          重建数据库:

                    #rpm �Cinitdb:如果不存在数据库,重建之

                    #rpm �Crebuilddb:直接重建,会覆盖原有的库

 

yum使用:

        rpm安装包时无法解决依赖性关系,yum应运而生。yum能够在安装过程中自动解决依赖性关系。yum分为服务器端和客户端。

        yum服务器:

              相当于一个文件服务器,用于存放rpm包,可以使用http,nfs,ftp,本地file作为服务器。

        yum客户端:

               配置文件:/etc/yum.repo.d/*.conf,/etc/yum.conf

                          指定连接的yum服务器仓库

               缓存元数据:yum客户端从yum服务器仓库获取元数据,并缓存至本地

               分析元数据: 根据具体操作请求完成元数据分析,可以包括检查依赖性关系、文件列表等信息

               执行安装软件、查询等功能

         yum服务器配置:

               a.使用挂载的光盘作为yum源:

                      1.挂载光盘: mount /dev/cdrom /media

                      2.vim /etc/yum.repo.d/

                         [package]
                         name=centos packages
                         baseurl=file:///media/Packages
                         enabled=1
                         gpgcheck=0

                       3.测试

                          yum repolist

           yum 客户端常用的命令:

                     yum repolist [all | enabled | disabled]: 列出所有可用的yum repo

                     yum clean [all | packages | meta | expire-cache | rpmdb | plugins ]: 清理缓存

                     yum list [all | installed | avaliable ] : 列出所有可用的rpm包

                     yum info httpd : 列出包的详细信息

                     yum grouplist: 列出所有包组

                     yum group info “package_group_name”: 列出包组信息

                            三个和开发相关的包组:

                                Desktop Platform Development

                                Server Platform Development

                                Development Tools

                     yum install httpd : 安装指定的包

                     yum reinstall httpd : 重新安装指定的包

                     yum check-update: 检查可升级的包

                     yum update httpd : 升级指定的包

                     yum downgrade httpd: 阶级指定的包

                     yum erase | remove httpd: 删除或卸载指定的包

                     yum whatprovides | provides /etc/passwd : 查询文件是由哪个包提供的

                     yum groupinstall “group_name” : 安装指定的组包

                     yum groupremove “group_name” : 卸载指定的组包

                     yum install *.rpm: 安装本地包