一、操作系统软件包管理概述

1.1 Windows 软件包管理方式

**系统级注册安装:**通过「控制面板」→「程序和功能」完成软件安装 / 卸载,软件信息会注册到系统注册表中。

**绿色软件:**无需注册,直接解压即可使用(如 U 盘启动盘工具 Rufus)。

软件包来源:系统应用商城、第三方官方网站(QQ、微信等)。

1.2 Linux 发行版包管理体系版本

包管理体系 代表发行版 核心特征
RPM RHEL、CentOS、Fedora、Rocky、OEL 红帽主导,标准化包格式,单文件管理
DEB Debian、Ubuntu、Kali Linux 社区驱动,遵循 GNU 规范,桌面 / 渗透测试场景常用
其他 ArchLinux、Gentoo 源码编译 / 轻量极简,面向高级用户

二、RPM 包深度解析

2.1 RPM 包文件名格式

RPM 包命名遵循统一规范:name-version-release.architecture.rpm

  • 示例:

    lrzsz-0.12.20-36.el7.x86_64.rpm

    • name:软件名称(lrzsz)

    • version:原始软件版本号(0.12.20)

    • release:发行版号(36.el7,由打包商定义)

    • architecture:架构类型

      • noarch:不限架构

      • x86_64:x86 64 位

      • aarch64:ARM 64 位

2.2 RPM 包组成结构

每个 RPM 包包含 3 核心部分:

  1. 安装文件:软件运行所需的可执行文件、库文件等;
  2. 元数据信息:包名、版本、架构、依赖关系、许可证、变更日志等;
  3. 脚本:安装 / 更新 / 卸载时自动执行的脚本(preinstall、postinstall 等);
  4. 数字签名:RedHat 等厂商通过 GPG 私钥签名,客户端用公钥验证完整性(基于非对称加密)。

2.3 RPM 包安装 / 更新规则

  • 同一软件默认仅保留最高版本(kernel 除外,可多版本共存,方便回滚);
  • 升级无需逐步更新,直接安装最新版本即可,旧版本会被替换,配置文件通常保留;
  • 内核包特殊设计:多版本安装时文件名无冲突,确保新内核启动失败时可回滚旧内核。

三、RPM 命令全场景实战

3.1 查询(核心高频操作)

基本语法:

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]

实战示例:

#1.查询系统已安装的所有软件包
[root@client ~ 16:29:48]# rpm -qa
firewalld-filesystem-0.6.3-13.el7_9.noarch
langtable-python-0.0.31-4.el7.noarch
kbd-misc-1.15.5-16.el7_9.noarch
libglvnd-gles-1.0.1-0.8.git5baa1e5.el7.x86_64
selinux-policy-targeted-3.13.1-268.el7_9.2.noarch
mobile-broadband-provider-info-1.20170310-1.el7.noarch
...

#2.查询指定软件是否安装
[root@client ~ 16:30:46]# rpm -q httpd
package httpd is not installed
[root@client ~ 16:30:58]# rpm -q kernel
kernel-3.10.0-1160.71.1.el7.x86_64

#3.查询已安装软件的元数据信息
[root@client ~ 16:31:21]# rpm -q coreutils -i
Name        : coreutils
Version     : 8.22
Release     : 24.el7_9.2
Architecture: x86_64
Install Date: Wed May 13 17:08:39 2026
Group       : System Environment/Base
Size        : 14594210
License     : GPLv3+
Signature   : RSA/SHA256, Wed Nov 18 22:16:51 2020, Key ID 24c6a8a7f4a80eb5
Source RPM  : coreutils-8.22-24.el7_9.2.src.rpm
Build Date  : Tue Nov 17 06:24:59 2020
Build Host  : x86-01.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://www.gnu.org/software/coreutils/
Summary     : A set of basic GNU tools commonly used in shell scripts
Description :
These are the GNU core utilities.  This package is the combination of
the old GNU fileutils, sh-utils, and textutils packages.

#4. 查询已安装软件包含的所有文件
[root@client ~ 16:31:49]# rpm -q openssh-server -l
/etc/pam.d/sshd
/etc/ssh/sshd_config
/etc/sysconfig/sshd
/usr/lib/systemd/system/sshd-keygen.service
/usr/lib/systemd/system/sshd.service
/usr/lib/systemd/system/sshd.socket
/usr/lib/systemd/system/sshd@.service
/usr/lib64/fipscheck/sshd.hmac
/usr/libexec/openssh/sftp-server
/usr/sbin/sshd
/usr/sbin/sshd-keygen
/usr/share/man/man5/moduli.5.gz
/usr/share/man/man5/sshd_config.5.gz
/usr/share/man/man8/sftp-server.8.gz
/usr/share/man/man8/sshd.8.g

#5. 查询已安装软件的配置文件
[root@client ~ 16:32:28]# rpm -q openssh-server -c
/etc/pam.d/sshd
/etc/ssh/sshd_config
/etc/sysconfig/sshd


#6. 查询已安装软件的文档文件
[root@client ~ 16:33:04]# rpm -q openssh-server -d 
/usr/share/man/man5/moduli.5.gz
/usr/share/man/man5/sshd_config.5.gz
/usr/share/man/man8/sftp-server.8.gz
/usr/share/man/man8/sshd.8.gz

