首页 > 代码库 > rpm包管理器

rpm包管理器

wKiom1PL6JjzDR2VAAC0nXswWmk192.jpg

 

rpm包的使用:

    rpm包管理器所打包后的程序包都是以rpm结尾的

         源代码:

                   name-version.tar.{gz,bz2,xz}

                            versionmajor.minor.release

                            

         rpm包的命名格式

                   name-version-relase.arch.rpm

 

                            version:major.minor.release,同源代码

                   主版本号.次版本号.修订版本号

                            release:rpm自身的发行号,与程序源码的发行号无关,仅用于标识对rpm包不同制作的修订;同时,release还包含此包适用的OS

                                     bash-4.2.3-3.centos5此包已经修订3次了

                            arch:适用于的硬件平台,

                                     x86:i386, i486, i586, i686等;

                                     x86_64:x86_64

                                     powerpc:ppc

                                     noarch:依赖于虚拟机

                                               例如:bash-4.2.3-3.centos5.x86_64.rpm

 

                   一个程序有20个功能:常用功能有8个,特殊A:3个,特殊B6个,二次开发相关功能:3

                            分包机制:

                                     核心包,主包:命名与源程序一致

                                               bash-4.2.3-3.centos7.x86_64.rpm

                                     子包:命名源程序包后再跟上具体的功能

                                               bash-a-4.2.3-3.centos7.x86_64.rpm

                                               bash-b-4.2.3-3.centos7.x86_64.rpm

                                               bash-devel-4.2.3-3.centos7.x86_64.rpm

包和包之间有复杂的依赖关系,安装某个包是要一并把他所依赖的包全装上。当然如果忽略所依赖的包而强制安装,有可能无法运行

 

                                     OSVendor: 系统发行商提供的包

                            获取rpm包的途径:

                                     1、发行的光盘或站点服务器

                                               镜像:官方发行的镜像

                                                        

                                                        http://mirrors.sohu.com

                                                        http://mirrors.163.com

wKioL1PL6cOBV5jOAAHfHjYZBDE356.jpg

                                     2、项目的官网

                                               源代码

                                               rpm

                                     3、很多第三方机构或个人制作并公开发布许多rpm

                                               http://rpmfind.net

                                               http://rpm.pbone.net

 

                                     可靠的途径:EPEL

                                               Fedora-EPEL一般常用的包都在里面

 

                   rpm包的合法性验正:

                            包制作者制作完成之后会附加数字签名于包上;

                                     来源合法性

                                     包的完整性

 

                                     包的制作者使用单向加密提取原始数据的特征码,而后使用自己的私钥加密这段特性码,附加原始数据后面。

                                     验正过程:

                                               前提:必须有可靠机制获取到包制作者的公钥;

                                               1、使用制作者的公钥解密加密的特征码,能解密则意味着来源合法;

                                               2、使用与制作者同样的意向加密算法提取原始数据的特征码,并与解密出来的特征作比对,相同,则意味着完整性没问题;

 

rpm包管理器的常见使用场景:

 

 

                   安装程序包:

                            rpm[option] /path/to/package_file

                                     -i:install安装

                                     -v:显示安装的详细信息

                                     -vv: 显示安装的再详细信息

                                     -vvv:显示安装的再再详细信息

                                     -h:使用#号来显示安装进度,一个#表示2%的进度

 

                                     组合选项:-ivh

                                     --test:仅作测试,没有真正执行安装

 

                                     如果依赖于其它包:

                                               1、解决依赖关系

                                               2、忽略依赖关系

                                                        能安装上,但有可能无法运行;

                                                        --nodeps

 

                                     重新安装:

                                               --replacepkgs

 

                                                        如果原有配置文件作了修改,很有可能不执行替换,而是将应该安装生成的配置文件重命名为 .rpmnew

 

                   卸载程序包:

                            rpm[option] package_name包名

                                     -e:erase卸载(擦除)

 

                                     如果被其它包所依赖:

                                               1、将依赖于此包的所有包一并卸载

                                               2、忽略依赖关系

                                                        能卸载,但依赖于此包程序包可能会运行不正常;

                                                        --nodeps忽略依赖关系安装

 

                                     如果包的配置文件安装后曾被改动过,卸载时,此文件将不会卸载,而是被重命名并保留,例如

                                               warning:/etc/zprofile saved as /etc/zprofile.rpmsave

 

                   升级程序包:

                            新版本替换老版本

                            rpm[option] /path/to/package_file

                                     1、升级或安装

                                               -Uvh

 

                                     2、纯升级

                                               -Fvh

 

                                     X--> Y-2.2.1

                                               Y-2.2.3

                                               升级后的版本冲突等;

 

                                     --force:强制升级

 

                            注意:不应该对内核执行升级操作,而是安装

                                     系统允许多内核并存

 

                   查询操作:

                            1、查询某包是否安装

                                     rpm-q package_name...

