IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 系统运维 -> Linux程序包管理命令之rpm -> 正文阅读

[系统运维]Linux程序包管理命令之rpm

一、官方文档
rpm命令man文档如下:

NAME
       rpm - RPM Package Manager

SYNOPSIS
   QUERYING AND VERIFYING PACKAGES:
       rpm {-q|--query} [select-options] [query-options]

       rpm {-V|--verify} [select-options] [verify-options]

   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 ...

二、常用命令总结:
安装:rpm -i | --install PACKAGE_FILE …
卸载:rpm -e | --erase PACKAGE_FILE …
升级:rpm -U | --update PACKAGE_FILE …
查询:rpm -q | --query [select-options] [query-options]
校验:rpm -V | --verify PACKAGE_FILE …

[root@linux4 Packages]# ls zsh-*
zsh-5.0.2-34.el7_8.2.x86_64.rpm  zsh-html-5.0.2-34.el7_8.2.x86_64.rpm

########################## 安装rpm包 ##############################
[root@linux4 Packages]# rpm -ivh zsh-5.0.2-34.el7_8.2.x86_64.rpm 
Preparing...                          ################################# [100%]
Updating / installing...
   1:zsh-5.0.2-34.el7_8.2             ################################# [100%]

########################## 升级rpm包 ##############################
[root@linux4 Packages]# rpm -Uvh zsh-*
Preparing...                          ################################# [100%]
	package zsh-5.0.2-34.el7_8.2.x86_64 is already installed

########################## 查询rpm包 ##############################
[root@linux4 Packages]# rpm -q zsh
zsh-5.0.2-34.el7_8.2.x86_64

######################## 查询rpm包详细信息 ##############################
[root@linux4 Packages]# rpm -qi zsh
Name        : zsh
Version     : 5.0.2
Release     : 34.el7_8.2
Architecture: x86_64
Install Date: Wed 21 Sep 2022 03:16:05 PM CST
Group       : System Environment/Shells
Size        : 5860430
License     : MIT
Signature   : RSA/SHA256, Wed 08 Apr 2020 10:41:00 PM CST, Key ID 24c6a8a7f4a80eb5
Source RPM  : zsh-5.0.2-34.el7_8.2.src.rpm
Build Date  : Tue 07 Apr 2020 10:38:13 PM CST
Build Host  : x86-02.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://zsh.sourceforge.net/
Summary     : Powerful interactive shell
Description :
The zsh shell is a command interpreter usable as an interactive login
shell and as a shell script command processor.  Zsh resembles the ksh
shell (the Korn shell), but includes many enhancements.  Zsh supports
command line editing, built-in spelling correction, programmable
command completion, shell functions (with autoloading), a history
mechanism, and more.

########################## 校验rpm包 ##############################
[root@linux4 Packages]# rpm -V zsh
[root@linux4 Packages]# 

########################## 卸载rpm包 ##############################
[root@linux4 Packages]# rpm -e zsh

三、各命令详解
1、安装
?命令:rpm {-i|–install} [install-options] PACKAGE_FILE …
?文档:

       rpm {-i|--install} [install-options] PACKAGE_FILE ...
          install-options
        [--allfiles] [--badreloc] [--excludepath OLDPATH]
        [--excludedocs] [--force] [-h,--hash]
        [--ignoresize] [--ignorearch] [--ignoreos]
        [--includedocs] [--justdb] [--nocollections]
        [--nodeps] [--nodigest] [--nosignature] [--noplugins]
        [--noorder] [--noscripts] [--notriggers]
        [--oldpackage] [--percent] [--prefix NEWPATH]
        [--relocate OLDPATH=NEWPATH]
        [--replacefiles] [--replacepkgs]
        [--test]

??[install-options]
???-h: 输出进度条,每个#显示2%的进度
???--test: 测试安装,不执行安装,仅检查并报告依赖关系及冲突
???--nodeps: 不检查依赖
???--force: 同replacepkgs
???--replacepkgs: 即使包已存在,也要执行安装,即覆盖安装
???--justdb: 只更新数据库
???--nosignature: 不检查签名信息
???--nodigest: 不检查完整性信息
???--prefix NEWPATH: 指定路径安装

############### -h  ###############
[root@linux4 Packages]# rpm -ivh zsh-5.0.2-34.el7_8.2.x86_64.rpm 
Preparing...                          ################################# [100%]
Updating / installing...
   1:zsh-5.0.2-34.el7_8.2             ################################# [100%]
   
############### --test ###############
[root@linux4 Packages]# rpm -ivh --test zsh-html-5.0.2-34.el7_8.2.x86_64.rpm 
Preparing...                          ################################# [100%]