#7. 查询指定文件所属的软件包
[root@client ~ 16:33:29]#  rpm -q -f /etc/ssh/sshd_config 
openssh-server-7.4p1-23.el7_9.x86_64

#8. 查询已安装软件的脚本(安装/卸载等)
[root@client ~ 16:33:53]#  rpm -q openssh-server --scripts
preinstall scriptlet (using /bin/sh):
getent group sshd >/dev/null || groupadd -g 74 -r sshd || :
getent passwd sshd >/dev/null || \
  useradd -c "Privilege-separated SSH" -u 74 -g sshd \
  -s /sbin/nologin -r -d /var/empty/sshd sshd 2> /dev/null || :
postinstall scriptlet (using /bin/sh):

if [ $1 -eq 1 ] ; then 
        # Initial installation 
        systemctl preset sshd.service sshd.socket >/dev/null 2>&1 || : 
fi
preuninstall scriptlet (using /bin/sh):

if [ $1 -eq 0 ] ; then 
        # Package removal, not upgrade 
        systemctl --no-reload disable sshd.service sshd.socket > /dev/null 2>&1 || : 
        systemctl stop sshd.service sshd.socket > /dev/null 2>&1 || : 
fi
postuninstall scriptlet (using /bin/sh):

systemctl daemon-reload >/dev/null 2>&1 || : 
if [ $1 -ge 1 ] ; then 
        # Package upgrade, not uninstall 
        systemctl try-restart sshd.service >/dev/null 2>&1 || : 
fi

#9. 查询软件包的变更日志
[root@client ~ 16:34:17]# rpm -q openssh-server --changelog 
* Thu Jul 20 2023 Dmitry Belyavskiy <dbelyavs@redhat.com> - 7.4p1-23 + 0.10.3-2
- Avoid remote code execution in ssh-agent PKCS#11 support
  Resolves: CVE-2023-38408
...


# 10. 查询本地RPM包文件的配置文件(-p参数)
# 先下载包:
[root@client ~ 16:36:32]# yum install -y yum-utils
[root@client ~ 16:36:44]# yumdownloader httpd
[root@client ~ 16:37:08]# ls httpd-*
httpd-2.4.6-99.el7.centos.1.x86_64.rpm

# 查询本地包的配置文件
[root@client ~ 16:37:29]# rpm -q -p httpd-2.4.6-99.el7.centos.1.x86_64.rpm -c
/etc/httpd/conf.d/autoindex.conf
/etc/httpd/conf.d/userdir.conf
/etc/httpd/conf.d/welcome.conf
/etc/httpd/conf.modules.d/00-base.conf
/etc/httpd/conf.modules.d/00-dav.conf
/etc/httpd/conf.modules.d/00-lua.conf
/etc/httpd/conf.modules.d/00-mpm.conf
/etc/httpd/conf.modules.d/00-proxy.conf
/etc/httpd/conf.modules.d/00-systemd.conf
/etc/httpd/conf.modules.d/01-cgi.conf
/etc/httpd/conf/httpd.conf
/etc/httpd/conf/magic
/etc/logrotate.d/httpd
/etc/sysconfig/htcacheclean
/etc/sysconfig/httpd

# 同样-l -d -i也可以配合-p使用

#11. 查询指定软件包组包含的软件
[root@client ~ 16:38:01]# rpm -qg 'System Environment/Base'
grub2-common-2.02-0.87.0.1.el7.centos.9.noarch
centos-release-7-9.2009.1.el7.centos.x86_64
setup-2.8.71-11.el7.noarch
filesystem-3.2-25.el7.x86_64
basesystem-10.0-7.el7.centos.noarch
......

扩展

# 查看软件包仓库位置
[root@client ~ 16:39:06]# repoquery --location httpd
http://mirrors.aliyun.com/centos/7/updates/x86_64/Packages/httpd-2.4.6-99.el7.centos.1.x86_64.rpm

# wget下载
[root@client ~ 16:40:51]# wget \
> http://mirrors.aliyun.com/centos/7/updates/x86_64/Packages/httpd-2.4.6-99.el7.centos.1.x86_64.rpm
--2026-05-18 16:41:03--  http://mirrors.aliyun.com/centos/7/updates/x86_64/Packages/httpd-2.4.6-99.el7.centos.1.x86_64.rpm
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 180.97.232.62, 218.92.233.18, 222.186.17.200, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|180.97.232.62|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2849200 (2.7M) [application/x-rpm]
Saving to: 'httpd-2.4.6-99.el7.centos.1.x86_64.rpm.1'

100%[===============================================================================================>] 2,849,200   1.76MB/s   in 1.5s  

3.2验证

基本语法:

rpm {-V|--verify} [select-options] [verify-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]
   
   verify-options
        [--nodeps] [--nofiles] [--noscripts]
        [--nodigest] [--nosignature]
        [--nolinkto] [--nofiledigest] [--nosize] [--nouser]
        [--nogroup] [--nomtime] [--nomode] [--nordev]
        [--nocaps] [--noconfig] [--noghost]

实战示例:

