yum & dnf 包管理器

RPM包基础

参考链接:学习CentOS的包管理 | 骏马金龙 (junmajinlong.com)

包名称

rhel/centos/fedora上,包的名称以rpm结尾,它们分为二进制包和源码包。

源码包以.src.rpm结尾,它是未编译过的包,可以自行进行编译或者用其制作自己的二进制rpm包。非.src.rpm结尾的包都是二进制包,都是已经编译完成的。

安装rpm包的过程实际上就是将包中的文件复制到Linux上,有可能还会在复制文件的前后执行一些命令,如创建一个必要的用户,删除非必要文件等。关于rpm包的制作,可能是件很烦人的事,但学习它还是非常有必要的,至少也得能制作简单的包吧?网上有很多文章,也可以参考官网:

  • https://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/Packagers_Guide/index.html
  • https://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/index.html

注意区分源码包和源码的概念,源码一般是打包压缩后的文件(如.tar.gz结尾的文件)。源码包中包含了源码,还包含了一些有助于制作二进制rpm的文件。最有力的说明就是源码编译安装的程序都没有服务启动脚本(/etc/init.d/下对应的启动脚本),而二进制rpm包安装的就有,因为二进制rpm包都是通过源码包.src.rpm定制而来,在源码包中提供了必要的文件(如服务启动脚本),并在安装rpm的时候复制到指定路径下。

回归正题,一个rpm包的名称分为包全名和包名,包全名如httpd-2.2.15-39.el6.centos.x86_64.rpm,包全名中各部分的意义如下:

1
2
3
4
5
6
7
httpd   	  # 包名
2.2.15 # 版本号,版本号格式[ 主版本号.[ 次版本号.[ 修正号 ] ] ]
39 # 软件发布次数
el6.centos # 适合的操作系统平台以及适合的操作系统版本
x86_64 # 适合的硬件平台,硬件平台根据cpu来决定,
# 有i386、i586、i686、x86_64、noarch或者省略,noarch或省略表示不区分硬件平台
rpm # 软件包后缀扩展名

使用rpm工具管理包时,如果要操作未安装的包,则使用包全名,如安装包,查看未安装包的信息等;如果要操作已安装的rpm包,则只需要给定其包名即可,如查询已装包生成了哪些文件,查看已装包的信息等。

而对于yum工具来说,只需给定其包名即可,若有需要,再指定版本号,如明确指明要安装1.6.10版本的tree工具,yum install tree-1.6.10

主包和子包

对于一个程序而言,在制作rpm包时,很多时候都将其按功能分割成多个子包,如客户端程序包、服务端程序包等。

mysql这个程序来说,它分有以下几个包。

1
2
3
4
5
mysql-server.x86_64
mysql.x86_64
mysql-bench.x86_64
mysql-libs.x86_64
mysql-devel.x86_64

其中mysql-server.x86_64是提供服务的主包,mysql.x86_64是客户端主包,mysql-bench是用于对MySQL进行压力测试的包,mysql-libsmysql-devel分别是库文件包和头文件包。后两者是提供给其他需要联合mysql的程序使用的,仅就实现mysql服务而言,只需安装mysql-server即可。

而源码编译安装的包会包含所有功能包,也就是说编译安装一个程序后,它的客户端工具、服务提供程序、库文件、头文件等等都已经安装了。

rpm管理包

rpm包被安装后,会在/var/lib/rpm下会建立已装rpm数据库,以后有任何rpm的升级、查询、版本比较等包的操作都是从这个目录下获取信息并完成相应操作的。

1
2
3
4
5
[root@vagrant ~]# ll /var/lib/rpm
total 145904
-rw-r--r--. 1 root root 149372928 Jun 7 10:57 rpmdb.sqlite
-rw-r--r--. 1 root root 32768 Jun 7 11:39 rpmdb.sqlite-shm
-rw-r--r--. 1 root root 0 Jun 7 10:57 rpmdb.sqlite-wal

安装包后的文件分布

rpm安装完成后,相关的文件会复制到多个目录下(具体复制的路径是在制作rpm包时指定的)。一般来说,分布形式差不多如下表。

路径 一般作用
/etc 放置配置文件的目录
/bin、/sbin、/usr/bin或/usr/sbin 一些可执行文件
/lib、/lib64、/usr/lib(/usr/lib64) 一些库文件
/usr/include 一些头文件
/usr/share/doc 一些基本的软件使用手册与帮助文件
/usr/share/man 一些 man page 档案

rpm指令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
rpm -ivhUe --nodeps --test --force --prefix

选项说明:
-i 表示安装,install的意思
-v 显示安装信息,还可以"-vv""-vvv",v提供的越多显示信息越多
-h 显示安装进度,以#显示安装的进度
-U 升级或升级包
-F 只升级已安装的包
-e 卸载包,卸载也有依赖性,"--erase"
--nodeps 忽略依赖性强制安装或卸载(no dependencies)
--test 测试是否能够成功安装指定的rpm包
--prefix 新路径 自行指定安装路径而不是使用默认路径,基本上都不支持该功能,功能极其简单的软件估计才支持重定位安装路径
--force 强制动作
--replacepkgs 替换安装,即重新覆盖安装。

有时误删文件可以不用卸载再装,直接使用--replacepkgs选项再次安装即可。

rpm包另一个缺陷是只能安装本地或给定url路径的rpm包。

注意:尽量不要对内核进行升级;多版本的内核可以并存,因此可以执行安装操作。

rpm查询

1
2
3
4
5
6
7
8
9
-q[p] -q查询已安装的包,-qp查询未安装的包。它们都可接下面的参数
-a 查询所有已安装的包,也可以指定通配符名称进行查询
-i 查询指定包的信息(版本、开发商、安装时间等)。从这里面可以查看到软件包属于哪个包组。
-l 查询包的文件列表和目录(包在生产的时候就指定了文件路径,因此可查未装包)
-R 查询包的依赖性(Required)
-c 查询安装后包生成的配置文件
-d 查询安装后包生成的帮助文档
-f 查询系统文件属于哪个已安装的包(接的是文件而不是包)
--scripts 查询包相关的脚本文档。脚本文档分四类:安装前运行、安装后运行、卸载前运行、卸载后运行

示例

1
2
3
4
5
6
7
8
9
10
11
# 查询文件/etc/yum.conf是通过哪个包安装的
rpm -qf /etc/yum.conf

# 查询安装httpd时生成了哪些目录和文件,还可以过滤出提供了哪些命令行工具。
rpm -ql httpd
rpm -ql httpd | grep 'bin/'

# 查询某个未安装包的依赖性如zip-3.0-1.el6.x86_64.rpm的依赖性。
rpm -qRp zip-3.0-1.el6.x86_64.rpm
# 实际上,查看包的依赖性时,使用yum-utils包中的repoquery工具更好,
# repoquery -R pkg_name会更简洁。yum-utils中包含了好几个非常实用的包管理工具,可以大致都了解下。

提取rpm包中文件

安装rpm包会安装rpm中所有文件,如果将某个文件删除了,除了重装rpm,还可以通过从rpm包提取缺失文件的方式来修复。在win上安装个万能压缩工具【好压】(嫌其流氓可以换其他工具),可以直接打开rpm包,然后从中解压需要的文件出来。但是在Linux上,过程还是有点小复杂的,其中涉及了cpio这个古来的归档工具。

方法:使用rpm2cpio命令组合cpio -idv命令的方式来提取。cpio具体用法参见cpio归档工具用法详细说明

rpm2cpio是将rpm转换为cpio格式归档文件的命令,有了cpio文件,就可以使用cpio命令对其进行相关的操作。

cpio命令是从归档文件中提取文件或向归档文件中写入文件的工具,一般都从标准输入或输出操作归档文件,所以都使用管道或重定向符号。

1
2
3
4
-i: 运行在copy-in模式,即从归档文件中将文件copy出来,即提取文件(提取)
-o: 运行在copy-out模式,将文件copy到归档文件中,即将文件拷贝到归档文件中(写入)
-d: 需要目录时自动建立目录
-v: 显示信息

提取rpm包文件的一般格式为以下格式:

1
rpm2cpio package_full_name|cpio -idv dir_name

例如,删除/bin/ls文件,将导致ls命令不可用,使用文件提取的方式去修复。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@xuexi cdrom]# which ls     # 查找需要删除的ls文件位置
alias ls='ls --color=auto'
/bin/ls
[root@xuexi cdrom]# rpm -qf /bin/ls # 查找ls命令属于哪个包
coreutils-8.4-37.el6.x86_64
[root@xuexi cdrom]# rm -f /bin/ls # 删除ls命令
[root@xuexi cdrom]# ls # ls命令已不可用
-bash: /bin/ls: No such file or directory
[root@xuexi ~]# yumdownloader coreutils # 下载所需的rpm包
[root@xuexi ~]# rpm2cpio coreutils-8.4-37.el6.x86_64.rpm | cpio -id ./bin/ls # 提取bin/ls到当前目录下
[root@xuexi ~]# dir ~/bin # 使用dir命令查看已经提取成功,dir命令功能等价于ls
ls
[root@xuexi tmp]# cp bin/ls /bin/ # 复制ls命令到/bin下
[root@xuexi tmp]# ls # 测试,ls已经可用

yum仓库配置文件语法

1
2
3
4
5
6
7
8
9
10
$ vim CentOS-Base.repo
[base] # 仓库ID,ID必须保证唯一性
name # 仓库名称,可随意命名
mirrorlist # 该地址下包含了仓库地址列表,包含一个或多个镜像站点,和baseurl使用一个就可以了
#baseurl # 仓库地址。网络上的地址则写网络地址,
# 本地地址则写本地地址,格式为"file://"后接路径,如file:///mnt/cdrom
gpgcheck=1 # 指定是否需要gpg签名,1表示需要,0表示不需要
gpgkey = # 签名文件的路径
enabled # 该仓库是否生效,enabled=1表示生效,enabled=0表示不生效
cost= # 开销越高,优先级越低

repo配置文件中默认可用的宏:

  • $releasever:程序的版本(release version),对yum而言指的是redhat-release版本。只替换为主版本号,如redhat6.5 则替换为6
  • $arch:系统架构
  • $basharch:系统基本架构,如i686,i586等的基本架构为i386
  • $YUM0-9:在系统定义的环境变量,可以在yum中使用

也可以自己在/etc/yum/vars目录中定义变量文件。例如:

1
2
$ cat /etc/yum/vars/huawei 
https://mirrors.huaweicloud.com

然后就可以在repo的配置文件中使用变量$huawei

1
2
3
4
5
6
$ cat /etc/yum.repos.d/base.repo 
[base]
name=os
baseurl=$huawei/centos/$releasever/os/$basearch/
gpgcheck=0
enabled=1