wKioL1PL6hfQlPYSAAApJH7JU8E289.jpg

 

                            2、查询所有已经安装的包

                                      rpm -qa

 

                                     按条件过滤:rpm -qa| grep ‘PATTERN‘

wKiom1PL6R-hbQRvAABNNqiUksI553.jpg当你只记得包的一部分名字时,可用rpm –qa再通过管道找到所以部分名有关的包即可

 

                            3、查询包的描述信息

                                     rpm-qi package_name

 

                            4、查询某包安装生成了哪些文件

                                     rpm-ql package_name

 

                                     (1)查询某包安装生成了哪些配置文件

                                     rpm-qc package_name

 

                                     (2)查询某包安装生成了哪些帮助文件

                                     rpm-qd package_name

 

                                     (3)查询程序包的相关脚本

                                     rpm-q --scripts package_name这些脚本不一定要执行,只是在某些特定环境下才执行

 

                                               脚本有四类:

                                                        preinstall:安装前执行脚本

                                                        postinstall:安装后执行脚本

                                                        preuninstall:卸载前执行脚本

                                                        postuninstall:卸载后执行脚本

 

                            5、查询某文件是由哪个包安装生成的

                            rpm-qf /path/to/some_file

 

                            6、对尚未安装的包执行查询

                            rpm[option] /path/to/package_file

                                     -qpi

                                     -qpl

                                     -qpc

                                     -qpd

 

 

                   校验:

                            用于检查包安装生成的文件属性是否发生变化

 

                            rpm-V package_name

 

                          S file Size differs文件大小不同

                          M Mode differs (includes permissions andfile type)方式不同(包括权限和文件类型)

                          5 digest (formerly MD5 sum) differs消化(原名MD5总和)不同

                          D Device major/minor number mismatch设备主要/次要版本号不匹配

                          L readLink(2) path mismatch指向(2)路径不匹配

                          U User ownership differs

                          G Group ownership differs

                          T mTime differs

                          P caPabilities differ

 

                         某属性无变化,显示为.

 

         rpm包来源合法性及完整性检验:

 

                   前提:在当前系统上导入包的制作者的公钥

                            导入:

                                     rpm--import /path/to/key_file

 

                                     #rpm -qa gpg-pubkey*

                                     显示所有已经导入的gpg格式的公钥

 

                                     #rpm -qi gpg-pubkey-NAME

                                     显示密钥的详细信息

 

                            检查包:安装过程中会自动执行

 

                            手动检查:

                                     rpm-K /path/to/package_file

                                     rpm--checksig /path/to/package_file

 

                                               不检查包完整性:

                                                        rpm-K --nodigest

                                               不检查来源合法性:

                                                        rpm-K --nosignature

 

         数据库重建:

                   数据库目录:/var/lib/rpm

 

                   重建:

                            rpm--initdb:初始化

                                     如果事先没有库,会新建一个;如果有,则不新建;

 

                            rpm--rebuilddb: 重建

                                     直接重建,覆盖原有的数据库


rpm包管理器