#1. 验证openssh-server安装完整性(无输出=无异常)
[root@client ~ 16:41:44]# rpm -V openssh-server 

#2. 修改配置文件后验证(触发异常提示)
[root@client ~ 16:42:04]# sed -i 's/PermitRootLogin yes/PermitRootLogin no/g' /etc/ssh/sshd_config
[root@client ~ 16:43:35]# rpm -V openssh-server
S.5....T.  c /etc/ssh/sshd_config
# 恢复配置
[root@client ~ 16:44:16]# sed -i 's/PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config

#3. 删除配置文件后验证
[root@client ~ 16:46:39]# mv /etc/ssh/sshd_config .
[root@client ~ 16:47:34]# rpm -V openssh-server
missing   c /etc/ssh/sshd_config
# 恢复文件
[root@client ~ 16:48:20]# mv sshd_config /etc/ssh/sshd_config

3.3 安装 / 卸载 / 重装

基本语法:

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]

实战示例:

#1.下载lrzsz包
[root@client ~ 16:49:15]# repoquery --location lrzsz
http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/lrzsz-0.12.20-36.el7.x86_64.rpm
root@client ~ 16:49:20]# wget http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/lrzsz-0.12.20-36.el7.x86_64.rpm

#2.安装lrzsz
[root@client ~ 16:50:18]# rpm -i lrzsz-0.12.20-36.el7.x86_64.rpm
	package lrzsz-0.12.20-36.el7.x86_64 is already installed
[root@client ~ 16:50:22]# rpm -q lrzsz
lrzsz-0.12.20-36.el7.x86_64

#3.卸载lrzsz
[root@client ~ 16:50:33]# rpm -e lrzsz
[root@client ~ 16:51:01]# rpm -q lrzsz
package lrzsz is not installed

#4.重新安装
[root@client ~ 16:51:12]# rpm --reinstall -vh lrzsz*
Preparing...                          ################################# [100%]
Updating / installing...
   1:lrzsz-0.12.20-36.el7             ################################# [100%]

四、YUM:RPM 包的自动化管理神器

4.1 YUM 核心优势

  • 自动解决依赖关系(RPM 命令无此能力);
  • 支持软件仓库管理,可从多个源获取包;
  • 集成安装 / 升级 / 降级 / 卸载 / 查询全流程。

4.2 YUM 高频命令实战

1. 查看软件包信息
# 查看httpd包详情
[root@client ~ 16:53:55]# yum info httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Available Packages
Name        : httpd
Arch        : x86_64
Version     : 2.4.6
Release     : 99.el7.centos.1
Size        : 2.7 M
Repo        : updates/7/x86_64
Summary     : Apache HTTP Server
URL         : http://httpd.apache.org/
License     : ASL 2.0
Description : The Apache HTTP Server is a powerful, efficient, and extensible
            : web server.

2.列出软件包清单
# 列出http开头的包
[root@client ~ 16:54:07]# yum list 'http*'
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Available Packages
http-parser.i686                                                        2.7.1-9.el7                                               base   
http-parser.x86_64                                                      2.7.1-9.el7                                               base   
http-parser-devel.i686                                                  2.7.1-9.el7                                               base   
http-parser-devel.x86_64                                                2.7.1-9.el7                                               base   
httpcomponents-client.noarch                                            4.2.5-5.el7_0                                             base   
httpcomponents-client-javadoc.noarch                                    4.2.5-5.el7_0                                             base   
httpcomponents-core.noarch                                              4.2.4-6.el7                                               base   
httpcomponents-core-javadoc.noarch                                      4.2.4-6.el7                                               base   
httpcomponents-project.noarch                                           6-4.el7                                                   base   
httpd.x86_64                                                            2.4.6-99.el7.centos.1                                     updates
httpd-devel.x86_64                                                      2.4.6-99.el7.centos.1                                     updates
httpd-itk.x86_64                                                        2.4.7.04-2.el7                                            epel   
httpd-manual.noarch                                                     2.4.6-99.el7.centos.1                                     updates
httpd-tools.x86_64                                                      2.4.6-99.el7.centos.1                                     updates
httpie.noarch                                                           1.0.3-1.el7                                               epel   
httping.x86_64                                                          2.5-1.el7                                                 epel   
httpress.x86_64                                                         1.1.0-2.el7                                               epel   
httpry.x86_64                                                           0.1.8-1.el7                                               epel   
httpunit.noarch                                                         1.7-15.el7                                                base   
httpunit-doc.noarch                                                     1.7-15.el7                                                base   
httpunit-javadoc.noarch                                                 1.7-15.el7                                                base   
......