RHEL7 本地仓库配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
mount /dev/sr1 /mnt
mount –o loop –t iso9660 rhel.iso /mnt

mkdir /opt/cdrom
cp -fr /mnt/* /opt/cdrom

# CentOS7-Media.repo
[root@docker1 yum.repos.d]# cat CentOS-Media.repo
# CentOS-Media.repo
#
# This repo can be used with mounted DVD media, verify the mount point for
# CentOS-7. You can use this repo and yum to install items directly off the
# DVD ISO that we release.
#
# To use this repo, put in your DVD and use it with the other repos too:
# yum --enablerepo=c7-media [command]
#
# or for ONLY the media repo, do this:
#
# yum --disablerepo=\* --enablerepo=c7-media [command]

[c7-media]
name=CentOS-$releasever - Media
baseurl=file:///media/CentOS/
file:///media/cdrom/
file:///mnt # 本地位置
gpgcheck=1
enabled=1 # 启用[c7-media]
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

RPM仓库说明

在 CentOS 7 及之前的版本,yum 官方仓库一直都是 Base 库、Extras 库、Updates 库、centosplus 库等。其中 Base 库是安装 CentOS 时必须提供的仓库,它提供 CentOS 安装 (比如可以选择安装桌面环境、开发工具等)、运行以及一些常用用户空间程序。

在 CentOS 8 中发生了变化,原来的 base 库被拆分成两部分:AppStream 和 Base 库。安装 CentOS 8 时必须提供这两个库。

其中:

  • CentOS 8 的 Base 库提供安装和运行 CentOS 8 时必须的包,即 CentOS 核心包。这个仓库中全都是 rpm 包。
  • CentOS 8 的 AppStream 库提供常用用户空间程序,它们并不一定是安装和运行 CentOS 8 所必须的,比如 Python 包、Perl 包等语言包都在 AppStream。AppStream 中包含 rpm 包和 dnf 的模块。

AppStream 库中的包一般是用户空间程序包,这些程序的更新速度一般比 CentOS 系统更新快的多,将它们单独提取到 AppStream 库,意味着这些程序包和系统相关的包被解绑分开到两个仓库,这可以让系统包和常用程序包分开升级,有利于提供这些程序包的最新的版本。

使用过 CentOS 的人可能都会庆幸这种改变。最近这些年互联网的发展极为迅速,很多程序包的迭代速度也非常快,以前的 CentOS 版本中,很多程序的版本往往都非常古老,要升级这些程序包,只能单独配置它们的镜像仓库 (相当于是第三方仓库),甚至很多程序只能自己编译新版本。

在配置 CentOS 8 仓库时,还有一个 PowerTools 仓库很可能会用上,它主要用于提供:

  • 其他程序包的依赖包 (大量的 devel 包和 lib 包)
  • 那些语言的模块或包,比如 Perl-DataTime。这意味着,如果不用语言自身的包管理器 (比如 pip/gem/cpan/npm 等) 安装它们的模块,就需要启用 PowerTools 仓库后用 yum/dnf 来安装

配置 CentOS 8 的国内镜像仓库和之前 CentOS 版本倒没什么区别,只是要注意提供 AppStream 和可能要使用到的 PowerTools 仓库。

yum/dnf 语法帮助

不同的版本,yum命令可能功能上有所不同,例如在CentOS 7上的yum有--downloadonly的功能,而在CentOS 6.6上就没有(更新yum包后就有了)。

Main Commands

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
help         命令的帮助信息,用法:yum help command
clean 清除缓存数据,如yum clean all
makecache 生成元数据缓存数据,yum makecache
deplist 列出包的依赖关系
erase 卸载包
fs 为当前文件系统创建快照,或者列出或删除当前已有快照。
快照是非常有用的,升级或打补丁前拍个快照,就能放心地升级或打补丁了
fssnapshot 同fs一样
groups 操作包组
history 查看yum事务信息,yum是独占模式的进程,所以有时候查看事务信息还是有用的
info 输出包或包组的信息,例如该包是谁制作的,大概是干什么用的,来源于哪个包组等信息
install 包安装命令
list 列出包名,一般会结合grep来搜索包,如yum list all | grep -i zabbix
provides 搜索给定的内容是谁提供的,可用来搜索文件来源于哪个包,如
yum provides '*bin/mysql'可搜索mysql命令来源于何处
reinstall 重新安装包
repolist 列出可用的仓库列表
search 给定字符串搜索相关包,并给出相关包较为详细的信息
update 更新包

Plugin Commands

从8开始:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
builddep                  Install build dependencies for package or spec file
changelog Show changelog data of packages
config-manager manage yum configuration options and repositories
copr Interact with Copr repositories.
debug-dump dump information about installed rpm packages to file
debug-restore restore packages recorded in debug-dump file
debuginfo-install install debuginfo packages
download Download package to current directory
groups-manager create and edit groups metadata file
needs-restarting determine updated binaries that need restarting
offline-distrosync Prepare offline distrosync of the system
offline-upgrade Prepare offline upgrade of the system
playground Interact with Playground repository.
repoclosure Display a list of unresolved dependencies for repositories
repodiff List differences between two sets of repositories
repograph Output a full package dependency graph in dot format
repomanage Manage a directory of rpm packages
reposync download all packages from remote repo
system-upgrade Prepare system for upgrade to a new release

通用选项

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
Options:
-R [minutes], --randomwait=[minutes]:最多等待时间
-q, --quiet 安静模式
-v, --verbose 详细模式
-y, --assumeyes 对所有问题回答yes
--assumeno 对所有问题回答no
--enablerepo=[repo] 启用一个或多个仓库,可用通配符通配仓库ID
--disablerepo=[repo] 禁用一个或多个仓库,可用通配符通配仓库ID
-x [package], --exclude=[package] 通配要排除的包
--nogpgcheck 禁用gpgcheck
--color=COLOR 带颜色
--downloadonly 仅下载包,不安装或升级。默认下载在yum的缓存目录
/var/cache/yum/$basearch/$releasever
--downloaddir=DLDIR 指定下载目录


-c [config file], --config [config file]
config file location
-q, --quiet quiet operation
-v, --verbose verbose operation
--version show YUM version and exit
--installroot [path] set install root
--nodocs do not install documentations
--noplugins disable all plugins
--enableplugin [plugin]
enable plugins by name
--disableplugin [plugin]
disable plugins by name
--releasever RELEASEVER
override the value of $releasever in config and repo files
--setopt SETOPTS set arbitrary config and repo options
--skip-broken resolve depsolve problems by skipping packages
-h, --help, --help-cmd
show command help
--allowerasing allow erasing of installed packages to resolve dependencies
-b, --best try the best available package versions in transactions.
--nobest do not limit the transaction to the best candidate
-C, --cacheonly run entirely from system cache, don't update cache
-R [minutes], --randomwait [minutes]
maximum command wait time
-d [debug level], --debuglevel [debug level]
debugging output level
--debugsolver dumps detailed solving results into files
--showduplicates show duplicates, in repos, in list/search commands
-e ERRORLEVEL, --errorlevel ERRORLEVEL
error output level
--obsoletes enables yum's obsoletes processing logic for upgrade or display capabilities that the package obsoletes for info, list and repoquery
--rpmverbosity [debug level name]
debugging output level for rpm
-y, --assumeyes automatically answer yes for all questions
--assumeno automatically answer no for all questions
--enablerepo [repo] Temporarily enable repositories for the purpose of the current dnf command. Accepts an id, a comma-separated list of ids, or a glob of ids. This option can be
specified multiple times.
--disablerepo [repo] Temporarily disable active repositories for the purpose of the current dnf command. Accepts an id, a comma-separated list of ids, or a glob of ids. This option
can be specified multiple times, but is mutually exclusive with `--repo`.
--repo [repo], --repoid [repo]
enable just specific repositories by an id or a glob, can be specified multiple times
--enable enable repos with config-manager command (automatically saves)
--disable disable repos with config-manager command (automatically saves)
-x [package], --exclude [package], --excludepkgs [package]
exclude packages by name or glob
--disableexcludes [repo], --disableexcludepkgs [repo]
disable excludepkgs
--repofrompath [repo,path]
label and path to an additional repository to use (same path as in a baseurl), can be specified multiple times.
--noautoremove disable removal of dependencies that are no longer used
--nogpgcheck disable gpg signature checking (if RPM policy allows)
--color COLOR control whether color is used
--refresh set metadata as expired before running the command
-4 resolve to IPv4 addresses only
-6 resolve to IPv6 addresses only
--destdir DESTDIR, --downloaddir DESTDIR
set directory to copy packages to
--downloadonly only download packages
--comment COMMENT add a comment to transaction
--bugfix Include bugfix relevant packages, in updates
--enhancement Include enhancement relevant packages, in updates
--newpackage Include newpackage relevant packages, in updates
--security Include security relevant packages, in updates
--advisory ADVISORY, --advisories ADVISORY
Include packages needed to fix the given advisory, in updates
--bz BUGZILLA, --bzs BUGZILLA
Include packages needed to fix the given BZ, in updates
--cve CVES, --cves CVES
Include packages needed to fix the given CVE, in updates
--sec-severity {Critical,Important,Moderate,Low}, --secseverity {Critical,Important,Moderate,Low}
Include security relevant packages matching the severity, in updates
--forcearch ARCH Force the use of an architecture

[disable|enable]repo

1
2
3
4
5
# 仅使用指定的repo,--disablerepo也可以不用指定
yum --disablerepo=\* --enablerepo=c7-media [command]

yum --disablerepo="*" --enablerepo=c7-media install vim

/etc/yum.conf

/etc/yum.conf是yum的默认文件,里面配置的也是全局默认项。

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@server2 ~]# cat /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever # 缓存目录
keepcache=0 # 是否保留缓存,设置为1时,安装包时所下载的包将不会被删除
debuglevel=2 # 调试信息的级别
logfile=/var/log/yum.log # 日志文件位置
exactarch=1 # 设置为1将只会安装和系统架构完全匹配的包
obsoletes=1 # 是否允许更新旧的包
gpgcheck=1 # 是否要进行gpg check
plugins=1 # 是否允许使用yum插件
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 # 指定基准包,yum会根据这个包判断发行版本

yum check

Check for problems in the rpmdb

rpm数据库

1
rpm --rebuilddb

yum check-update

check for available package upgrades

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@vagrant ~]# yum check-update
Last metadata expiration check: 4:52:10 ago on Fri 07 Jun 2024 04:48:06 AM CST.

NetworkManager.x86_64 1:1.46.0-4.0.1.el9_4 ol9_baseos_latest
NetworkManager-libnm.x86_64 1:1.46.0-4.0.1.el9_4 ol9_baseos_latest
NetworkManager-team.x86_64 1:1.46.0-4.0.1.el9_4 ol9_baseos_latest
NetworkManager-tui.x86_64 1:1.46.0-4.0.1.el9_4 ol9_baseos_latest
VirtualBox-7.0.x86_64 7.0.18_162988_el9-1 virtualbox
acl.x86_64 2.3.1-4.el9 ol9_baseos_latest
alsa-lib.x86_64 1.2.10-2.el9 ol9_appstream
annobin.x86_64 12.31-2.el9 ol9_appstream
audit.x86_64 3.1.2-2.el9 ol9_baseos_latest
audit-libs.x86_64 3.1.2-2.el9 ol9_baseos_latest
avahi-libs.x86_64 0.8-20.el9 ol9_baseos_latest
bash.x86_64 5.1.8-9.el9 ol9_baseos_latest
...

以第一行为例

1
bash.x86_64                          5.1.8-9.el9                       ol9_baseos_latest
  • 包名称:bash

  • 架构:x86_64

  • 即将安装包的版本:5.1.8

    1
    2
    3
    4
    5
    6
    # 例如当前bash版本为
    [root@vagrant ~]# bash --version
    bash --version
    GNU bash, version 5.1.8(1)-release (x86_64-redhat-linux-gnu)
    Copyright (C) 2020 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
  • 更新包的发布版本:9.el9

  • 更新包所在的仓库:ol9_baseos_latest

yum clean

Remove cached data

1
yum clean all

yum deplist

查看依赖包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
[root@docker2 ~]# dnf deplist vim-enhanced.x86_64
Last metadata expiration check: 1:09:13 ago on Fri 07 Jun 2024 10:07:49 AM CST.
package: vim-enhanced-2:8.2.2637-20.el9_1.x86_64
dependency: /usr/bin/sh
provider: bash-5.1.8-9.el9.x86_64
dependency: libacl.so.1()(64bit)
provider: libacl-2.3.1-4.el9.x86_64
dependency: libacl.so.1(ACL_1.0)(64bit)
provider: libacl-2.3.1-4.el9.x86_64
dependency: libc.so.6(GLIBC_2.34)(64bit)
provider: glibc-2.34-100.el9_4.2.x86_64
dependency: libgpm.so.2()(64bit)
provider: gpm-libs-1.20.7-29.el9.x86_64
dependency: libm.so.6()(64bit)
provider: glibc-2.34-100.el9_4.2.x86_64
dependency: libm.so.6(GLIBC_2.2.5)(64bit)
provider: glibc-2.34-100.el9_4.2.x86_64
dependency: libm.so.6(GLIBC_2.29)(64bit)
provider: glibc-2.34-100.el9_4.2.x86_64
dependency: libselinux.so.1()(64bit)
provider: libselinux-3.6-1.el9.x86_64
dependency: libselinux.so.1(LIBSELINUX_1.0)(64bit)
provider: libselinux-3.6-1.el9.x86_64
dependency: libtinfo.so.6()(64bit)
provider: ncurses-libs-6.2-10.20210508.el9.x86_64
dependency: rtld(GNU_HASH)
provider: glibc-2.34-100.el9_4.2.x86_64
provider: glibc-2.34-100.el9_4.2.i686
dependency: vim-common = 2:8.2.2637-20.el9_1
provider: vim-common-2:8.2.2637-20.el9_1.x86_64
dependency: which
provider: which-2.21-29.el9.x86_64
[root@docker2 ~]#

yum-config-manager

  • 该工具来自yum-utilsdnf-utils

  • yum-config-manager可用来配置repo文件

用法示例

1
2
3
4
5
6
7
8
9
10
# 启用禁用repo
yum-config-manager --enable repoid
yum-config-manager --disable repoid

# 创建repo
yum-config-manager --add-repo ”http://xx/”
# 就是新添加一个repo并启用,此外自动生成一个以url为名称的repo文件

# dnf
dnf config-manager --set-enabled powertools

yum makecache

1
2
3
4
5
yum makecache fast
# 定期更新缓存,则需要安装yum-cron

# dnf
dnf makecache

yum downgrade

降级软件包.

当包没有任何依赖关系时,降级是非常简单的。否则yum不会解决依赖关系,需要手动解决

1
yum downgrade package_name

yum查询

1
2
3
4
5
6
yum list|search|info|provides

yum list pkg_name*
yum list | grep pkg_name*
yum provides cmd
yum search string

yum list

yum list列出当前系统中已经安装的和当前系统已启用的仓库中提供的可用软件包

list子命令

  • installed:列出已安装的软件包
  • available:列出可用的软件包
  • updates:列出可更新的软件包
  • extras:列出当前系统中已安装,但在仓库中没有的软件包
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 列出所有版本
yum list nginx --showduplicates

# 模糊查询
yum list vim*

# 注意:list后面只能使用通配符*,如果想使用其他操作符,则请使用管道配合grep,例如,查找以bind开头的:
yum list | grep ‘^bind

# 列出所有可获取的包(包括已安装和未安装),下面等价
dnf list # 默认--all选项
dnf list --all

# 分别列出已安装和未安装的包
dnf list --installed
dnf list --available

# 列出可升级的包,等价
dnf list --updates
dnf list --upgrades
dnf check-updates

# 列出可被移除(已不再被依赖)的包
dnf list --autoremove

依据包名称,概要信息,关键字进行查询。

1
2
3
4
5
6
7
8
9
10
[root@docker2 ~]# yum search
usage: yum search [-c [config file]] [-q] [-v] [--version] [--installroot [path]] [--nodocs] [--noplugins] [--enableplugin [plugin]] [--disableplugin [plugin]]
[--releasever RELEASEVER] [--setopt SETOPTS] [--skip-broken] [-h] [--allowerasing] [-b | --nobest] [-C] [-R [minutes]] [-d [debug level]]
[--debugsolver] [--showduplicates] [-e ERRORLEVEL] [--obsoletes] [--rpmverbosity [debug level name]] [-y] [--assumeno] [--enablerepo [repo]]
[--disablerepo [repo] | --repo [repo]] [--enable | --disable] [-x [package]] [--disableexcludes [repo]] [--repofrompath [repo,path]]
[--noautoremove] [--nogpgcheck] [--color COLOR] [--refresh] [-4] [-6] [--destdir DESTDIR] [--downloadonly] [--comment COMMENT] [--bugfix]
[--enhancement] [--newpackage] [--security] [--advisory ADVISORY] [--bz BUGZILLA] [--cve CVES] [--sec-severity {Critical,Important,Moderate,Low}]
[--forcearch ARCH] [--all]
KEYWORD [KEYWORD ...]
yum search: error: the following arguments are required: KEYWORD

示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 查找指定关键字的rpm包
[root@docker2 ~]# yum search openssl
Last metadata expiration check: 22:13:44 ago on Tue 04 Jun 2024 06:57:20 PM CST.
============================================================================== Name Exactly Matched: openssl ==============================================================================
openssl.x86_64 : Utilities from the general purpose cryptography library with TLS implementation
============================================================================= Name & Summary Matched: openssl =============================================================================
apr-util-openssl.x86_64 : APR utility library OpenSSL crypto support
openssl-devel.x86_64 : Files for development of applications which will use OpenSSL
openssl-devel.i686 : Files for development of applications which will use OpenSSL
openssl-fips-provider.i686 : FIPS module for OpenSSL
openssl-fips-provider.x86_64 : FIPS module for OpenSSL
openssl-perl.x86_64 : Perl scripts provided with OpenSSL
openssl-pkcs11.x86_64 : A PKCS#11 engine for use with OpenSSL
openssl-pkcs11.i686 : A PKCS#11 engine for use with OpenSSL
perl-Crypt-OpenSSL-Bignum.x86_64 : Perl interface to OpenSSL for Bignum
perl-Crypt-OpenSSL-RSA.x86_64 : Perl interface to OpenSSL for RSA
perl-Crypt-OpenSSL-Random.x86_64 : OpenSSL/LibreSSL pseudo-random number generator access
rsyslog-openssl.x86_64 : TLS protocol support for rsyslog via OpenSSL library
xmlsec1-openssl.x86_64 : OpenSSL crypto plugin for XML Security Library
xmlsec1-openssl.i686 : OpenSSL crypto plugin for XML Security Library
================================================================================== Name Matched: openssl ==================================================================================
compat-openssl11.i686 : Utilities from the general purpose cryptography library with TLS implementation
compat-openssl11.x86_64 : Utilities from the general purpose cryptography library with TLS implementation
openssl-libs.x86_64 : A general purpose cryptography library with TLS implementation
openssl-libs.i686 : A general purpose cryptography library with TLS implementation
================================================================================ Summary Matched: openssl =================================================================================
perl-Net-SSLeay.x86_64 : Perl extension for using OpenSSL
qatengine.x86_64 : Intel QuickAssist Technology (QAT) OpenSSL Engine
[root@docker2 ~]#

# 在指定的repo中查找
yum search --repo epel gcc

如上所示,我们查找有关openssl关键字的包,其给出了4种结果:

  1. rpm包名称和关键字openssl完全匹配的==>Name Exactly Matched
  2. rpm包名称或概要中包含openssl关键字的==>Name & Summary Matched
  3. rpm包名称中包含openssl关键字的==>Name Matched
  4. rpm包概要信息中包含openssl关键字的==>Summary Matched

yum info

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
[root@vagrant ~]# yum info openssl
Last metadata expiration check: 4:41:31 ago on Fri 07 Jun 2024 04:48:06 AM CST.
Installed Packages # 已安装的
Name : openssl
Epoch : 1
Version : 3.0.7
Release : 24.0.1.el9
Architecture : x86_64
Size : 1.8 M
Source : openssl-3.0.7-24.0.1.el9.src.rpm
Repository : @System
From repo : anaconda
Summary : Utilities from the general purpose cryptography library with TLS implementation
URL : http://www.openssl.org/
License : ASL 2.0
Description : The OpenSSL toolkit provides support for secure communications between
: machines. OpenSSL includes a certificate management tool and shared
: libraries which provide various cryptographic algorithms and
: protocols.

Available Packages # 可用的
Name : openssl
Epoch : 1
Version : 3.0.7
Release : 27.0.3.el9
Architecture : x86_64
Size : 1.3 M
Source : openssl-3.0.7-27.0.3.el9.src.rpm
Repository : ol9_baseos_latest
Summary : Utilities from the general purpose cryptography library with TLS implementation
URL : http://www.openssl.org/
License : ASL 2.0
Description : The OpenSSL toolkit provides support for secure communications between
: machines. OpenSSL includes a certificate management tool and shared
: libraries which provide various cryptographic algorithms and
: protocols.

Name : openssl
Epoch : 1
Version : 3.0.7
Release : 27.0.3.el9
Architecture : src
Size : 15 M
Source : None
Repository : ol9_appstream
Summary : Utilities from the general purpose cryptography library with TLS implementation
URL : http://www.openssl.org/
License : ASL 2.0
Description : The OpenSSL toolkit provides support for secure communications between
: machines. OpenSSL includes a certificate management tool and shared
: libraries which provide various cryptographic algorithms and
: protocols.

Name : openssl
Epoch : 1
Version : 3.0.7
Release : 27.0.3.el9
Architecture : src
Size : 15 M
Source : None
Repository : ol9_baseos_latest
Summary : Utilities from the general purpose cryptography library with TLS implementation
URL : http://www.openssl.org/
License : ASL 2.0
Description : The OpenSSL toolkit provides support for secure communications between
: machines. OpenSSL includes a certificate management tool and shared
: libraries which provide various cryptographic algorithms and
: protocols.

yum provides

1
yum provides ip

dnf repoquery

1
2
3
4
5
6
7
# 只依据包名称查询
[root@vagrant ~]# dnf repoquery 'net*tools'
Last metadata expiration check: 1:57:36 ago on Fri 07 Jun 2024 09:42:12 AM CST.
net-tools-0:2.0-0.62.20160912git.el9.src
net-tools-0:2.0-0.62.20160912git.el9.x86_64
netlabel_tools-0:0.30.0-13.el9.src
netlabel_tools-0:0.30.0-13.el9.x86_64

yum repolist

1
2
3
4
5
6
7
8
9
# 列出已启用(enabled=1)、已禁用或所有已配置仓库
dnf repolist
dnf repolist --enabled
dnf repolist --disabled
dnf repolist --all

# 查看某个或所有仓库的详细信息
dnf repolist -v
dnf repolist BaseOS -v

yum clean

1
2
3
4
5
6
7
8
9
10
11
# 清除缓存中rpm头文件
yum clean headers

# 清除缓存中旧的rpm头文件
yum clean oldheaders

# 清除缓存目录下的rpm包
yum clean packages

# 清除暂存中旧的rpm头文件和包文件
yum clean all

yum update

直接更新整个系统

yum group

组就是针对特定目的而一起安装的相关软件的集合。在RHEL8中,有两种类型的组:

  1. 常规组:软件包的集合
  2. 环境组:环境组是常规组的集合。

一个组提供的软件包或组可能为

  • mandatory(安装该组时必须安装)
  • default(安装该组时通常不会安装)
  • optional(安装该组时不予安装,除非特别要求)

RHEL7开始,yum group的行为有所改变。在RHEL7及其更高版本中,group被视为对象,受到系统跟踪,如果已安装的组有了更新,并通过yum存储库添加了新的mandatorydefault软件包,则更新时将安装这些新的软件包。

RHEL6及其更早版本中,如果group满足以下任何条件,则被视为已经安装:

  1. 该组的所有必选软件已经安装
  2. 该组没有任何必选软件包
  3. 安装了该组中的任何默认或可选软件包

RHEL7开始,只有使用yum groupinstall安装了某个组,该组才会被视为已经安装。yum group mark install GROUPName可用于将某个组标记为已安装,下次更新时将安装任何缺少的软件包和依赖项。

此外,RHEL6及其之前的版本只有yum grouplist这种命令,没有yum group list这种形式的命令

yum group list

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
[root@vagrant ~]# dnf group list installed
Last metadata expiration check: 4:25:23 ago on Fri 07 Jun 2024 04:48:06 AM CST.
Installed Environment Groups:
Minimal Install
[root@vagrant ~]# dnf grouplist installed
Last metadata expiration check: 4:25:57 ago on Fri 07 Jun 2024 04:48:06 AM CST.
Installed Environment Groups:
Minimal Install

# 列出所有组
[root@vagrant ~]# dnf grouplist
Last metadata expiration check: 4:28:40 ago on Fri 07 Jun 2024 04:48:06 AM CST.
Available Environment Groups:
Server with GUI
Server
Workstation
Custom Operating System
Virtualization Host
Installed Environment Groups:
Minimal Install
Available Groups:
Legacy UNIX Compatibility
Console Internet Tools
Container Management
Development Tools
.NET Development
Graphical Administration Tools
Headless Management
Network Servers
RPM Development Tools
Scientific Support
Security Tools
Smart Card Support
System Tools

如上两种写法都可以。

1
2
3
4
5
6
7
8
9
10
# 列出隐藏组
# 有些组一般通过环境组安装,默认为隐藏
[root@vagrant ~]# dnf grouplist hidden installed
Last metadata expiration check: 4:27:11 ago on Fri 07 Jun 2024 04:48:06 AM CST.
Installed Environment Groups:
Minimal Install
Installed Groups:
Core
VMware platform specific packages
[root@vagrant ~]#

yum group info

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 显示组相关信息,会列出必选,默认,可选软件包名称:
[root@vagrant ~]# dnf groupinfo 'Development Tools'
Last metadata expiration check: 4:30:39 ago on Fri 07 Jun 2024 04:48:06 AM CST.
Group: Development Tools
Description: A basic development environment.
Mandatory Packages: # 必要
autoconf
automake
...
rpm-sign
strace
Default Packages: # 默认
asciidoc
byacc
diffstat
git
intltool
...
systemtap
valgrind
valgrind-devel
Optional Packages: # 可选
cmake
dtrace
expect
rpmdevtools
rpmlint

yum group install

安装一个组,同时安装组中必选的软件包和默认的软件包以及它们依赖的软件包

1
yum groupinstall "group1"[,"group2"]

注意:正常情况下会自动帮你安装好必要软件包和默认软件包,但如果某个组里面的软件都是可选的,在这种情况下,该组中的软件默认都不会安装,此时你指定手动一个个安装组中的软件,或更改/etc/yum.conf的默认行为:

1
2
# 7/8版本默认都没有此设置
group_package_types=default,mandatory,optional

yum group remove

yum group remove用于删除组中的所有包,与groupinstall不同,这将删除所有内容而不管group_package_types。 值得指出的是,软件包可以位于多个组中,因此group install X Y+group remove Y不会和group install X的结果相等。

groupremove_leaf_only 配置将此命令的行为更改为仅删除不需要的包 别的东西。

yum history

所有安装和删除事务的日志都记录在

1
/var/log/dnf.rpm.log

yum history 显示安装和删除事务的摘要信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[root@docker1 ~]# yum history
Loaded plugins: fastestmirror
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
ID | Command line | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------
28 | install trzsz | 2024-03-05 10:59 | Install | 1 <
27 | install ntp | 2024-01-25 11:27 | Install | 3 >
26 | install xorg-x11-apps.x8 | 2023-12-29 15:25 | Install | 18
25 | install zabbix-agent2 za | 2023-11-25 21:27 | Install | 4 <
24 | install lrzsz | 2023-07-15 10:08 | Install | 1 >
23 | install -y perf | 2023-07-03 12:39 | Install | 2
22 | install -y pv-1.4.6-1.el | 2023-06-30 23:50 | Install | 1
21 | install libcgroup-tools | 2023-06-09 13:09 | Install | 1
20 | --enablerepo=elrepo-kern | 2023-06-01 16:36 | Install | 1
19 | install https://www.elre | 2023-06-01 16:18 | Install | 1
18 | install net-snmp net-snm | 2023-05-29 16:46 | Install | 5
17 | install -y git | 2023-05-22 11:25 | Install | 5
16 | install -y lsof | 2023-05-09 21:34 | Install | 1
15 | install dstat -y | 2023-01-18 20:04 | Install | 1 <
14 | install -y kmod-oracleas | 2022-09-27 09:18 | Install | 1 >
13 | remove -y php72w php72w- | 2022-09-19 10:05 | Erase | 12
12 | remove httpd | 2022-09-19 10:04 | Erase | 1
11 | install -y php72w php72w | 2022-09-19 09:58 | Install | 22
10 | -y install httpd | 2022-09-19 09:56 | Install | 5 <
9 | install -y tmux | 2022-09-06 23:34 | Install | 2 >
history list
[root@docker1 ~]#

yum history undo可以撤销事务

yum remove

1
2
3
yum remove packagename

#

dnf autoremove

1
2
# 自动移除已经不被依赖的包
dnf autoremove

yum install

1
2
3
4
5
6
7
8
9
10
11
12
# 下载而不安装
yum install httpd --downloadonly --downloaddir=/data/packages

# 指定安装位置
yum install nginx --installroot=/opt

# 安装多个包
yum install p1 p2 p3 ...

# 根据文件名安装(dnf有而以前yum没有但好用的功能)
dnf install /usr/bin/netstat
dnf install $(which netstat)

yum download

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# 查询依赖包
[root@vagrant ~]# dnf deplist vim-enhanced-2:8.2.2637-20.0.1.el9_1
Last metadata expiration check: 0:54:47 ago on Fri 07 Jun 2024 12:52:57 PM CST.
package: vim-enhanced-2:8.2.2637-20.0.1.el9_1.x86_64
dependency: /usr/bin/sh
provider: bash-5.1.8-9.el9.x86_64
dependency: libacl.so.1()(64bit)
provider: libacl-2.3.1-4.el9.x86_64
dependency: libacl.so.1(ACL_1.0)(64bit)
provider: libacl-2.3.1-4.el9.x86_64
dependency: libc.so.6(GLIBC_2.34)(64bit)
provider: glibc-2.34-100.0.1.el9_4.2.x86_64
dependency: libgpm.so.2()(64bit)
provider: gpm-libs-1.20.7-29.el9.x86_64
dependency: libm.so.6()(64bit)
provider: glibc-2.34-100.0.1.el9_4.2.x86_64
dependency: libm.so.6(GLIBC_2.2.5)(64bit)
provider: glibc-2.34-100.0.1.el9_4.2.x86_64
dependency: libm.so.6(GLIBC_2.29)(64bit)
provider: glibc-2.34-100.0.1.el9_4.2.x86_64
dependency: libselinux.so.1()(64bit)
provider: libselinux-3.6-1.el9.x86_64
dependency: libselinux.so.1(LIBSELINUX_1.0)(64bit)
provider: libselinux-3.6-1.el9.x86_64
dependency: libtinfo.so.6()(64bit)
provider: ncurses-libs-6.2-10.20210508.el9.x86_64
dependency: rtld(GNU_HASH)
provider: glibc-2.34-100.0.1.el9_4.2.i686
provider: glibc-2.34-100.0.1.el9_4.2.x86_64
dependency: vim-common = 2:8.2.2637-20.0.1.el9_1
provider: vim-common-2:8.2.2637-20.0.1.el9_1.x86_64
dependency: which
provider: which-2.21-29.el9.src
provider: which-2.21-29.el9.x86_64

# 方法1:repotrack
# --resolve 解析依赖
# --alldeps 下载所有依赖
yum install yum-utils -y
repotrack vim-enhanced.x86_64 --download_path=/root/rpm/ # RHEL7
[root@vagrant ~]# repotrack vim-enhanced-2:8.2.2637-20.0.1.el9_1 --resolve --alldeps --downloadonly --destdir=/root/rpm/ # RHEL8
Last metadata expiration check: 1:18:39 ago on Fri 07 Jun 2024 12:52:57 PM CST.
(1/25): vim-enhanced-8.2.2637-20.0.1.el9_1.x86_64.rpm 833 kB/s | 1.7 MB 00:02
(2/25): ncurses-base-6.2-10.20210508.el9.noarch.rpm 890 kB/s | 212 kB 00:00
(3/25): ncurses-libs-6.2-10.20210508.el9.x86_64.rpm 1.3 MB/s | 332 kB 00:00
(4/25): libattr-2.5.1-3.el9.x86_64.rpm 88 kB/s | 19 kB 00:00
(5/25): libgcc-11.4.1-3.0.1.el9.x86_64.rpm 447 kB/s | 98 kB 00:00
(6/25): redhat-release-9.4-0.4.0.1.el9.x86_64.rpm 95 kB/s | 19 kB 00:00
(7/25): filesystem-3.16-2.el9.x86_64.rpm 3.3 MB/s | 1.1 MB 00:00
(8/25): vim-common-8.2.2637-20.0.1.el9_1.x86_64.rpm 2.1 MB/s | 8.4 MB 00:03
(9/25): glibc-common-2.34-100.0.1.el9_4.2.x86_64.rpm 1.0 MB/s | 328 kB 00:00
(10/25): glibc-gconv-extra-2.34-100.0.1.el9_4.2.x86_64.rpm 4.6 MB/s | 1.8 MB 00:00
(11/25): basesystem-11-13.el9.noarch.rpm 38 kB/s | 7.4 kB 00:00
(12/25): tzdata-2024a-1.el9.noarch.rpm 479 kB/s | 2.2 MB 00:04
(13/25): libselinux-3.6-1.el9.x86_64.rpm 397 kB/s | 85 kB 00:00
(14/25): oraclelinux-release-9.4-1.0.6.el9.x86_64.rpm 8.2 MB/s | 8.3 MB 00:01
(15/25): vim-filesystem-8.2.2637-20.0.1.el9_1.noarch.rpm 64 kB/s | 13 kB 00:00
(16/25): gpm-libs-1.20.7-29.el9.x86_64.rpm 114 kB/s | 21 kB 00:00
(17/25): setup-2.13.7-10.el9.noarch.rpm 735 kB/s | 175 kB 00:00
(18/25): glibc-minimal-langpack-2.34-100.0.1.el9_4.2.x86_64.rpm 132 kB/s | 25 kB 00:00
(19/25): which-2.21-29.el9.x86_64.rpm 197 kB/s | 51 kB 00:00
(20/25): libsepol-3.6-1.el9.x86_64.rpm 1.5 MB/s | 329 kB 00:00
(21/25): libacl-2.3.1-4.el9.x86_64.rpm 89 kB/s | 22 kB 00:00
(22/25): pcre2-10.40-5.0.1.el9.x86_64.rpm 1.1 MB/s | 234 kB 00:00
(23/25): bash-5.1.8-9.el9.x86_64.rpm 1.5 MB/s | 1.8 MB 00:01
(24/25): pcre2-syntax-10.40-5.0.1.el9.noarch.rpm 591 kB/s | 155 kB 00:00
(25/25): glibc-2.34-100.0.1.el9_4.2.x86_64.rpm 5.0 MB/s | 2.0 MB 00:00
[root@vagrant ~]# ll rpm/ | wc -l
26
[root@vagrant ~]# dnf localinstall rpm/*.rpm

# 方法2:yumdownloader
# –destdir:指定 rpm 包下载目录(不指定时,默认为当前目录)
# –resolve:下载依赖的 rpm 包。
# 仅会下载没有安装的软件和依赖
yum install yum-utils -y
yumdownloader --resolve --destdir=/tmp package_name

# 方法3:downloadonly选项
# 与 yumdownloader 命令一样,也是仅会将主软件包和基于你现在的操作系统所缺少的依赖关系包一并下载。
# 意思也就是说,如果你要下载vim,如果系统已经安装了vim,则无法下载,如果系统中已经安装了部分依赖,则仅下载尚未安装的那些
# 你可以通过yum mark手动将软件包标记为已安装还是未安装
# rhel7
yum install httpd --downloadonly --downloaddir=/data/packages
# rhel8
--destdir DESTDIR, --downloaddir DESTDIR
set directory to copy packages to
--downloadonly only download packages

# 方法4:download插件指令,RHEL8自带,下载到当前目录,并且不下载依赖
[root@vagrant ~]# dnf download vim-enhanced-2:8.2.2637-20.0.1.el9_1 --destdir=/root/rpm
Last metadata expiration check: 0:56:03 ago on Fri 07 Jun 2024 12:52:57 PM CST.
vim-enhanced-8.2.2637-20.0.1.el9_1.x86_64.rpm 1.1 MB/s | 1.7 MB 00:01
[root@vagrant ~]# ll /root/rpm/
total 1792
-rw-r--r--. 1 root root 1834831 Jun 7 13:49 vim-enhanced-8.2.2637-20.0.1.el9_1.x86_64.rpm

yum localinstall

安装本地的rpm包

1
2
3
4
yum localinstall p1 p2 p3 ...

# 解决本地依赖
yum localinstall *.rpm --disablerepo=*

yum [update|upgrade]

yum -y update:升级所有包同时,也升级软件和系统内核;
yum -y upgrade:只升级所有包,不升级软件和系统内核,软件和内核保持原样。

updateupgrade的描述,不是非常准确.

通过check-update选项,可以了解系统中哪些已安装的包当前有更新,如下所示,这些包存在可用的更新,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@vagrant ~]# yum check-update
Last metadata expiration check: 4:52:10 ago on Fri 07 Jun 2024 04:48:06 AM CST.

NetworkManager.x86_64 1:1.46.0-4.0.1.el9_4 ol9_baseos_latest
NetworkManager-libnm.x86_64 1:1.46.0-4.0.1.el9_4 ol9_baseos_latest
NetworkManager-team.x86_64 1:1.46.0-4.0.1.el9_4 ol9_baseos_latest
NetworkManager-tui.x86_64 1:1.46.0-4.0.1.el9_4 ol9_baseos_latest
VirtualBox-7.0.x86_64 7.0.18_162988_el9-1 virtualbox
acl.x86_64 2.3.1-4.el9 ol9_baseos_latest
alsa-lib.x86_64 1.2.10-2.el9 ol9_appstream
annobin.x86_64 12.31-2.el9 ol9_appstream
audit.x86_64 3.1.2-2.el9 ol9_baseos_latest
audit-libs.x86_64 3.1.2-2.el9 ol9_baseos_latest
avahi-libs.x86_64 0.8-20.el9 ol9_baseos_latest
bash.x86_64 5.1.8-9.el9 ol9_baseos_latest
...

以第一行为例

1
bash.x86_64                          5.1.8-9.el9                       ol9_baseos_latest
  • 包名称:bash

  • 架构:x86_64

  • 即将安装包的版本:5.1.8

    1
    2
    3
    4
    5
    6
    # 例如当前bash版本为
    [root@vagrant ~]# bash --version
    bash --version
    GNU bash, version 5.1.8(1)-release (x86_64-redhat-linux-gnu)
    Copyright (C) 2020 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
  • 更新包的发布版本:9.el9

  • 更新包所在的仓库:ol9_baseos_latest

再说一点yumrpm的区别,就是无论使用yum update还是yum upgrade都会安装新的内核。当使用rpm的时候,-u选项会替换当前的内核,-i才会安装一个新内核。

yum upgrade,等价于打开obsoletes配置的yum update。而默认中/etc/yum.conf配置文件obsoletes是打开的,==因此这两个指令默认情况下是等价的==。

这是一个yum缓存配置文件的示例,obsoletes定义了更新时处理软件包的取代关系,简单来讲,1表示更新旧的rpm包的同时会删除旧包,0表示更新的时候不会删除旧包,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[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=3


[comments abridged]


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

因此,yum updateyum upgrade的功能都是一样的,都是将需要更新的软件包,更新到repo中的最新版。唯一不同的是,yum upgrade会删除旧版本的软件包,而yum update则会保留(obsoletes=0)。

生产环境中建议使用yum update,防止因为替换,导致旧的软件包依赖出现问题。

yum update

1
2
3
4
5
6
7
8
9
10
# 安装指定软件包的新版本,该过程尝试适当保留配置文件,但某些情况下,如果打包商认为旧版本在更新后无法使用,则可能对其进行重命名。
yum update packagename

# 如果不指定packagename,则安装所有相关更新,升级系统版本,并且也会升级内核,重启后生效。
yum update

# 由于新内核只有通过启动到内核才能进行测试,针对内核软件包进行了特殊设计,以便一次能够安装多个版本。
# 如果新内核启动失败,则依然可以使用旧的内核。使用yum update kernel实际上是安装新的内核。
# 配置文件中保存了一份软件包列表,即使在管理员要求更新时也始终安装这些软件包。
yum update kernel

yum upgrade

1
2
# 只升级所有包,不升级软件和系统内核,软件和内核保持原样。
yum upgrade == yum –obsoletes update

yum distro-sync

  • RHEL7:yum distribution-synchronization
  • RHEL8:dnf distro-sync

将已安装的软件包同步到最新可用版本,会更新内核,但保留旧版本内核。

1
2
dnf distro-sync # 完成后重启,确定没问题
dnf upgrade # 再执行upgrade会自动删除旧版本内核

dnf upgrade-minimal

1
2
# 最小化升级,只升级check-updates中最后列出的obsolete类型的包
yum upgrade-minimal

yum 模块流

概念

在RHEL7之前的版本,没有模块流的概念。

流–>上游软件提供商一旦发布,更新软件–>下游的用户可以快速使用。

模块流就是区别于普通软件包的一种,快速提供软件包版本的方法。

在RHEL8.0引入应用流(AppStream)概念,可同时提供发行版附随的多个版本的用户空间组件。它们可能比核心系统软件包更新的更频繁。

想象一种场景:开发人员需要最新版本的应用,管理员希望获得最稳定版本的应用,这会造成一种难以管理的局面。RHEL8运用一种称为模块流的技术简化此过程。==模块化允许单个存储库承载应用软件及其依赖项的多个版本==。

RHEL8内容通过两个主要的存储库分发:

  • BaseOS

    BaseOS repo以RPM软件包的形式为RHEL提供核心系统内容,BaseOS组件的生命周期与之前RHEL发行版中的内容相同。

  • AppStream

    AppStream repo提供具有不同生命周期的内容,作为模块和传统软件包。应用流包含系统的必要部分,以及以前作为红帽软件集合的一部分以及其他产品和程序提供的各种应用。

    AppStream repo包含两种类型的内容:

    1. 模块:模块描述了属于一个整体的一组RPM软件包;模块可以包含多个流,使多个版本的应用可供安装使用。启用模块流之后,系统能够访问该模块流中的RPM包
    2. 传统的RPM软件包

模块

模块是一组属于一个整体的,协调一致的RPM软件包。通常,这是围绕应用软件或编程语言的特定版本进行组织的。

典型的模块可包含应用的软件包,应用特定依赖库的软件包,应用文档的软件包,以及帮助工具的软件包。

可以将其理解为docker,一组特定的环境。

模块流

每个模块可以具有一个或多个模块流,其包含不同版本的内容。每个流独立接收更新。模块流可视为AppStream物理存储库中的虚拟存储库。

对于每个模块,只能启用其中一个流并提供它的软件包。

模块配置文件

每个模块可以有一个或多个配置文件。配置文件是要为特定用例一起安装的某些软件包的列表,这些用例包括服务器,客户端,开发或最小安装等。

安装特定的模块配置文件只是从模块流安装一组特定的软件包。可以随后正常安装或卸载软件包。如果没有指定配置文件,则模块将安装它的默认配置文件。

yum module

yum module选项

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Module command-specific options:
--enabled show only enabled modules
--disabled show only disabled modules
--installed show only installed modules or packages
--profile show profile content
--available show only available packages
--all remove all modular packages

<modular command> disable: disable a module with all its streams
enable: enable a module stream
info: print detailed information about a module
install: install a module profile including its packages
list: list all module streams, profiles and states
provides: list modular packages
remove: remove installed module profiles and their packages
repoquery: list packages belonging to a module
reset: reset a module
switch-to: switch a module to a stream and distrosync rpm packages
update: update packages associated with an active stream
module-spec Module specification

yum module list

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 列出可用模块列表
[root@vagrant ~]# yum module list
Last metadata expiration check: 0:26:57 ago on Fri 07 Jun 2024 09:42:12 AM CST.
Oracle Linux 9 Application Stream Packages (x86_64)
Name Stream Profiles Summary
mariadb 10.11 client, galera, server [d] MariaDB Module
maven 3.8 common [d] Java project management and project comprehension tool
nginx 1.22 common [d] nginx webserver
nginx 1.24 common [d] nginx webserver
nodejs 18 common [d], development, minimal, s2i Javascript runtime
nodejs 20 common [d], development, minimal, s2i Javascript runtime
php 8.1 common [d], devel, minimal PHP scripting language
php 8.2 common [d], devel, minimal PHP scripting language
postgresql 15 client, server [d] PostgreSQL server and client module
postgresql 16 client, server [d] PostgreSQL server and client module
redis 7 common [d] Redis persistent key-value database
ruby 3.1 common [d] An interpreter of object-oriented scripting language
ruby 3.3 common [d] An interpreter of object-oriented scripting language

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

[root@vagrant ~]# yum module list postgresql
Last metadata expiration check: 0:23:26 ago on Fri 07 Jun 2024 09:42:12 AM CST.
Oracle Linux 9 Application Stream Packages (x86_64)
Name Stream Profiles Summary
postgresql 15[d][e] client, server [d] PostgreSQL server and client module
postgresql 16 client, server [d] PostgreSQL server and client module

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
[root@vagrant ~]#
  • name:模块名称

  • stream:模块流的版本,后[d]表示默认版本,[e]表示启用

  • profiles:模块配置文件,[d]表示默认的配置文件

  • summary:描述

yum module info

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# 查看模块详细信息
[root@vagrant ~]# yum module info nginx
Last metadata expiration check: 0:35:07 ago on Fri 07 Jun 2024 09:42:12 AM CST.
Name : nginx
Stream : 1.22
Version : 9020020221218004026
Context : 9
Architecture : x86_64
Profiles : common [d]
Default profiles : common
Repo : ol9_appstream
Summary : nginx webserver
Description : nginx 1.22 webserver module
Requires : platform:[el9]
Artifacts : nginx-1:1.22.1-3.0.1.module+el9.2.0+20957+ca2c5b96.x86_64
: nginx-all-modules-1:1.22.1-3.0.1.module+el9.2.0+20957+ca2c5b96.noarch
: nginx-core-1:1.22.1-3.0.1.module+el9.2.0+20957+ca2c5b96.x86_64
: nginx-filesystem-1:1.22.1-3.0.1.module+el9.2.0+20957+ca2c5b96.noarch
: nginx-mod-devel-1:1.22.1-3.0.1.module+el9.2.0+20957+ca2c5b96.x86_64
: nginx-mod-http-image-filter-1:1.22.1-3.0.1.module+el9.2.0+20957+ca2c5b96.x86_64
: nginx-mod-http-perl-1:1.22.1-3.0.1.module+el9.2.0+20957+ca2c5b96.x86_64
: nginx-mod-http-xslt-filter-1:1.22.1-3.0.1.module+el9.2.0+20957+ca2c5b96.x86_64
: nginx-mod-mail-1:1.22.1-3.0.1.module+el9.2.0+20957+ca2c5b96.x86_64
: nginx-mod-stream-1:1.22.1-3.0.1.module+el9.2.0+20957+ca2c5b96.x86_64

Name : nginx
Stream : 1.22
Version : 9020020231011212752
Context : f855f1a9
Architecture : x86_64
Profiles : common [d]
Default profiles : common
Repo : ol9_appstream
Summary : nginx webserver
Description : nginx 1.22 webserver module
Requires : platform:[el9]
Artifacts : nginx-1:1.22.1-3.0.1.module+el9.2.0+90031+da4273d7.1.x86_64
: nginx-all-modules-1:1.22.1-3.0.1.module+el9.2.0+90031+da4273d7.1.noarch
: nginx-core-1:1.22.1-3.0.1.module+el9.2.0+90031+da4273d7.1.x86_64
: nginx-filesystem-1:1.22.1-3.0.1.module+el9.2.0+90031+da4273d7.1.noarch
: nginx-mod-devel-1:1.22.1-3.0.1.module+el9.2.0+90031+da4273d7.1.x86_64
: nginx-mod-http-image-filter-1:1.22.1-3.0.1.module+el9.2.0+90031+da4273d7.1.x86_64
: nginx-mod-http-perl-1:1.22.1-3.0.1.module+el9.2.0+90031+da4273d7.1.x86_64
: nginx-mod-http-xslt-filter-1:1.22.1-3.0.1.module+el9.2.0+90031+da4273d7.1.x86_64
: nginx-mod-mail-1:1.22.1-3.0.1.module+el9.2.0+90031+da4273d7.1.x86_64
: nginx-mod-stream-1:1.22.1-3.0.1.module+el9.2.0+90031+da4273d7.1.x86_64

Name : nginx
Stream : 1.22
Version : 9030020231109020034
Context : 1b7ac61d
Architecture : x86_64
Profiles : common [d]
Default profiles : common
Repo : ol9_appstream
Summary : nginx webserver
Description : nginx 1.22 webserver module
Requires : platform:[el9]
Artifacts : nginx-1:1.22.1-5.0.1.module+el9.3.0+90064+5f6be4e1.x86_64
: nginx-all-modules-1:1.22.1-5.0.1.module+el9.3.0+90064+5f6be4e1.noarch
: nginx-core-1:1.22.1-5.0.1.module+el9.3.0+90064+5f6be4e1.x86_64
: nginx-filesystem-1:1.22.1-5.0.1.module+el9.3.0+90064+5f6be4e1.noarch
: nginx-mod-devel-1:1.22.1-5.0.1.module+el9.3.0+90064+5f6be4e1.x86_64
: nginx-mod-http-image-filter-1:1.22.1-5.0.1.module+el9.3.0+90064+5f6be4e1.x86_64
: nginx-mod-http-perl-1:1.22.1-5.0.1.module+el9.3.0+90064+5f6be4e1.x86_64
: nginx-mod-http-xslt-filter-1:1.22.1-5.0.1.module+el9.3.0+90064+5f6be4e1.x86_64
: nginx-mod-mail-1:1.22.1-5.0.1.module+el9.3.0+90064+5f6be4e1.x86_64
: nginx-mod-stream-1:1.22.1-5.0.1.module+el9.3.0+90064+5f6be4e1.x86_64

Name : nginx
Stream : 1.24
Version : 9040020240409052757
Context : bc5b3234
Architecture : x86_64
Profiles : common [d]
Default profiles : common
Repo : ol9_appstream
Summary : nginx webserver
Description : nginx 1.24 webserver module
Requires : platform:[el9]
Artifacts : nginx-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64
: nginx-all-modules-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.noarch
: nginx-core-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64
: nginx-filesystem-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.noarch
: nginx-mod-devel-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64
: nginx-mod-http-image-filter-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64
: nginx-mod-http-perl-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64
: nginx-mod-http-xslt-filter-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64
: nginx-mod-mail-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64
: nginx-mod-stream-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled, [a]ctive

如果不指定模块流,则yum module info将显示默认流的模块的默认配置文件所安装的软件包列表。

使用module-name:stream格式来查看特定的模块流,--profile选项可显示有关各个模块的配置文件所安装的软件包的信息,例如:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
[root@vagrant ~]# yum module list nginx
Last metadata expiration check: 0:36:49 ago on Fri 07 Jun 2024 09:42:12 AM CST.
Oracle Linux 9 Application Stream Packages (x86_64)
Name Stream Profiles Summary
nginx 1.22 common [d] nginx webserver
nginx 1.24 common [d] nginx webserver

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
[root@vagrant ~]# yum module info --profile [common] nginx:1.22
Last metadata expiration check: 0:38:12 ago on Fri 07 Jun 2024 09:42:12 AM CST.
Unable to resolve argument common
Name : nginx:1.22:9020020221218004026:9:x86_64
common : nginx
: nginx-all-modules
: nginx-filesystem
: nginx-mod-http-image-filter
: nginx-mod-http-perl
: nginx-mod-http-xslt-filter
: nginx-mod-mail
: nginx-mod-stream

Name : nginx:1.22:9020020231011212752:f855f1a9:x86_64
common : nginx
: nginx-all-modules
: nginx-filesystem
: nginx-mod-http-image-filter
: nginx-mod-http-perl
: nginx-mod-http-xslt-filter
: nginx-mod-mail
: nginx-mod-stream

Name : nginx:1.22:9030020231109020034:1b7ac61d:x86_64
common : nginx
: nginx-all-modules
: nginx-filesystem
: nginx-mod-http-image-filter
: nginx-mod-http-perl
: nginx-mod-http-xslt-filter
: nginx-mod-mail
: nginx-mod-stream

启用模块流

必须启用模块流才能安装模块,为了简化这个过程,在安装模块的同时,它根据需要启用其模块流。也可以手动去启用模块流。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 启用指定的模块流
# 注意:对于指定模块,只能启用一个模块流,启用其他模块流将会禁用原始的模块流。
[root@vagrant ~]# yum module list nginx
Last metadata expiration check: 0:41:40 ago on Fri 07 Jun 2024 09:42:12 AM CST.
Oracle Linux 9 Application Stream Packages (x86_64)
Name Stream Profiles Summary
nginx 1.22 common [d] nginx webserver
nginx 1.24 common [d] nginx webserver

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
[root@vagrant ~]# yum module enable nginx:1.22
Last metadata expiration check: 0:42:00 ago on Fri 07 Jun 2024 09:42:12 AM CST.
Dependencies resolved.
======================================================================================================================================================================
Package Architecture Version Repository Size
======================================================================================================================================================================
Enabling module streams:
nginx 1.22

Transaction Summary
======================================================================================================================================================================

Is this ok [y/N]: y
Complete!
[root@vagrant ~]# yum module list nginx
Last metadata expiration check: 0:42:14 ago on Fri 07 Jun 2024 09:42:12 AM CST.
Oracle Linux 9 Application Stream Packages (x86_64)
Name Stream Profiles Summary
nginx 1.22 [e] common [d] nginx webserver
nginx 1.24 common [d] nginx webserver

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
[root@vagrant ~]#

如果某个stream被标记为[d],则表示是默认流,此时在你安装时如果不指定流,则默认安装该模块流。

如果某个stram被标记为[d][e],则表示默认启用的模块流,此时无法通过yum module enable nginx:1.22这种形式来启用到其他的流。此时必须显式指定[module_stream_switch]选项,否则无法切换

切换模块流

当启用了模块流之后,如果想更换模块流,则无法通过yum module enable来启用到其他的流,此时必须显式指定[module_stream_switch]选项,否则无法切换。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[root@vagrant ~]# yum module list nginx
Last metadata expiration check: 0:51:42 ago on Fri 07 Jun 2024 09:42:12 AM CST.
Oracle Linux 9 Application Stream Packages (x86_64)
Name Stream Profiles Summary
nginx 1.22 [e] common [d] nginx webserver
nginx 1.24 common [d] nginx webserver

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
[root@vagrant ~]# yum module switch-to nginx:1.24
Last metadata expiration check: 0:51:59 ago on Fri 07 Jun 2024 09:42:12 AM CST.
Dependencies resolved.
===========================================================================================================================================================================================
Package Architecture Version Repository Size
===========================================================================================================================================================================================
Switching module streams:
nginx 1.22 -> 1.24

Transaction Summary
===========================================================================================================================================================================================

Is this ok [y/N]: y
Complete!
[root@vagrant ~]# yum module list nginx
Last metadata expiration check: 0:52:08 ago on Fri 07 Jun 2024 09:42:12 AM CST.
Oracle Linux 9 Application Stream Packages (x86_64)
Name Stream Profiles Summary
nginx 1.22 common [d] nginx webserver
nginx 1.24 [e] common [d] nginx webserver

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

安装模块

安装模块时,会自动启用对应的模块流

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 使用默认流和默认配置文件安装模块
yum module install nginx

# 等价语法,@表示法告知yum参数是模块名而非软件包名称。
yum install @nginx

# 安装指定版本流
yum module install 模块名:模块流

# 从指定的流,使用指定的配置文件,安装指定模块
# 配置文件决定了所要安装的软件包列表
# 省略profile将使用默认配置文件,省略stream将使用默认流
yum module install modname:stream/profile
# 示例:从3.6这个版本流中使用common配置文件安装名为python36的模块
yum module install python36:3.6/common

删除模块

删除模块流会删除当前启用的模块流配置集中的所有软件包,以及其依赖项。从此模块流中安装的软件包如果未在其配置文件中列出,则不会被删除,你可以手动删除。

警告:

删除模块和切换模块流比较棘手。切换模块流相当于重置当前流并启用新流,它不会自动更改任何已安装的软件包,你必须手动完成。

强烈建议不要直接安装与当前所安装的模块流不同的模块流,因为升级脚本可能会在安装期间运行,从而破坏原始模块流,这可能会导致数据丢失或其他配置问题。

1
yum module remove nginx

删除模块后,其模块流仍然为启用状态。

禁用模块流

1
yum module disable nginx

切换模块流实验

切换模块流通常需要将内容升级或降级到不同版本。

为确保顺利,应首先删除模块流提供的模块,这会删除模块的配置文件所安装的所有软件包及其依赖项。

安装nginx:1.24流所提供的nginx模块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
[root@vagrant ~]# yum module list nginx
Last metadata expiration check: 1:02:13 ago on Fri 07 Jun 2024 09:42:12 AM CST.
Oracle Linux 9 Application Stream Packages (x86_64)
Name Stream Profiles Summary
nginx 1.22 common [d] nginx webserver
nginx 1.24 [e] common [d] nginx webserver

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
[root@vagrant ~]# yum module install nginx:1.24
Last metadata expiration check: 1:03:53 ago on Fri 07 Jun 2024 09:42:12 AM CST.
Dependencies resolved.
===========================================================================================================================================================================================
Package Architecture Version Repository Size
===========================================================================================================================================================================================
Installing group/module packages:
nginx x86_64 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 ol9_appstream 46 k
nginx-all-modules noarch 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 ol9_appstream 8.0 k
nginx-filesystem noarch 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 ol9_appstream 8.9 k
nginx-mod-http-image-filter x86_64 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 ol9_appstream 20 k
nginx-mod-http-perl x86_64 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 ol9_appstream 36 k
nginx-mod-http-xslt-filter x86_64 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 ol9_appstream 18 k
nginx-mod-mail x86_64 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 ol9_appstream 53 k
nginx-mod-stream x86_64 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 ol9_appstream 80 k
Installing dependencies:
gd x86_64 2.3.2-3.el9 ol9_appstream 132 k
jbigkit-libs x86_64 2.1-23.el9 ol9_appstream 58 k
libXpm x86_64 3.5.13-10.el9 ol9_appstream 62 k
libtiff x86_64 4.4.0-12.el9 ol9_appstream 204 k
libwebp x86_64 1.2.0-8.el9_3 ol9_appstream 286 k
nginx-core x86_64 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 ol9_appstream 599 k
oracle-logos-httpd noarch 90.2-1.0.4.el9 ol9_baseos_latest 37 k
Installing module profiles:
nginx/common

Transaction Summary
===========================================================================================================================================================================================
Install 15 Packages

Total download size: 1.6 M
Installed size: 4.2 M
Is this ok [y/N]: y
Downloading Packages:
(1/15): jbigkit-libs-2.1-23.el9.x86_64.rpm 60 kB/s | 58 kB 00:00
(2/15): oracle-logos-httpd-90.2-1.0.4.el9.noarch.rpm 37 kB/s | 37 kB 00:01
(3/15): gd-2.3.2-3.el9.x86_64.rpm 93 kB/s | 132 kB 00:01
(4/15): libXpm-3.5.13-10.el9.x86_64.rpm 122 kB/s | 62 kB 00:00
(5/15): libtiff-4.4.0-12.el9.x86_64.rpm 310 kB/s | 204 kB 00:00
(6/15): libwebp-1.2.0-8.el9_3.x86_64.rpm 434 kB/s | 286 kB 00:00
(7/15): nginx-all-modules-1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.noarch.rpm 3.5 kB/s | 8.0 kB 00:02
(8/15): nginx-1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64.rpm 17 kB/s | 46 kB 00:02
(9/15): nginx-filesystem-1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.noarch.rpm 6.7 kB/s | 8.9 kB 00:01
(10/15): nginx-core-1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64.rpm 188 kB/s | 599 kB 00:03
(11/15): nginx-mod-http-image-filter-1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64.rpm 8.9 kB/s | 20 kB 00:02
(12/15): nginx-mod-http-perl-1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64.rpm 18 kB/s | 36 kB 00:02
(13/15): nginx-mod-http-xslt-filter-1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64.rpm 7.3 kB/s | 18 kB 00:02
(14/15): nginx-mod-mail-1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64.rpm 22 kB/s | 53 kB 00:02
(15/15): nginx-mod-stream-1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64.rpm 33 kB/s | 80 kB 00:02
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 169 kB/s | 1.6 MB 00:09
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Running scriptlet: nginx-filesystem-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.noarch 1/15
Installing : nginx-filesystem-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.noarch 1/15
Installing : libwebp-1.2.0-8.el9_3.x86_64 2/15
Installing : nginx-core-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 3/15
Installing : libXpm-3.5.13-10.el9.x86_64 4/15
Installing : jbigkit-libs-2.1-23.el9.x86_64 5/15
Installing : libtiff-4.4.0-12.el9.x86_64 6/15
Installing : gd-2.3.2-3.el9.x86_64 7/15
Installing : oracle-logos-httpd-90.2-1.0.4.el9.noarch 8/15
Installing : nginx-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 9/15
Running scriptlet: nginx-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 9/15
Installing : nginx-mod-http-image-filter-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 10/15
Running scriptlet: nginx-mod-http-image-filter-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 10/15
Installing : nginx-mod-http-perl-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 11/15
Running scriptlet: nginx-mod-http-perl-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 11/15
Installing : nginx-mod-http-xslt-filter-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 12/15
Running scriptlet: nginx-mod-http-xslt-filter-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 12/15
Installing : nginx-mod-mail-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 13/15
Running scriptlet: nginx-mod-mail-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 13/15
Installing : nginx-mod-stream-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 14/15
Running scriptlet: nginx-mod-stream-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 14/15
Installing : nginx-all-modules-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.noarch 15/15
Running scriptlet: nginx-all-modules-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.noarch 15/15
Verifying : oracle-logos-httpd-90.2-1.0.4.el9.noarch 1/15
Verifying : gd-2.3.2-3.el9.x86_64 2/15
Verifying : jbigkit-libs-2.1-23.el9.x86_64 3/15
Verifying : libXpm-3.5.13-10.el9.x86_64 4/15
Verifying : libtiff-4.4.0-12.el9.x86_64 5/15
Verifying : libwebp-1.2.0-8.el9_3.x86_64 6/15
Verifying : nginx-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 7/15
Verifying : nginx-all-modules-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.noarch 8/15
Verifying : nginx-core-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 9/15
Verifying : nginx-filesystem-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.noarch 10/15
Verifying : nginx-mod-http-image-filter-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 11/15
Verifying : nginx-mod-http-perl-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 12/15
Verifying : nginx-mod-http-xslt-filter-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 13/15
Verifying : nginx-mod-mail-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 14/15
Verifying : nginx-mod-stream-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 15/15

Installed:
gd-2.3.2-3.el9.x86_64 jbigkit-libs-2.1-23.el9.x86_64
libXpm-3.5.13-10.el9.x86_64 libtiff-4.4.0-12.el9.x86_64
libwebp-1.2.0-8.el9_3.x86_64 nginx-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64
nginx-all-modules-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.noarch nginx-core-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64
nginx-filesystem-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.noarch nginx-mod-http-image-filter-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64
nginx-mod-http-perl-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 nginx-mod-http-xslt-filter-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64
nginx-mod-mail-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 nginx-mod-stream-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64
oracle-logos-httpd-90.2-1.0.4.el9.noarch

Complete!
[root@vagrant ~]# yum module list nginx
Last metadata expiration check: 1:04:38 ago on Fri 07 Jun 2024 09:42:12 AM CST.
Oracle Linux 9 Application Stream Packages (x86_64)
Name Stream Profiles Summary
nginx 1.22 common [d] nginx webserver
nginx 1.24 [e] common [d] [i] nginx webserver

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

列出模块安装了哪些软件包

1
2
3
4
5
6
7
8
9
10
11
12
13
# 列出所安装的module包
[root@vagrant ~]# yum module info nginx | grep module+el9 | sed 's/.*: //g;s/\n/ /g' | xargs yum list installed
Installed Packages
nginx.x86_64 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 @ol9_appstream
nginx-all-modules.noarch 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 @ol9_appstream
nginx-core.x86_64 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 @ol9_appstream
nginx-filesystem.noarch 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 @ol9_appstream
nginx-mod-http-image-filter.x86_64 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 @ol9_appstream
nginx-mod-http-perl.x86_64 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 @ol9_appstream
nginx-mod-http-xslt-filter.x86_64 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 @ol9_appstream
nginx-mod-mail.x86_64 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 @ol9_appstream
nginx-mod-stream.x86_64 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 @ol9_appstream
[root@vagrant ~]#

下面的是yum module install的输出,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Installing group/module packages:  # 模块流配置文件中指定的包
nginx x86_64 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 ol9_appstream 46 k
nginx-all-modules noarch 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 ol9_appstream 8.0 k
nginx-filesystem noarch 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 ol9_appstream 8.9 k
nginx-mod-http-image-filter x86_64 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 ol9_appstream 20 k
nginx-mod-http-perl x86_64 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 ol9_appstream 36 k
nginx-mod-http-xslt-filter x86_64 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 ol9_appstream 18 k
nginx-mod-mail x86_64 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 ol9_appstream 53 k
nginx-mod-stream x86_64 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 ol9_appstream 80 k
Installing dependencies: # 依赖包
gd x86_64 2.3.2-3.el9 ol9_appstream 132 k
jbigkit-libs x86_64 2.1-23.el9 ol9_appstream 58 k
libXpm x86_64 3.5.13-10.el9 ol9_appstream 62 k
libtiff x86_64 4.4.0-12.el9 ol9_appstream 204 k
libwebp x86_64 1.2.0-8.el9_3 ol9_appstream 286 k
nginx-core x86_64 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 ol9_appstream 599 k
oracle-logos-httpd noarch 90.2-1.0.4.el9 ol9_baseos_latest 37 k
Installing module profiles:
nginx/common

使用yum module info查看配置文件中指定的需要安装的包

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@vagrant ~]# yum module info --profile common nginx:1.24
Last metadata expiration check: 1:12:59 ago on Fri 07 Jun 2024 09:42:12 AM CST.
Unable to resolve argument common
Name : nginx:1.24:9040020240409052757:bc5b3234:x86_64
common : nginx
: nginx-all-modules
: nginx-filesystem
: nginx-mod-http-image-filter
: nginx-mod-http-perl
: nginx-mod-http-xslt-filter
: nginx-mod-mail
: nginx-mod-stream
[root@vagrant ~]#

删除模块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
[root@vagrant ~]# yum module remove nginx:1.24
Last metadata expiration check: 1:14:38 ago on Fri 07 Jun 2024 09:42:12 AM CST.
Dependencies resolved.
===========================================================================================================================================================================================
Package Architecture Version Repository Size
===========================================================================================================================================================================================
Removing:
nginx x86_64 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 @ol9_appstream 129 k
nginx-all-modules noarch 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 @ol9_appstream 0
nginx-filesystem noarch 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 @ol9_appstream 0
nginx-mod-http-image-filter x86_64 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 @ol9_appstream 32 k
nginx-mod-http-perl x86_64 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 @ol9_appstream 67 k
nginx-mod-http-xslt-filter x86_64 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 @ol9_appstream 28 k
nginx-mod-mail x86_64 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 @ol9_appstream 120 k
nginx-mod-stream x86_64 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 @ol9_appstream 193 k
Removing unused dependencies:
gd x86_64 2.3.2-3.el9 @ol9_appstream 412 k
jbigkit-libs x86_64 2.1-23.el9 @ol9_appstream 114 k
libXpm x86_64 3.5.13-10.el9 @ol9_appstream 126 k
libtiff x86_64 4.4.0-12.el9 @ol9_appstream 573 k
libwebp x86_64 1.2.0-8.el9_3 @ol9_appstream 769 k
nginx-core x86_64 1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9 @ol9_appstream 1.6 M
oracle-logos-httpd noarch 90.2-1.0.4.el9 @ol9_baseos_latest 29 k
Disabling module profiles:
nginx/common

Transaction Summary
===========================================================================================================================================================================================
Remove 15 Packages

Freed space: 4.2 M
Is this ok [y/N]: y
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Erasing : nginx-all-modules-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.noarch 1/15
Erasing : nginx-mod-http-image-filter-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 2/15
Erasing : gd-2.3.2-3.el9.x86_64 3/15
Erasing : libtiff-4.4.0-12.el9.x86_64 4/15
Erasing : nginx-mod-http-perl-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 5/15
Erasing : nginx-mod-http-xslt-filter-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 6/15
Erasing : nginx-mod-mail-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 7/15
Erasing : nginx-mod-stream-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 8/15
Running scriptlet: nginx-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 9/15
Erasing : nginx-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 9/15
Running scriptlet: nginx-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 9/15
Erasing : oracle-logos-httpd-90.2-1.0.4.el9.noarch 10/15
Erasing : nginx-core-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 11/15
Erasing : nginx-filesystem-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.noarch 12/15
Erasing : jbigkit-libs-2.1-23.el9.x86_64 13/15
Erasing : libwebp-1.2.0-8.el9_3.x86_64 14/15
Erasing : libXpm-3.5.13-10.el9.x86_64 15/15
Running scriptlet: libXpm-3.5.13-10.el9.x86_64 15/15
Verifying : gd-2.3.2-3.el9.x86_64 1/15
Verifying : jbigkit-libs-2.1-23.el9.x86_64 2/15
Verifying : libXpm-3.5.13-10.el9.x86_64 3/15
Verifying : libtiff-4.4.0-12.el9.x86_64 4/15
Verifying : libwebp-1.2.0-8.el9_3.x86_64 5/15
Verifying : nginx-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 6/15
Verifying : nginx-all-modules-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.noarch 7/15
Verifying : nginx-core-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 8/15
Verifying : nginx-filesystem-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.noarch 9/15
Verifying : nginx-mod-http-image-filter-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 10/15
Verifying : nginx-mod-http-perl-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 11/15
Verifying : nginx-mod-http-xslt-filter-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 12/15
Verifying : nginx-mod-mail-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 13/15
Verifying : nginx-mod-stream-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 14/15
Verifying : oracle-logos-httpd-90.2-1.0.4.el9.noarch 15/15

Removed:
gd-2.3.2-3.el9.x86_64 jbigkit-libs-2.1-23.el9.x86_64
libXpm-3.5.13-10.el9.x86_64 libtiff-4.4.0-12.el9.x86_64
libwebp-1.2.0-8.el9_3.x86_64 nginx-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64
nginx-all-modules-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.noarch nginx-core-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64
nginx-filesystem-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.noarch nginx-mod-http-image-filter-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64
nginx-mod-http-perl-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 nginx-mod-http-xslt-filter-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64
nginx-mod-mail-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64 nginx-mod-stream-1:1.24.0-1.0.1.module+el9.4.0+90262+d5d126d9.x86_64
oracle-logos-httpd-90.2-1.0.4.el9.noarch

Complete!

重置模块流

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[root@vagrant ~]# yum module list nginx
Last metadata expiration check: 1:15:38 ago on Fri 07 Jun 2024 09:42:12 AM CST.
Oracle Linux 9 Application Stream Packages (x86_64)
Name Stream Profiles Summary
nginx 1.22 common [d] nginx webserver
nginx 1.24 [e] common [d] nginx webserver

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
[root@vagrant ~]# yum module reset nginx
Last metadata expiration check: 1:15:54 ago on Fri 07 Jun 2024 09:42:12 AM CST.
Dependencies resolved.
======================================================================================================================================================================
Package Architecture Version Repository Size
======================================================================================================================================================================
Resetting modules:
nginx

Transaction Summary
======================================================================================================================================================================

Is this ok [y/N]: y
Complete!
[root@vagrant ~]# yum module list nginx
Last metadata expiration check: 1:16:04 ago on Fri 07 Jun 2024 09:42:12 AM CST.
Oracle Linux 9 Application Stream Packages (x86_64)
Name Stream Profiles Summary
nginx 1.22 common [d] nginx webserver
nginx 1.24 common [d] nginx webserver

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

使用新的模块流

1
yum install @nginx:1.22

启用新的模块流之后,可能需要更新或降级之前模块流中,未在新配置文件中列出的软件包。必要时,可用yum distro-sync来执行此任务,此外,也可能会从先前模块流中保持安装的软件包,可通过yum remove对其删除。

多版本选择

1
alternatives --config python   # 根据提示选择所需的版本

不使用模块流

1
2
3
4
5
6
7
# 以下几种方法可以避免使用模块流安装软件
dnf module list php
dnf module reset php
dnf module enable php:remi-8.3
dnf install php
dnf install php-fpm
dnf install php-{mysqld,xml,...}