欢迎来到我的博客园

Linux RPM 软件包管理

RPM的介绍(RPM Package Manager)

RPM是一个功能强大的包管理系统:

  • 使用源代码构造的方便分发转移的软件包
  • 安装,升级和卸载打包软件
  • 不论是否安装,都可以查询到打包的软件的具体信息
  • 验证打包软件的完整性,和最终安装软件

RPM管理的软件包优缺点

  • 优点:比源码安装方便简单很多,不需要自己编译,相关信息记录在数据库中,不管是否安装都可以查到。
  • 缺点:需要自行解决软件包依赖关系,卸载时要注意不要将依赖的软件也卸载,可能会引起其他软件出现问题。

RPM软件包命名规范:

RPM软件包名字的命名规范是 packagename-a.b.c-x.arch.rpm

packagename -- 包的名字
a.b.c -- 软件的版本号
x -- 软件发布号码
devel -- 软件的开发包(特殊)
arch -- 软件打包的服务器的硬件平台
noarch -- 包可以在任何硬件平台上安装(特殊)

RPM命令详解

 查询和检验包
 
#查询包的信息
rpm {-q|--query} [select-options] [query-options]
#验证包的信息 rpm {-V|--verify} [select-options] [verify-options]
 
[select-options] 选项说明
PACKAGE_NAME  包名
-a, --all   所有的包
-f, --file FILE  查询文件对应得包名
-g, --group GROUP 查询group的包
 
实验如下:
#-q PACKAGE_NAME
[root@node1 ~]# rpm -q mysql-community-server
mysql-community-server-8.0.29-1.el7.x86_64
#-qa
[root@node1 ~]# rpm -qa |head -5
doxygen-1.8.5-4.el7.x86_64
hicolor-icon-theme-0.12-7.el7.noarch
setup-2.8.71-11.el7.noarch
libsysfs-2.1.0-16.el7.x86_64
xmlsec1-openssl-1.2.20-7.el7_4.x86_64
#-qf
[root@node1 ~]#  rpm -qf  /usr/lib/rpm/rpmrc
rpm-4.11.3-45.el7.x86_64
[root@node1 ~]# rpm -qg Applications/Databases
sqlite-3.7.17-8.el7_7.1.x86_64
libdb-utils-5.3.21-25.el7.x86_64
mysql-community-common-8.0.29-1.el7.x86_64
mysql-community-client-plugins-8.0.29-1.el7.x86_64
mysql-community-libs-8.0.29-1.el7.x86_64
mysql-community-client-8.0.29-1.el7.x86_64
mysql-community-icu-data-files-8.0.29-1.el7.x86_64
mysql-community-server-8.0.29-1.el7.x86_64
mysql-community-libs-compat-8.0.29-1.el7.x86_64

 

 

[query-options] 选项说明
 
--changelog 包修改日志
-c, --configfiles   包的配置文件
-i, --info  包的信息,包括名字,版本,介绍。
-l, --list   包的文件
-R, --requires  包的依赖性
--scripts 安装包的脚本
-s, --state  包的文件的状态
 
实验如下:
#--changelog
[root@node1 ~]# rpm -q --changelog zlib
* Tue Apr 12 2022 Matej Mužila <mmuzila@redhat.com> - 1.2.7-20
- Resolves: CVE-2018-25032