# 列出httpd所有可用版本
[root@centos7 ~]# yum list httpd --showduplicates
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
已安装的软件包
httpd.x86_64               2.4.6-99.el7.centos.1                       @updates
可安装的软件包
httpd.x86_64               2.4.6-95.el7.centos                         base    
httpd.x86_64               2.4.6-97.el7.centos                         updates 
httpd.x86_64               2.4.6-97.el7.centos.1                       updates 
httpd.x86_64               2.4.6-97.el7.centos.2                       updates 
httpd.x86_64               2.4.6-97.el7.centos.4                       updates 
httpd.x86_64               2.4.6-97.el7.centos.5                       updates 
httpd.x86_64               2.4.6-98.el7.centos.6                       updates 
httpd.x86_64               2.4.6-98.el7.centos.7                       updates 
httpd.x86_64               2.4.6-99.el7.centos.1                       updates
3.查找文件所属包
# 查找sar命令所属包
[root@client ~ 16:57:54]# yum provides sar
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
docker-ce-stable/7/x86_64/filelists_db                                                                            |  66 kB  00:00:00     
mirrors.aliyun.com_kubernetes_yum_repos_kubernetes-el7-x86_64_/filelists                                          |  45 kB  00:00:00     
sysstat-10.1.5-19.el7.x86_64 : Collection of performance monitoring tools for Linux
Repo        : base
Matched from:
Filename    : /usr/bin/sar


sysstat-10.1.5-20.el7_9.x86_64 : Collection of performance monitoring tools for Linux
Repo        : updates
Matched from:
Filename    : /usr/bin/sar


sysstat-10.1.5-20.el7_9.x86_64 : Collection of performance monitoring tools for Linux
Repo        : @updates
Matched from:
Filename    : /usr/bin/sar
4.安装 / 下载软件包
# 安装vsftpd
[root@client ~ 16:59:13]# yum install -y vsftpd

# 只下载不安装(含依赖)
[root@client ~ 16:59:17]# yum install vsftpd --downloadonly --downloaddir=/root/
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Package vsftpd-3.0.2-29.el7_9.x86_64 already installed and latest version
Nothing to do
[root@client ~ 16:59:40]# ls vsftpd-*
vsftpd-3.0.2-29.el7_9.x86_64.rpm

5.降级 / 升级软件包
# 安装本地文件系统中vsftpd包
[root@client ~ 16:59:50]# yum localinstall ./vsftpd-3.0.2-29.el7_9.x86_64.rpm
Loaded plugins: fastestmirror
Examining ./vsftpd-3.0.2-29.el7_9.x86_64.rpm: vsftpd-3.0.2-29.el7_9.x86_64
./vsftpd-3.0.2-29.el7_9.x86_64.rpm: does not update installed package.
Nothing to do
 
# 降级vsftpd到指定版本
[root@client ~ 17:00:39]# yum downgrade -y vsftpd-3.0.2-28.el7
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package vsftpd.x86_64 0:3.0.2-28.el7 will be a downgrade
---> Package vsftpd.x86_64 0:3.0.2-29.el7_9 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================================================================
 Package                        Arch                           Version                                Repository                    Size
=========================================================================================================================================
Downgrading:
 vsftpd                         x86_64                         3.0.2-28.el7                           base                         172 k

Transaction Summary
=========================================================================================================================================
Downgrade  1 Package

Total download size: 172 k
Downloading packages:
vsftpd-3.0.2-28.el7.x86_64.rpm                                                                                    | 172 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : vsftpd-3.0.2-28.el7.x86_64                                                                                            1/2 
  Cleanup    : vsftpd-3.0.2-29.el7_9.x86_64                                                                                          2/2 
  Verifying  : vsftpd-3.0.2-28.el7.x86_64                                                                                            1/2 
  Verifying  : vsftpd-3.0.2-29.el7_9.x86_64                                                                                          2/2 

Removed:
  vsftpd.x86_64 0:3.0.2-29.el7_9                                                                                                         

Installed:
  vsftpd.x86_64 0:3.0.2-28.el7                                                                                                           

Complete!

# 降级的时候,要一并降级依赖软件包

# 环境准备:安装最新版httpd
[root@client ~ 17:00:49]# yum install -y httpd

# 降级到特定版本:降级失败,因为已安装的 httpd-tools 无法满足当前httpd版本
[root@client ~ 17:02:05]# yum downgrade -y httpd-2.4.6-97.el7.centos 
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-97.el7.centos will be a downgrade
--> Processing Dependency: httpd-tools = 2.4.6-97.el7.centos for package: httpd-2.4.6-97.el7.centos.x86_64
---> Package httpd.x86_64 0:2.4.6-99.el7.centos.1 will be erased
--> Finished Dependency Resolution
Error: Package: httpd-2.4.6-97.el7.centos.x86_64 (updates)
           Requires: httpd-tools = 2.4.6-97.el7.centos
           Installed: httpd-tools-2.4.6-99.el7.centos.1.x86_64 (@updates)
               httpd-tools = 2.4.6-99.el7.centos.1
           Available: httpd-tools-2.4.6-95.el7.centos.x86_64 (base)
               httpd-tools = 2.4.6-95.el7.centos
           Available: httpd-tools-2.4.6-97.el7.centos.x86_64 (updates)
               httpd-tools = 2.4.6-97.el7.centos
           Available: httpd-tools-2.4.6-97.el7.centos.1.x86_64 (updates)
               httpd-tools = 2.4.6-97.el7.centos.1
           Available: httpd-tools-2.4.6-97.el7.centos.2.x86_64 (updates)
               httpd-tools = 2.4.6-97.el7.centos.2
           Available: httpd-tools-2.4.6-97.el7.centos.4.x86_64 (updates)
               httpd-tools = 2.4.6-97.el7.centos.4
           Available: httpd-tools-2.4.6-97.el7.centos.5.x86_64 (updates)
               httpd-tools = 2.4.6-97.el7.centos.5
           Available: httpd-tools-2.4.6-98.el7.centos.6.x86_64 (updates)
               httpd-tools = 2.4.6-98.el7.centos.6
           Available: httpd-tools-2.4.6-98.el7.centos.7.x86_64 (updates)
               httpd-tools = 2.4.6-98.el7.centos.7
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

 
 # 解决方法:httpd-tools与httpd一起降级到相同版本