############### --force ###############
[root@linux4 Packages]# rpm -ivh --force zsh-5.0.2-34.el7_8.2.x86_64.rpm 
Preparing...                          ################################# [100%]
Updating / installing...
   1:zsh-5.0.2-34.el7_8.2             ################################# [100%]
   
############### --replacepkgs ###############
[root@linux4 Packages]# rpm -ivh --replacepkgs zsh-5.0.2-34.el7_8.2.x86_64.rpm 
Preparing...                          ################################# [100%]
Updating / installing...
   1:zsh-5.0.2-34.el7_8.2             ################################# [100%]
   
############### --justdb ###############
[root@linux4 Packages]# rpm -ivh --justdb zsh-5.0.2-34.el7_8.2.x86_64.rpm 
Preparing...                          ################################# [100%]
	package zsh-5.0.2-34.el7_8.2.x86_64 is already installed
[root@linux4 Packages]# rpm -e zsh

############### --nosignature ###############
[root@linux4 Packages]# rpm -ivh --nosignature zsh-5.0.2-34.el7_8.2.x86_64.rpm 
Preparing...                          ################################# [100%]
Updating / installing...
   1:zsh-5.0.2-34.el7_8.2             ################################# [100%]
[root@linux4 Packages]# rpm -e zsh

############### --nodigest ###############
[root@linux4 Packages]# rpm -ivh --nodigest zsh-5.0.2-34.el7_8.2.x86_64.rpm 
Preparing...                          ################################# [100%]
Updating / installing...
   1:zsh-5.0.2-34.el7_8.2             ################################# [100%]
[root@linux4 Packages]# rpm -e zsh

############### --prefix ###############
[root@linux4 Packages]# rpm -ivh --prefix /tmp/zsh zsh-5.0.2-34.el7_8.2.x86_64.rpm 
error: package zsh is not relocatable
[root@linux4 Packages]# 

2、升级
?命令:rpm {-U|–upgrade} [install-options] PACKAGE_FILE … 升级或安装
????rpm {-F|–freshen} [install-options] PACKAGE_FILE … 只升级
?文档:同install
??--oldpackage: 降级
??--force: 强制升级

3、查询
?命令:rpm {-q|–query} [select-options] [query-options]
?文档:

   select-options
        [PACKAGE_NAME] [-a,--all] [-f,--file FILE]
        [-g,--group GROUP] {-p,--package PACKAGE_FILE]
        [--hdrid SHA1] [--pkgid MD5] [--tid TID]
        [--querybynumber HDRNUM] [--triggeredby PACKAGE_NAME]
        [--whatprovides CAPABILITY] [--whatrequires CAPABILITY]

   query-options
        [--changelog] [-c,--configfiles] [--conflicts]
        [-d,--docfiles] [--dump] [--filesbypkg] [-i,--info]
        [--last] [-l,--list] [--obsoletes] [--provides]
        [--qf,--queryformat QUERYFMT] [-R,--requires]
        [--scripts] [-s,--state] [--triggers,--triggerscripts]

??[select-options]
???PACKAGE_NAME: 查询指定的包是否被安装
???-a|–all: 查询所有安装的包,通常会配合grep使用
???-f|–file:查询指定文件由哪个程序包安装生成
???-p|–package PACKAGE_FILE: 查询未安装的程序包
??[query-options]
???--changelog:查询rpm包的changelog
???-c|–configfiles:查询rpm包的配置文件信息
???-d|–docfiles:查询rpm包指定的文档
???-i|–info: 查询rpm包相关信息,如版本号、大小等
???-l|–list:程序包生成的文件列表
???-R|–requires:查询程序包的依赖关系
???--scripts:查询程序包自带的脚本文件

[root@linux4 Packages]# rpm -q zsh
zsh-5.0.2-34.el7_8.2.x86_64

[root@linux4 Packages]# rpm -qf /bin/ls
coreutils-8.22-24.el7.x86_64
[root@linux4 Packages]# rpm -qp zlib-static-1.2.7-18.el7.x86_64.rpm 
zlib-static-1.2.7-18.el7.x86_64
[root@linux4 Packages]# rpm -qa
aether-util-1.13.1-13.el7.noarch
firewalld-0.6.3-11.el7.noarch
atinject-tck-1-13.20100611svn86.el7.noarch
perl-Convert-ASN1-0.26-4.el7.noarch
......

[root@linux4 Packages]# rpm -qa|grep mysql
mha4mysql-node-0.58-0.el7.centos.noarch
mha4mysql-manager-0.58-0.el7.centos.noarch