* Wed Sep 09 2020 Ondrej Dubaj <odubaj@redhat.com> - 1.2.7-19
- fixed accessing password-protected .zip files via libminizip (#1875700)

* Mon Jul 09 2018 Pavel Raiskup <praiskup@redhat.com> - 1.2.7-18
- Link with -z now for full RELRO

* Thu May 19 2016 jchaloup <jchaloup@redhat.com> - 1.2.7-17
- Fix writing empty files on gzopen()/gzclose()
  resolves: #1337441
# -qc --configfiles
[root@node1 ~]# rpm -qc rpm
/var/lib/rpm/Basenames
/var/lib/rpm/Conflictname
/var/lib/rpm/Dirnames
/var/lib/rpm/Group
/var/lib/rpm/Installtid
/var/lib/rpm/Name

# -qi rpm
[root@node1 ~]# rpm -qi rpm
Name        : rpm
Version     : 4.11.3
Release     : 45.el7
Architecture: x86_64
Install Date: Thu 23 Jun 2022 06:15:16 PM EDT
Group       : System Environment/Base
Size        : 2622621
License     : GPLv2+
Signature   : RSA/SHA256, Wed 14 Oct 2020 03:00:03 PM EDT, Key ID 24c6a8a7f4a80eb5
Source RPM  : rpm-4.11.3-45.el7.src.rpm
Build Date  : Wed 30 Sep 2020 01:30:03 PM EDT
Build Host  : x86-02.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://www.rpm.org/
Summary     : The RPM package management system
Description :
The RPM Package Manager (RPM) is a powerful command line driven
package management system capable of installing, uninstalling,
verifying, querying, and updating software packages. Each software
package consists of an archive of files along with information about
the package like its version, a description, etc.

# -ql 

[root@node1 ~]# rpm -ql zlib
/usr/lib64/libz.so.1
/usr/lib64/libz.so.1.2.7
/usr/share/doc/zlib-1.2.7
/usr/share/doc/zlib-1.2.7/ChangeLog
/usr/share/doc/zlib-1.2.7/FAQ
/usr/share/doc/zlib-1.2.7/README

#-qR
[root@node1 ~]# rpm -qR zlib
/sbin/ldconfig
/sbin/ldconfig
libc.so.6()(64bit)
libc.so.6(GLIBC_2.14)(64bit)
libc.so.6(GLIBC_2.2.5)(64bit)
libc.so.6(GLIBC_2.3.4)(64bit)
libc.so.6(GLIBC_2.4)(64bit)
rpmlib(CompressedFileNames) <= 3.0.4-1
rpmlib(FileDigests) <= 4.6.0-1
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
rtld(GNU_HASH)
rpmlib(PayloadIsXz) <= 5.2-1

#-q --scripts
[root@node1 ~]# rpm -q --scripts zlib
postinstall program: /sbin/ldconfig
postuninstall program: /sbin/ldconfig
[root@node1 ~]#

#-qs 状态
[root@node1 ~]# rpm -qs zlib
normal        /usr/lib64/libz.so.1
normal        /usr/lib64/libz.so.1.2.7
normal        /usr/share/doc/zlib-1.2.7
normal        /usr/share/doc/zlib-1.2.7/ChangeLog
normal        /usr/share/doc/zlib-1.2.7/FAQ
normal        /usr/share/doc/zlib-1.2.7/README 
 
验证包
 
#验证包的信息
rpm {-V|--verify} [select-options] [verify-options]
 
[select-options] 选项说明
PACKAGE_NAME  包名
-a, --all   所有的包
-f, --file FILE  查询文件对应得包名
-g, --group GROUP 查询group的包

实验如下:

#-Va校验所有的包。时间较长
[root@node1 ~]# rpm -Va
[root@node1 ~]# 
#-Vf 文件名  检查包的配置文件是否被修改

[root@node1 ssh]# rpm -Vf /etc/httpd/conf/httpd.conf
S.5....T.  c /etc/httpd/conf/httpd.conf
[root@node1 ~]# rpm -V httpd
S.5....T. c /etc/httpd/conf/httpd.conf

校验内容含义

The format of the output is a string of 9 characters, a possible attribute marker:

       c %config configuration file.                                                            #配置文件
       d %doc documentation file.                                                               #手册文件
       g %ghost file (i.e. the file contents are not included in the package payload).          #ghost文件                              
       l %license license file.                                                                 #证书文件
       r %readme readme file.                                                                   #ReadMe文件

       from the package header, followed by the file name.  Each of the 9 characters denotes the result of a comparison of attribute(s) of the file to the value of those  attribute(s)  recorded  in  the
       database.   A  single  "."  (period)  means  the  test passed, while a single "?" (question mark) indicates the test could not be performed (e.g. file permissions prevent reading). Otherwise, the
       (mnemonically emBoldened) character denotes failure of the corresponding --verify test:

       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                                                                 #文件owner
       G Group ownership differs                                                                #文件组
       T mTime differs                                                                          #文件修改时间
       P caPabilities differ           
[root@node1 ssh]# rpm -Vf /etc/httpd/conf/httpd.conf
S.5....T.  c /etc/httpd/conf/httpd.conf 
表示 文件大小被改变,文件校验码已变,文件mTime被改变,当前校验被修改的文件是配置文件 c必须是 c/d/g/l/r/"空格"中的一种
配置文件大多时候是我们自己改的。如果可执行文件被修改了,这时候要小心。例如下面的/usr/sbin/apachectl文件已经被修改了。

[root@node1 ~]# rpm -V httpd
S.5....T. c /etc/httpd/conf/httpd.conf
S.5....T. /usr/sbin/apachectl    

 

  

  

安装、升级以及卸载包
   INSTALLING, UPGRADING, AND REMOVING PACKAGES:
       rpm {-i|--install} [install-options] PACKAGE_FILE ...
       rpm {-U|--upgrade} [install-options] PACKAGE_FILE ...
       rpm {-F|--freshen} [install-options] PACKAGE_FILE ...
       rpm {-e|--erase} [--allmatches] [--justdb] [--nodeps] [--noscripts]
           [--notriggers] [--test] PACKAGE_NAME ...

 

安装软件包:

[install-options]选项说明:
-h, --hash 打印hash信息
-v verbose详细输出
--test 实际安装文件只是预执行,查看有误软件冲突
--nodeps 安装之前不做依赖性检查

实验如下

--test测试命令
[root@node1 Packages]# rpm -iv --test qt3-3.3.8b-51.el7.x86_64.rpm
error: Failed dependencies:
        libmng.so.1()(64bit) is needed by qt3-3.3.8b-51.el7.x86_64
--ivh 安装命令
[root@node1 Packages]# rpm -ivh  rsyslog-mysql-8.24.0-55.el7.x86_64.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:rsyslog-mysql-8.24.0-55.el7      ################################# [100%]

  

卸载rpm包

[root@node1 ~]# rpm -qa |grep syslog
rsyslog-mysql-8.24.0-55.el7.x86_64
rpmrsyslog-8.24.0-55.el7.x86_64
[root@node1 ~]# rpm -e rsyslog-mysql-8.24.0-55.el7.x86_64
[root@node1 ~]# rpm -qa |grep syslog
rsyslog-8.24.0-55.el7.x86_64

  

 

posted @ 2022-06-26 21:29  panzq  阅读(278)  评论(0编辑  收藏  举报