[root@client ~ 17:02:09]# yum downgrade -y httpd-tools-2.4.6-97.el7.centos httpd-2.4.6-97.el7.centos

# 升级 vsftpd 版本为 3.0.2-29.el7_9
[root@client ~ 17:03:12]# yum update vsftpd-3.0.2-29.el7_9

# 升级系统中所有软件为最新版本
[root@client ~ 17:03:48]# yum update 
6.卸载软件包
# 卸载软件包
[root@client ~ 17:04:29]# yum remove -y vsftpd
7.YUM 事务历史管理
# 列出事务历史
[root@client ~ 17:04:56]# yum history list
Loaded plugins: fastestmirror
ID     | Command line             | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
    22 | remove -y vsftpd         | 2026-05-18 17:04 | Erase          |    1   
    21 | update vsftpd-3.0.2-29.e | 2026-05-18 17:03 | Update         |    1   
    20 | downgrade -y httpd-tools | 2026-05-18 17:02 | Downgrade      |    2   
    19 | install -y httpd         | 2026-05-18 17:01 | Install        |    5   
    18 | downgrade -y vsftpd-3.0. | 2026-05-18 17:00 | Downgrade      |    1   
    17 | install -y vsftpd        | 2026-05-18 16:59 | Update         |    1   
    16 | -y install gcc make auto | 2026-05-18 16:17 | Install        |    3   
    15 | install -y wget          | 2026-05-18 15:52 | Install        |    1   
    14 | install gcc make pcre-de | 2026-05-18 15:51 | I, U           |   10   
    13 | install kubectl --nogpgc | 2026-05-18 14:58 | Install        |    1   
    12 | groupremove Server with  | 2026-05-18 14:05 | Erase          |  476 EE
    11 | groupinstall Server with | 2026-05-18 14:02 | I, U           | 1004 EE
    10 | downgrade -y vsftpd      | 2026-05-18 13:50 | Downgrade      |    1   
     9 | install -y vsftpd        | 2026-05-18 13:49 | Update         |    1   
     8 | update openssh-server    | 2026-05-18 11:32 | Update         |    3   
     7 | downgrade -y openssh-ser | 2026-05-18 11:31 | Downgrade      |    3   
     6 | install -y vsftpd-3.0.2- | 2026-05-18 11:24 | Install        |    1   
     5 | install net-tools        | 2026-05-18 11:18 | Install        |    1   
     4 | install -y sysstat       | 2026-05-18 11:16 | Install        |    2   
     3 | install -y yum-utils     | 2026-05-18 09:59 | Install        |    4   
history list


[root@client ~ 17:05:24]# yum install -y vsftpd
[root@client ~ 17:05:33]# yum downgrade -y vsftpd


# list 可以省略
[root@client ~ 17:05:43]# yum history 
Loaded plugins: fastestmirror
ID     | Command line             | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
    24 | downgrade -y vsftpd      | 2026-05-18 17:05 | Downgrade      |    1   
    23 | install -y vsftpd        | 2026-05-18 17:05 | Install        |    1   
    22 | remove -y vsftpd         | 2026-05-18 17:04 | Erase          |    1   
    21 | update vsftpd-3.0.2-29.e | 2026-05-18 17:03 | Update         |    1   
    20 | downgrade -y httpd-tools | 2026-05-18 17:02 | Downgrade      |    2   
    19 | install -y httpd         | 2026-05-18 17:01 | Install        |    5   
    18 | downgrade -y vsftpd-3.0. | 2026-05-18 17:00 | Downgrade      |    1   
    17 | install -y vsftpd        | 2026-05-18 16:59 | Update         |    1   
    16 | -y install gcc make auto | 2026-05-18 16:17 | Install        |    3   
    15 | install -y wget          | 2026-05-18 15:52 | Install        |    1   
    14 | install gcc make pcre-de | 2026-05-18 15:51 | I, U           |   10   
    13 | install kubectl --nogpgc | 2026-05-18 14:58 | Install        |    1   
    12 | groupremove Server with  | 2026-05-18 14:05 | Erase          |  476 EE
    11 | groupinstall Server with | 2026-05-18 14:02 | I, U           | 1004 EE
    10 | downgrade -y vsftpd      | 2026-05-18 13:50 | Downgrade      |    1   
     9 | install -y vsftpd        | 2026-05-18 13:49 | Update         |    1   
     8 | update openssh-server    | 2026-05-18 11:32 | Update         |    3   
     7 | downgrade -y openssh-ser | 2026-05-18 11:31 | Downgrade      |    3   
     6 | install -y vsftpd-3.0.2- | 2026-05-18 11:24 | Install        |    1   
     5 | install net-tools        | 2026-05-18 11:18 | Install        |    1   