[root@linux4 Packages]# rpm -q --changelog zsh-5.0.2-34.el7_8.2.x86_64.rpm 
package zsh-5.0.2-34.el7_8.2.x86_64.rpm is not installed
[root@linux4 Packages]# rpm -q --changelog zsh
* Tue Mar 03 2020 Kamil Dudka <kdudka@redhat.com> - 5.0.2-34.el7_8.2
- improve printing of error messages introduced by the fix of CVE-2019-20044
* Mon Feb 24 2020 Kamil Dudka <kdudka@redhat.com> - 5.0.2-34.el7_8.1
- drop privileges securely when unsetting PRIVILEGED option (CVE-2019-20044)
......

[root@linux4 Packages]# rpm -qc zsh
/etc/skel/.zshrc
/etc/zlogin
/etc/zlogout
/etc/zprofile
/etc/zshenv
/etc/zshrc

[root@linux4 Packages]# rpm -qd zsh
/usr/share/doc/zsh-5.0.2/BUGS
/usr/share/doc/zsh-5.0.2/CONTRIBUTORS
/usr/share/doc/zsh-5.0.2/FAQ
/usr/share/doc/zsh-5.0.2/FEATURES
/usr/share/doc/zsh-5.0.2/LICENCE
/usr/share/doc/zsh-5.0.2/MACHINES
/usr/share/doc/zsh-5.0.2/NEWS
/usr/share/doc/zsh-5.0.2/README
/usr/share/doc/zsh-5.0.2/completion-style-guide
/usr/share/doc/zsh-5.0.2/zsh-development-guide

[root@linux4 Packages]# rpm -qi zsh
Name        : zsh
Version     : 5.0.2
Release     : 34.el7_8.2
Architecture: x86_64
Install Date: Wed 21 Sep 2022 04:50:02 PM CST
Group       : System Environment/Shells
Size        : 5860430
License     : MIT
Signature   : RSA/SHA256, Wed 08 Apr 2020 10:41:00 PM CST, Key ID 24c6a8a7f4a80eb5
Source RPM  : zsh-5.0.2-34.el7_8.2.src.rpm
Build Date  : Tue 07 Apr 2020 10:38:13 PM CST
Build Host  : x86-02.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://zsh.sourceforge.net/
Summary     : Powerful interactive shell
Description :
The zsh shell is a command interpreter usable as an interactive login
shell and as a shell script command processor.  Zsh resembles the ksh
shell (the Korn shell), but includes many enhancements.  Zsh supports
command line editing, built-in spelling correction, programmable
command completion, shell functions (with autoloading), a history
mechanism, and more.

[root@linux4 Packages]# rpm -ql zsh
/bin/zsh
/etc/skel/.zshrc
/etc/zlogin
/etc/zlogout
/etc/zprofile
/etc/zshenv
/etc/zshrc
/usr/lib64/zsh
/usr/lib64/zsh/5.0.2
/usr/lib64/zsh/5.0.2/zsh
/usr/lib64/zsh/5.0.2/zsh/attr.so
/usr/lib64/zsh/5.0.2/zsh/cap.so
/usr/lib64/zsh/5.0.2/zsh/clone.so
/usr/lib64/zsh/5.0.2/zsh/compctl.so
/usr/lib64/zsh/5.0.2/zsh/complete.so
/usr/lib64/zsh/5.0.2/zsh/complist.so

[root@linux4 Packages]# rpm -qR zsh
/bin/sh
/bin/zsh
/sbin/install-info
config(zsh) = 5.0.2-34.el7_8.2
coreutils
grep
grep
libc.so.6()(64bit)
libc.so.6(GLIBC_2.11)(64bit)
libm.so.6()(64bit)
rtld(GNU_HASH)
rpmlib(PayloadIsXz) <= 5.2-1
......

[root@linux4 Packages]# rpm -q --scripts zsh
postinstall scriptlet (using /bin/sh):
if [ ! -f /etc/shells ] ; then
    echo "/bin/zsh" > /etc/shells
else
    grep -q "^/bin/zsh$" /etc/shells || echo "/bin/zsh" >> /etc/shells
fi

if [ -f /usr/share/info/zsh.info.gz ]; then
# This is needed so that --excludedocs works.
/sbin/install-info /usr/share/info/zsh.info.gz /usr/share/info/dir \
  --entry="* zsh: (zsh).			An enhanced bourne shell."
fi

:
preuninstall scriptlet (using /bin/sh):
if [ "$1" = 0 ] ; then
    if [ -f /usr/share/info/zsh.info.gz ]; then
    # This is needed so that --excludedocs works.
    /sbin/install-info --delete /usr/share/info/zsh.info.gz /usr/share/info/dir \
      --entry="* zsh: (zsh).			An enhanced bourne shell."
    fi