history list

# 查看指定事务详情
[root@client ~ 17:07:04]# yum history info 2
Loaded plugins: fastestmirror
Transaction ID : 2
Begin time     : Wed May 13 17:19:30 2026
Begin rpmdb    : 312:499b8befefcbbb73843ba57c528196865f88451d
End time       :            17:19:34 2026 (4 seconds)
End rpmdb      : 348:bc9b692c0e326e6ab21641fc36c579df62811fe9
User           : root <root>
Return-Code    : Success
Command Line   : install -y bash-completion vim open-vm-tools lrzsz unzip rsync sshpass
Transaction performed with:
    Installed     rpm-4.11.3-48.el7_9.x86_64                      @anaconda
    Installed     yum-3.4.3-168.el7.centos.noarch                 @anaconda
    Installed     yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch @anaconda
Packages Altered:
    Install     bash-completion-1:2.1-8.el7.noarch         @base
    Dep-Install gpm-libs-1.20.7-6.el7.x86_64               @base
    Install     lrzsz-0.12.20-36.el7.x86_64                @base
    Updated     open-vm-tools-11.0.5-3.el7_9.3.x86_64      @anaconda
    Update                    11.0.5-3.el7_9.9.x86_64      @updates
    Dep-Install perl-4:5.16.3-299.el7_9.x86_64             @updates
    Dep-Install perl-Carp-1.26-244.el7.noarch              @base

......

# 撤销指定事务
[root@client ~ 17:07:41]# yum history undo 4

# 重做指定事务
[root@client ~ 17:08:00]# yum history redo 4

4.3 软件包组管理

# 列出所有包组
[root@client ~ 17:08:22]# yum grouplist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Available Environment Groups:
   Minimal Install
   Compute Node
   Infrastructure Server
   File and Print Server
   Cinnamon Desktop
   MATE Desktop
   Basic Web Server
   Virtualization Host
   Server with GUI
   GNOME Desktop
   KDE Plasma Workspaces
   Development and Creative Workstation
Available Groups:
   Cinnamon
   Compatibility Libraries
   Console Internet Tools
   Development Tools
   Educational Software
   Electronic Lab
   Fedora Packager
   General Purpose Desktop
   Graphical Administration Tools
   Haskell
   LXQt Desktop
   Legacy UNIX Compatibility
   MATE
   Milkymist
   Scientific Support
   Security Tools
   Smart Card Support
   System Administration Tools
   System Management
   TurboGears application framework
   Xfce
Done

# 详细列出包组(含组ID)
[root@client ~ 17:08:41]# yum grouplist -v
Loading "fastestmirror" plugin
Config time: 0.002
Yum version: 3.4.3
Setting up Package Sacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
pkgsack time: 0.006
group time: 0.028
Available Environment Groups:
   Minimal Install (minimal)
   Compute Node (compute-node-environment)
   Infrastructure Server (infrastructure-server-environment)
   File and Print Server (file-print-server-environment)
   Cinnamon Desktop (cinnamon-desktop-environment)
   MATE Desktop (mate-desktop-environment)
   Basic Web Server (web-server-environment)
   Virtualization Host (virtualization-host-environment)
   Server with GUI (graphical-server-environment)
   GNOME Desktop (gnome-desktop-environment)
   KDE Plasma Workspaces (kde-desktop-environment)
   Development and Creative Workstation (developer-workstation-environment)
Available Groups:
   Cinnamon (cinnamon-desktop)
   Compatibility Libraries (compat-libraries)
   Console Internet Tools (console-internet)
   Development Tools (development)
   Educational Software (education)
   Electronic Lab (electronic-lab)
   Fedora Packager (fedora-packager)
   General Purpose Desktop (general-desktop)
   Graphical Administration Tools (graphical-admin-tools)
   Haskell (haskell)
   LXQt Desktop (lxqt-desktop)
   Legacy UNIX Compatibility (legacy-unix)
   MATE (mate-desktop)
   Milkymist (milkymist)
   Scientific Support (scientific)
   Security Tools (security-tools)
   Smart Card Support (smart-card)
   System Administration Tools (system-admin-tools)
   System Management (system-management)
   TurboGears application framework (turbogears)
   Xfce (xfce-desktop)
Done


[root@client ~ 17:09:15]# unset LANG
[root@client ~ 17:09:37]# yum group list -v
Loading "fastestmirror" plugin
Config time: 0.003
Yum version: 3.4.3
Setting up Package Sacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
pkgsack time: 0.006
group time: 0.029
Available Environment Groups:
   Minimal Install (minimal)
   Compute Node (compute-node-environment)
   Infrastructure Server (infrastructure-server-environment)
   File and Print Server (file-print-server-environment)
   Cinnamon Desktop (cinnamon-desktop-environment)
   MATE Desktop (mate-desktop-environment)
   Basic Web Server (web-server-environment)
   Virtualization Host (virtualization-host-environment)
   Server with GUI (graphical-server-environment)
   GNOME Desktop (gnome-desktop-environment)
   KDE Plasma Workspaces (kde-desktop-environment)
   Development and Creative Workstation (developer-workstation-environment)