fi
:
postuninstall scriptlet (using /bin/sh):
if [ "$1" = 0 ] ; then
    if [ -f /etc/shells ] ; then
        TmpFile=`/bin/mktemp /tmp/.zshrpmXXXXXX`
        grep -v '^/bin/zsh$' /etc/shells > $TmpFile
        cp -f $TmpFile /etc/shells
        rm -f $TmpFile
    fi
fi
[root@linux4 Packages]# 

4、卸载
?命令:rpm {-e|–erase} [–allmatches] [–justdb] [–nodeps] [–noscripts] [–notriggers] [–test] PACKAGE_NAME …
??--allmatches: 卸载所有匹配指定名称的程序包的各版本
??--nodeps:忽略依赖关系
??--test:测试卸载,不真的执行

[root@linux4 Packages]# rpm -e --test zsh
[root@linux4 Packages]# rpm -q zsh
zsh-5.0.2-34.el7_8.2.x86_64
[root@linux4 Packages]# rpm -e zsh
[root@linux4 Packages]# rpm -q zsh
package zsh is not installed

5、校验
?命令:rpm {-V|–verify} [select-options] [verify-options]
?文档:

   verify-options
        [--nodeps] [--nofiles] [--noscripts]
        [--nodigest] [--nosignature]
        [--nolinkto] [--nofiledigest] [--nosize] [--nouser]
        [--nogroup] [--nomtime] [--nomode] [--nordev]
        [--nocaps] [--noconfig] [--noghost]

?示例:

[root@linux4 Packages]# rpm -ivh zsh-5.0.2-34.el7_8.2.x86_64.rpm 
Preparing...                          ################################# [100%]
Updating / installing...
   1:zsh-5.0.2-34.el7_8.2             ################################# [100%]
[root@linux4 Packages]# rpm -V zsh
[root@linux4 Packages]# 

6、数据库重建(此处待验证)
??rpm管理器数据库的路径: /var/lib/rpm
??rpm相关的查询操作会通过此数据库运行
??语法:rpm {–initdb|–rebuilddb}
????--initdb: 初始化数据库,当前无任何数据库可初始化创建一个新的,当前有时不执行任何操作
????--rebuilddb:重新构建,通过读取当前系统上所有已经安装过的程序包进行重新创建

[root@linux4 lib]# pwd
/var/lib
[root@linux4 lib]# ls rpm
Basenames     __db.001  __db.003  Group       Name          Packages     Requirename  Sigmd5
Conflictname  __db.002  Dirnames  Installtid  Obsoletename  Providename  Sha1header   Triggername

#############创建目录,备份rpm数据库,请务必做好备份!!!############
[root@linux4 lib]# mkdir rpm_bak   
[root@linux4 lib]# cp -r ./rpm/* rpm_bak
[root@linux4 lib]# rm -rf rpm
[root@linux4 lib]# rpm --initdb
[root@linux4 lib]# ls rpm
Basenames     __db.001  __db.003  Group       Name          Packages     Requirename  Sigmd5
Conflictname  __db.002  Dirnames  Installtid  Obsoletename  Providename  Sha1header   Triggername
[root@linux4 lib]# cd rpm
[root@linux4 rpm]# ls
Basenames     __db.001  __db.003  Group       Name          Packages     Requirename  Sigmd5
Conflictname  __db.002  Dirnames  Installtid  Obsoletename  Providename  Sha1header   Triggername
[root@linux4 rpm]# 
[root@linux4 rpm]# rpm --rebuilddb
[root@linux4 rpm]# ls
Basenames     Dirnames  Installtid  Obsoletename  Providename  Sha1header  Triggername
Conflictname  Group     Name        Packages      Requirename  Sigmd5
[root@linux4 rpm]# 

7、包来源合法性验证和完整性验证
??获取并导入信任的包制作者密钥:
???对于CentOS发行版来说命令如下:
????rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
??验证:
????1、安装此组织签名的程序时会自动执行验证
????2、手动验证:rpm -K PACKAGE_FILE

  系统运维 最新文章
配置小型公司网络WLAN基本业务(AC通过三层
如何在交付运维过程中建立风险底线意识,提
快速传输大文件,怎么通过网络传大文件给对
从游戏服务端角度分析移动同步(状态同步)
MySQL使用MyCat实现分库分表
如何用DWDM射频光纤技术实现200公里外的站点
国内顺畅下载k8s.gcr.io的镜像
自动化测试appium
ctfshow ssrf
Linux操作系统学习之实用指令(Centos7/8均
上一篇文章      下一篇文章      查看所有文章
加:2022-09-24 21:30:38  更:2022-09-24 21:33:31 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/15 10:05:46-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码