Available Groups:
   Cinnamon (cinnamon-desktop)
   Compatibility Libraries (compat-libraries)
   Console Internet Tools (console-internet)
   Development Tools (development)
   Educational Software (education)
   Electronic Lab (electronic-lab)
   Fedora Packager (fedora-packager)
   General Purpose Desktop (general-desktop)
   Graphical Administration Tools (graphical-admin-tools)
   Haskell (haskell)
   LXQt Desktop (lxqt-desktop)
   Legacy UNIX Compatibility (legacy-unix)
   MATE (mate-desktop)
   Milkymist (milkymist)
   Scientific Support (scientific)
   Security Tools (security-tools)
   Smart Card Support (smart-card)
   System Administration Tools (system-admin-tools)
   System Management (system-management)
   TurboGears application framework (turbogears)
   Xfce (xfce-desktop)
Done

# 查看指定包组详情
[root@client ~ 17:11:08]# yum groupinfo 'Server with GUI'

# 安装指定包组
[root@client ~ 17:11:33]#  yum groupinstall 'Server with GUI'

# 卸载指定包组
[root@client ~ 17:12:02]# yum groupremove 'Server with GUI

五、yum 仓库配置

5.1 核心配置文件

YUM 主配置文件:/etc/yum.conf,包含全局配置(main 块)和仓库引用,独立仓库配置存放在 /etc/yum.repos.d/*.repo

[root@client ~ 14:35:51]# cat /etc/yum.conf 
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release


#  This is the default, if you make this bigger yum won't see if the metadata
# is newer on the remote and so you'll "gain" the bandwidth of not having to
# download the new metadata and "pay" for it by yum not having correct
# information.
#  It is esp. important, to have correct metadata, for distributions like
# Fedora which don't keep old packages around. If you don't like this checking
# interupting your command line usage, it's much better to have something
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m

# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d

5.2 配置查看技巧

# 安装yum-utils工具
[root@client ~ 14:48:11]# yum install -y yum-utils
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Package yum-utils-1.1.31-54.el7_8.noarch already installed and latest version
Nothing to do


# 导出 yum 完整配置
[root@client ~ 14:48:27]# yum-config-manager 
Loaded plugins: fastestmirror
================================================================= main ==================================================================
[main]
alwaysprompt = True
assumeno = False
assumeyes = False
autocheck_running_kernel = True
autosavets = True
bandwidth = 0
bugtracker_url = http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
cache = 0
cachedir = /var/cache/yum/x86_64/7
check_config_file_age = True
clean_requirements_on_remove = False
color = auto
color_list_available_downgrade = dim,cyan
color_list_available_install = normal
color_list_available_reinstall = bold,underline,green
color_list_available_running_kernel = bold,underline

...

main 部分设置全局配置:

  • enabled = 1,仓库默认启用。
  • gpgcheck = 1,仓库默认启用gpg校验。
  • keepcache = 0,不保存缓存。
  • cachedir = /var/cache/yum,缓存文件保存的位置。
  • reposdir = /etc/yum.repos.d, /etc/yum/repos.d,yum仓库配置文件。

yum管理的软件包存放在yum仓库,yum仓库配置文件存放在/etc/yum.repos.d目录。

[root@client ~ 14:48:42]# ls /etc/yum.repos.d/
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Sources.repo  CentOS-fasttrack.repo      epel.repo
CentOS-CR.repo    CentOS-Media.repo      CentOS-Vault.repo    CentOS-x86_64-kernel.repo

5.3 仓库常用管理操作

1.查看启用的yum仓库
# 查看启用的yum仓库
[root@client ~ 14:49:09]# yum repolist   
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
repo id                                           repo name                                                                        status
base/7/x86_64                                     CentOS-7 - Base - mirrors.aliyun.com                                             10072
epel/x86_64                                       Extra Packages for Enterprise Linux 7 - x86_64                                   13791
extras/7/x86_64                                   CentOS-7 - Extras - mirrors.aliyun.com                                             526
updates/7/x86_64                                  CentOS-7 - Updates - mirrors.aliyun.com                                           6173
repolist: 30562


# 查看 yum 所有仓库,包括未启用的仓库
[root@client ~ 14:49:54]# yum repolist all
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
repo id                                            repo name                                                               status
C7.0.1406-base/x86_64                              CentOS-7.0.1406 - Base                                                  disabled
C7.0.1406-centosplus/x86_64                        CentOS-7.0.1406 - CentOSPlus                                            disabled
C7.0.1406-extras/x86_64                            CentOS-7.0.1406 - Extras                                                disabled
C7.0.1406-fasttrack/x86_64                         CentOS-7.0.1406 - Fasttrack                                             disabled
...
2.启用和禁用仓库
# 启用
[root@client ~ 14:50:08]# yum-config-manager --enable epel-debuginfo
Loaded plugins: fastestmirror
========================================================= repo: epel-debuginfo ==========================================================
[epel-debuginfo]
async = True
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/7
baseurl = http://mirrors.aliyun.com/epel/7/x86_64/debug
cache = 0
cachedir = /var/cache/yum/x86_64/7/epel-debuginfo
...
# 禁用
[root@client ~ 14:50:57]# yum-config-manager --disable epel-debuginfo
Loaded plugins: fastestmirror
========================================================= repo: epel-debuginfo ==========================================================
[epel-debuginfo]
async = True
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/7
baseurl = http://mirrors.aliyun.com/epel/7/x86_64/debug
cache = 0
cachedir = /var/cache/yum/x86_64/7/epel-debuginfo
...

也可以编辑仓库配置文件,将仓库中enabled值设置为1启用,设置为0禁用。

# 查看禁用的仓库清单
[root@client ~ 14:51:12]# vim /etc/yum.repos.d/epel.repo 
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://mirrors.aliyun.com/epel/7/$basearch
failovermethod=priority
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=http://mirrors.aliyun.com/epel/7/$basearch/debug
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0

[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=http://mirrors.aliyun.com/epel/7/SRPMS
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0

3.仓库缓存管理

更新缓存后,yum install命令可补全软件包名称。

# 清理缓存数据
[root@client ~ 14:51:43]# yum clean 
all           cache         dbcache       expire-cache  headers       metadata      packages 

# 清理所有缓存数据
[root@client ~ 14:52:12]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base epel extras updates
Cleaning up list of fastest mirrors

# 创建缓存数据
[root@client ~ 14:53:02]# yum makecache 
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                                              | 3.6 kB  00:00:00     
epel                                                                                                              | 4.3 kB  00:00:00     
extras                                                                                                            | 2.9 kB  00:00:00     
updates                                                                                                           | 2.9 kB  00:00:00     
(1/16): base/7/x86_64/group_gz                                                                                    | 153 kB  00:00:00     
(2/16): base/7/x86_64/primary_db                                                                                  | 6.1 MB  00:00:06     
(3/16): base/7/x86_64/filelists_db                                                                                | 7.2 MB  00:00:07     
(4/16): epel/x86_64/group                                                                                         | 399 kB  00:00:01     
(5/16): epel/x86_64/updateinfo                                                                                    | 1.0 MB  00:00:01     
(6/16): epel/x86_64/prestodelta                                                                                   |  592 B  00:00:00     
(7/16): base/7/x86_64/other_db                                                                                    | 2.6 MB  00:00:03     
(8/16): epel/x86_64/primary_db                                                                                    | 8.7 MB  00:00:12     
(9/16): extras/7/x86_64/primary_db                                                                                | 253 kB  00:00:00     
(10/16): extras/7/x86_64/filelists_db                                                                             | 305 kB  00:00:00     
(11/16): extras/7/x86_64/other_db                                                                                 | 154 kB  00:00:00     
(12/16): epel/x86_64/other_db                                                                                     | 4.1 MB  00:00:06     
(13/16): epel/x86_64/filelists_db                                                                                 |  15 MB  00:00:21     
(14/16): updates/7/x86_64/filelists_db                                                                            |  15 MB  00:00:17     
(15/16): updates/7/x86_64/other_db                                                                                | 1.6 MB  00:00:01     
(16/16): updates/7/x86_64/primary_db                                                                              |  27 MB  00:00:28     
Metadata Cache Created

元数据缓存已建立
添加 kubernetes 仓库
[root@client ~ 14:54:22]# yum-config-manager --add-repo=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
Loaded plugins: fastestmirror
adding repo from: https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/

[mirrors.aliyun.com_kubernetes_yum_repos_kubernetes-el7-x86_64_]
name=added from: https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1


root@client ~ 14:57:17]# cat /etc/yum.repos.d/mirrors.aliyun.com_kubernetes_yum_repos_kubernetes-el7-x86_64_.repo 

[mirrors.aliyun.com_kubernetes_yum_repos_kubernetes-el7-x86_64_]
name=added from: https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1


# 安装 kubectl 包
[root@client ~ 14:57:31]# yum install kubectl --nogpgcheck
添加 docker-ce 仓库
[root@client ~ 14:58:35]# cat << 'EOF' > /etc/yum.repos.d/docker-ce.repo
> [docker-ce-stable]
> name=Docker CE Stable - $basearch
> baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/$basearch/stable
> enabled=1
> gpgcheck=0
> EOF


# 查看docker版本
[root@client ~ 14:58:52]# yum list docker-ce
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
docker-ce-stable                                                                                                  | 3.5 kB  00:00:00     
(1/2): docker-ce-stable/7/x86_64/updateinfo                                                                       |   55 B  00:00:00     
(2/2): docker-ce-stable/7/x86_64/primary_db                                                                       | 152 kB  00:00:00     
Available Packages
docker-ce.x86_64                                             3:26.1.4-1.el7                                              docker-ce-stable
epel 仓库

EPEL(Extra Packages for Enterprise Linux),是由Fedora Special Interest Group维护的Enterprise Linux(RHEL、CentOS)中经常用到的包。

# 直接使用aliyun的源
[root@client ~ 14:59:15]# curl -s -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

Logo

openEuler 是由开放原子开源基金会孵化的全场景开源操作系统项目,面向数字基础设施四大核心场景(服务器、云计算、边缘计算、嵌入式),全面支持 ARM、x86、RISC-V、loongArch、PowerPC、SW-64 等多样性计算架构

更多推荐