软件管理¶
概述¶
在 Linux 系统上,可以通过两种方式安装软件
- 使用安装包;
- 从源代码文件编译。
注意
这里不介绍从源代码安装。一般情况下,除非您想要的软件无法通过包管理器获得,否则您应该使用包方法。这样做的原因是,包系统通常会管理依赖项,而从源代码安装则需要手动管理依赖项。
包: 这是一个包含安装程序所需所有数据的单个文件。它可以直接从软件库在系统上执行。
源代码文件: 一些软件不是以可以立即安装的包的形式提供,而是通过包含源代码文件的存档提供。管理员需要准备这些文件并进行编译才能安装程序。
RPM: RedHat 软件包管理器¶
RPM (RedHat 软件包管理器) 是一个软件管理系统。可以安装、卸载、更新或检查包中包含的软件。
RPM 是所有基于 RedHat 的发行版 (RockyLinux、Fedora、CentOS、SuSe、Mandriva 等) 使用的格式。它在 Debian 世界中的等效项是 DPKG (Debian 软件包)。
RPM 包的名称遵循特定的命名规则
rpm
命令¶
rpm 命令允许您安装软件包。
rpm [-i][-U] package.rpm [-e] package
示例(对于名为“package”的包)
rpm -ivh package.rpm
选项 | 描述 |
---|---|
-i package.rpm | 安装软件包。 |
-U package.rpm | 更新已安装的软件包。 |
-e package.rpm | 卸载软件包。 |
-h | 显示进度条。 |
-v | 通知操作的进度。 |
--test | 测试命令,但不执行。 |
rpm
命令还允许您通过添加 -q
选项来查询系统包数据库。
可以执行多种类型的查询以获取有关已安装包的不同信息。RPM 数据库位于目录 /var/lib/rpm
中。
示例
rpm -qa
此命令查询系统上安装的所有包。
rpm -q [-a][-i][-l] package [-f] file
示例
rpm -qil package
rpm -qf /path/to/file
选项 | 描述 |
---|---|
-a | 列出系统上安装的所有包。 |
-i __package__ | 显示包信息。 |
-l __package__ | 列出包中包含的文件。 |
-f | 显示包含指定文件的包的名称。 |
--last | 包列表按安装日期给出(最后安装的包最先出现)。 |
警告
在 -q
选项之后,包名必须完全匹配。不支持元字符(通配符)。
提示
但是,可以使用 grep
命令列出所有已安装的包并进行过滤。
示例: 列出最后安装的包
sudo rpm -qa --last | head
NetworkManager-config-server-1.26.0-13.el8.noarch Mon 24 May 2021 02:34:00 PM CEST
iwl2030-firmware-18.168.6.1-101.el8.1.noarch Mon 24 May 2021 02:34:00 PM CEST
iwl2000-firmware-18.168.6.1-101.el8.1.noarch Mon 24 May 2021 02:34:00 PM CEST
iwl135-firmware-18.168.6.1-101.el8.1.noarch Mon 24 May 2021 02:34:00 PM CEST
iwl105-firmware-18.168.6.1-101.el8.1.noarch Mon 24 May 2021 02:34:00 PM CEST
iwl100-firmware-39.31.5.1-101.el8.1.noarch Mon 24 May 2021 02:34:00 PM CEST
iwl1000-firmware-39.31.5.1-101.el8.1.noarch Mon 24 May 2021 02:34:00 PM CEST
alsa-sof-firmware-1.5-2.el8.noarch Mon 24 May 2021 02:34:00 PM CEST
iwl7260-firmware-25.30.13.0-101.el8.1.noarch Mon 24 May 2021 02:33:59 PM CEST
iwl6050-firmware-41.28.5.1-101.el8.1.noarch Mon 24 May 2021 02:33:59 PM CEST
示例: 列出内核的安装历史
sudo rpm -qa --last kernel
kernel-4.18.0-305.el8.x86_64 Tue 25 May 2021 06:04:56 AM CEST
kernel-4.18.0-240.22.1.el8.x86_64 Mon 24 May 2021 02:33:35 PM CEST
示例: 使用 grep
列出所有安装的包,其名称相同
sudo dnf list installed | grep httpd
centos-logos-httpd.noarch 80.5-2.el8 @baseos
httpd.x86_64 2.4.37-30.module_el8.3.0+561+97fdbbcc @appstream
httpd-filesystem.noarch 2.4.37-30.module_el8.3.0+561+97fdbbcc @appstream
httpd-tools.x86_64 2.4.37-30.module_el8.3.0+561+97fdbbcc @appstream
DNF: Dandified Yum¶
DNF (Dandified Yum) 是一个软件包管理器,是 YUM (Yellow dog Updater Modified) 的继任者。它使用存储在本地或远程存储库(用于存储包的目录)中的 RPM 包。对于最常见的命令,其用法与 yum
相同。
dnf
命令允许通过将系统上安装的包与服务器上定义的存储库中的包进行比较来管理包。它还会自动安装依赖项,如果它们也存在于存储库中。
dnf
是许多基于 RedHat 的发行版 (RockyLinux、Fedora、CentOS 等) 使用的管理器。它在 Debian 世界中的等效项是 APT (Advanced Packaging Tool)。
dnf
命令¶
dnf
命令允许您通过仅指定简短名称来安装包。
dnf [install][remove][list all][search][info] package
示例
dnf install tree
仅需要软件包的简短名称。
选项 | 描述 |
---|---|
install | 安装软件包。 |
remove | 卸载软件包。 |
list all | 列出存储库中已有的包。 |
search | 在存储库中搜索包。 |
provides */command_name | 搜索命令。 |
info | 显示包信息。 |
autoremove | 删除所有安装为依赖项但不再需要的包。 |
dnf install
命令允许您安装所需的包,而无需担心其依赖项,因为 dnf
本身会直接解决这些依赖项。
dnf install nginx
Last metadata expiration check: 3:13:41 ago on Wed 23 Mar 2022 07:19:24 AM CET.
Dependencies resolved.
============================================================================================================================
Package Architecture Version Repository Size
============================================================================================================================
Installing:
nginx aarch64 1:1.14.1-9.module+el8.4.0+542+81547229 appstream 543 k
Installing dependencies:
nginx-all-modules noarch 1:1.14.1-9.module+el8.4.0+542+81547229 appstream 22 k
nginx-mod-http-image-filter aarch64 1:1.14.1-9.module+el8.4.0+542+81547229 appstream 33 k
nginx-mod-http-perl aarch64 1:1.14.1-9.module+el8.4.0+542+81547229 appstream 44 k
nginx-mod-http-xslt-filter aarch64 1:1.14.1-9.module+el8.4.0+542+81547229 appstream 32 k
nginx-mod-mail aarch64 1:1.14.1-9.module+el8.4.0+542+81547229 appstream 60 k
nginx-mod-stream aarch64 1:1.14.1-9.module+el8.4.0+542+81547229 appstream 82 k
Transaction Summary
============================================================================================================================
Install 7 Packages
Total download size: 816 k
Installed size: 2.2 M
Is this ok [y/N]:
如果您不记得包的确切名称,可以使用 dnf search name
命令搜索它。如您所见,有一个部分包含确切的名称,另一个部分包含包对应关系,所有这些都突出显示以便于搜索。
dnf search nginx
Last metadata expiration check: 0:20:55 ago on Wed 23 Mar 2022 10:40:43 AM CET.
=============================================== Name Exactly Matched: nginx ================================================
nginx.aarch64 : A high performance web server and reverse proxy server
============================================== Name & Summary Matched: nginx ===============================================
collectd-nginx.aarch64 : Nginx plugin for collectd
munin-nginx.noarch : NGINX support for Munin resource monitoring
nginx-all-modules.noarch : A meta package that installs all available Nginx modules
nginx-filesystem.noarch : The basic directory layout for the Nginx server
nginx-mod-http-image-filter.aarch64 : Nginx HTTP image filter module
nginx-mod-http-perl.aarch64 : Nginx HTTP perl module
nginx-mod-http-xslt-filter.aarch64 : Nginx XSLT module
nginx-mod-mail.aarch64 : Nginx mail modules
nginx-mod-stream.aarch64 : Nginx stream modules
pagure-web-nginx.noarch : Nginx configuration for Pagure
pcp-pmda-nginx.aarch64 : Performance Co-Pilot (PCP) metrics for the Nginx Webserver
python3-certbot-nginx.noarch : The nginx plugin for certbot
另一种通过输入额外搜索关键字来搜索包的方法是将dnf
命令的结果通过管道传递到grep
命令,并使用所需的关键字。
dnf search nginx | grep mod
Last metadata expiration check: 3:44:49 ago on Wed 23 Mar 2022 06:16:47 PM CET.
nginx-all-modules.noarch : A meta package that installs all available Nginx modules
nginx-mod-http-image-filter.aarch64 : Nginx HTTP image filter module
nginx-mod-http-perl.aarch64 : Nginx HTTP perl module
nginx-mod-http-xslt-filter.aarch64 : Nginx XSLT module
nginx-mod-mail.aarch64 : Nginx mail modules
nginx-mod-stream.aarch64 : Nginx stream modules
dnf remove
命令会从系统中删除包及其依赖项。以下是dnf remove httpd命令的摘录。
dnf remove httpd
Dependencies resolved.
============================================================================================================================
Package Architecture Version Repository Size
============================================================================================================================
Removing:
httpd aarch64 2.4.37-43.module+el8.5.0+727+743c5577.1 @appstream 8.9 M
Removing dependent packages:
mod_ssl aarch64 1:2.4.37-43.module+el8.5.0+727+743c5577.1 @appstream 274 k
php aarch64 7.4.19-1.module+el8.5.0+696+61e7c9ba @appstream 4.4 M
python3-certbot-apache noarch 1.22.0-1.el8 @epel 539 k
Removing unused dependencies:
apr aarch64 1.6.3-12.el8 @appstream 299 k
apr-util aarch64 1.6.1-6.el8.1 @appstream 224 k
apr-util-bdb aarch64 1.6.1-6.el8.1 @appstream 67 k
apr-util-openssl aarch64 1.6.1-6.el8.1 @appstream 68 k
augeas-libs aarch64 1.12.0-6.el8 @baseos 1.4 M
httpd-filesystem noarch 2.4.37-43.module+el8.5.0+727+743c5577.1 @appstream 400
httpd-tools aarch64 2.4.37-43.module+el8.5.0+727+743c5577.1
...
dnf list
命令列出系统上安装的所有包以及存储库中存在的包。它接受多个参数
参数 | 描述 |
---|---|
all | 列出已安装的软件包,然后列出存储库中可用的软件包。 |
available | 仅列出可用于安装的软件包。 |
updates | 列出可以升级的软件包。 |
obsoletes | 列出被更高版本(可用)所淘汰的软件包。 |
recent | 列出最近添加到存储库的软件包。 |
dnf info
命令正如您所料,提供有关软件包的详细信息
dnf info firewalld
Last metadata expiration check: 15:47:27 ago on Tue 22 Mar 2022 05:49:42 PM CET.
Installed Packages
Name : firewalld
Version : 0.9.3
Release : 7.el8
Architecture : noarch
Size : 2.0 M
Source : firewalld-0.9.3-7.el8.src.rpm
Repository : @System
From repo : baseos
Summary : A firewall daemon with D-Bus interface providing a dynamic firewall
URL : http://www.firewalld.org
License : GPLv2+
Description : firewalld is a firewall service daemon that provides a dynamic customizable
: firewall with a D-Bus interface.
Available Packages
Name : firewalld
Version : 0.9.3
Release : 7.el8_5.1
Architecture : noarch
Size : 501 k
Source : firewalld-0.9.3-7.el8_5.1.src.rpm
Repository : baseos
Summary : A firewall daemon with D-Bus interface providing a dynamic firewall
URL : http://www.firewalld.org
License : GPLv2+
Description : firewalld is a firewall service daemon that provides a dynamic customizable
: firewall with a D-Bus interface.
有时您只知道要使用的可执行文件,但不知道包含它的软件包,在这种情况下,您可以使用dnf provides */package_name
命令,它会为您在数据库中搜索所需的匹配项。
搜索semanage
命令的示例
dnf provides */semanage
Last metadata expiration check: 1:12:29 ago on Wed 23 Mar 2022 10:40:43 AM CET.
libsemanage-devel-2.9-6.el8.aarch64 : Header files and libraries used to build policy manipulation tools
Repo : powertools
Matched from:
Filename : /usr/include/semanage
policycoreutils-python-utils-2.9-16.el8.noarch : SELinux policy core python utilities
Repo : baseos
Matched from:
Filename : /usr/sbin/semanage
Filename : /usr/share/bash-completion/completions/semanage
dnf autoremove
命令不需要任何参数。Dnf负责搜索要删除的候选包。
dnf autoremove
Last metadata expiration check: 0:24:40 ago on Wed 23 Mar 2022 06:16:47 PM CET.
Dependencies resolved.
Nothing to do.
Complete!
其他有用的dnf
选项¶
选项 | 描述 |
---|---|
repolist | 列出系统上配置的存储库。 |
grouplist | 列出可用的软件包集合。 |
clean | 删除临时文件。 |
dnf repolist
命令列出系统上配置的存储库。默认情况下,它只列出启用的存储库,但可以与以下参数一起使用
参数 | 描述 |
---|---|
--all | 列出所有存储库。 |
--enabled | 默认 |
--disabled | 仅列出禁用的存储库。 |
示例
dnf repolist
repo id repo name
appstream Rocky Linux 8 - AppStream
baseos Rocky Linux 8 - BaseOS
epel Extra Packages for Enterprise Linux 8 - aarch64
epel-modular Extra Packages for Enterprise Linux Modular 8 - aarch64
extras Rocky Linux 8 - Extras
powertools Rocky Linux 8 - PowerTools
rockyrpi Rocky Linux 8 - Rasperry Pi
以下是使用--all
标志的命令摘录。
dnf repolist --all
...
repo id repo name status
appstream Rocky Linux 8 - AppStream enabled
appstream-debug Rocky Linux 8 - AppStream - Source disabled
appstream-source Rocky Linux 8 - AppStream - Source disabled
baseos Rocky Linux 8 - BaseOS enabled
baseos-debug Rocky Linux 8 - BaseOS - Source disabled
baseos-source Rocky Linux 8 - BaseOS - Source disabled
devel Rocky Linux 8 - Devel WARNING! FOR BUILDROOT AND KOJI USE disabled
epel Extra Packages for Enterprise Linux 8 - aarch64 enabled
epel-debuginfo Extra Packages for Enterprise Linux 8 - aarch64 - Debug disabled
epel-modular Extra Packages for Enterprise Linux Modular 8 - aarch64 enabled
epel-modular-debuginfo Extra Packages for Enterprise Linux Modular 8 - aarch64 - Debug disabled
epel-modular-source Extra Packages for Enterprise Linux Modular 8 - aarch64 - Source
...
以下是禁用存储库列表的摘录。
dnf repolist --disabled
repo id repo name
appstream-debug Rocky Linux 8 - AppStream - Source
appstream-source Rocky Linux 8 - AppStream - Source
baseos-debug Rocky Linux 8 - BaseOS - Source
baseos-source Rocky Linux 8 - BaseOS - Source
devel Rocky Linux 8 - Devel WARNING! FOR BUILDROOT AND KOJI USE
epel-debuginfo Extra Packages for Enterprise Linux 8 - aarch64 - Debug
epel-modular-debuginfo Extra Packages for Enterprise Linux Modular 8 - aarch64 - Debug
epel-modular-source Extra Packages for Enterprise Linux Modular 8 - aarch64 - Source
epel-source Extra Packages for Enterprise Linux 8 - aarch64 - Source
epel-testing Extra Packages for Enterprise Linux 8 - Testing - aarch64
...
使用-v
选项可以增强列表,其中包含许多其他信息。以下您可以看到该命令结果的一部分。
dnf repolist -v
...
Repo-id : powertools
Repo-name : Rocky Linux 8 - PowerTools
Repo-revision : 8.5
Repo-distro-tags : [cpe:/o:rocky:rocky:8]: , , 8, L, R, c, i, k, n, o, u, x, y
Repo-updated : Wed 16 Mar 2022 10:07:49 PM CET
Repo-pkgs : 1,650
Repo-available-pkgs: 1,107
Repo-size : 6.4 G
Repo-mirrors : https://mirrors.rockylinux.org/mirrorlist?arch=aarch64&repo=PowerTools-8
Repo-baseurl : https://example.com/pub/rocky/8.8/PowerTools/x86_64/os/ (30 more)
Repo-expire : 172,800 second(s) (last: Tue 22 Mar 2022 05:49:24 PM CET)
Repo-filename : /etc/yum.repos.d/Rocky-PowerTools.repo
...
使用组
组是一组软件包的集合(您可以将其视为虚拟软件包),这些软件包在逻辑上将一组应用程序分组在一起以实现某种目的(桌面环境、服务器、开发工具等)。
dnf grouplist
命令列出所有可用的组。
dnf grouplist
Last metadata expiration check: 1:52:00 ago on Wed 23 Mar 2022 02:11:43 PM CET.
Available Environment Groups:
Server with GUI
Server
Minimal Install
KDE Plasma Workspaces
Custom Operating System
Available Groups:
Container Management
.NET Core Development
RPM Development Tools
Development Tools
Headless Management
Legacy UNIX Compatibility
Network Servers
Scientific Support
Security Tools
Smart Card Support
System Tools
Fedora Packager
Xfce
dnf groupinstall
命令允许您安装这些组之一。
dnf groupinstall "Network Servers"
Last metadata expiration check: 2:33:26 ago on Wed 23 Mar 2022 02:11:43 PM CET.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing Groups:
Network Servers
Transaction Summary
================================================================================
Is this ok [y/N]:
请注意,将组名用双引号括起来是一种良好的做法,因为如果没有双引号,该命令只有在组名不包含空格时才能正确执行。
因此,dnf groupinstall Network Servers
会产生以下错误。
dnf groupinstall Network Servers
Last metadata expiration check: 3:05:45 ago on Wed 23 Mar 2022 02:11:43 PM CET.
Module or Group 'Network' is not available.
Module or Group 'Servers' is not available.
Error: Nothing to do.
用于删除组的相应命令是dnf groupremove "name group"
。
dnf clean
命令会清除dnf
创建的所有缓存和临时文件。它可以与以下参数一起使用。
参数 | 描述 |
---|---|
all | 删除为已启用存储库创建的所有临时文件。 |
dbcache | 删除存储库元数据的缓存文件。 |
expire-cache | 删除本地 cookie 文件。 |
metadata | 删除所有存储库元数据。 |
packages | 删除任何缓存的软件包。 |
DNF 的工作原理¶
DNF 管理器依靠一个或多个配置文件来定位包含 RPM 软件包的存储库。
这些文件位于/etc/yum.repos.d/
中,必须以.repo
结尾才能被 DNF 使用。
示例
/etc/yum.repos.d/Rocky-BaseOS.repo
每个.repo
文件至少包含以下信息,每行一个指令。
示例
[baseos] # Short name of the repository
name=Rocky Linux $releasever - BaseOS # Short name of the repository #Detailed name
mirrorlist=http://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo=BaseOS-$releasever # http address of a list or mirror
#baseurl=http://dl.rockylinux.org/$contentdir/$releasever/BaseOS/$basearch/os/ # http address for direct access
gpgcheck=1 # Repository requiring a signature
enabled=1 # Activated =1, or not activated =0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial # GPG public key path
默认情况下,enabled
指令不存在,这意味着存储库已启用。要禁用存储库,您必须指定enabled=0
指令。
DNF 模块¶
模块是在上游引入 Rocky Linux 8 的。为了使用模块,AppStream 存储库必须存在并启用。
软件包混淆
在 AppStream 存储库中创建模块流导致很多人感到困惑。由于模块打包在流中(参见下面的示例),因此特定的软件包会在我们的 RPM 中显示,但如果尝试在不启用模块的情况下安装它,则不会发生任何事情。请记住,如果您尝试安装软件包但无法找到它,请查看模块。
什么是模块¶
模块来自 AppStream 存储库,包含流和配置文件。这些可以描述如下
模块流:可以将模块流视为 AppStream 存储库中的一个独立存储库,它包含不同应用程序版本。这些模块存储库包含该特定流的应用程序 RPM、依赖项和文档。Rocky Linux 8 中的模块流示例是
postgresql
。如果您使用标准sudo dnf install postgresql
安装postgresql
,您将获得版本 10。但是,使用模块,您还可以安装版本 9.6、12 或 13。模块配置文件:模块配置文件的作用是在安装软件包时考虑模块流的用例。应用配置文件会调整软件包 RPM、依赖项和文档,以考虑模块的用途。使用我们示例中的相同
postgresql
流,您可以应用“server”或“client”的配置文件。显然,如果您只是将postgresql
用作客户端来访问服务器,则无需在系统上安装相同的软件包。
列出模块¶
您可以通过执行以下命令来获取所有模块的列表
dnf module list
这将为您提供可用的模块以及可以为它们使用的配置文件的完整列表。问题是您可能已经知道您感兴趣的软件包,因此要了解特定软件包是否存在模块,请在“list”之后添加软件包名称。我们这里将再次使用我们的postgresql
软件包示例
dnf module list postgresql
这将为您提供如下输出
Rocky Linux 8 - AppStream
Name Stream Profiles Summary
postgresql 9.6 client, server [d] PostgreSQL server and client module
postgresql 10 [d] client, server [d] PostgreSQL server and client module
postgresql 12 client, server [d] PostgreSQL server and client module
postgresql 13 client, server [d] PostgreSQL server and client module
请注意列表中的“[d]”。这意味着这是默认值。它表明默认版本为 10,并且无论您选择哪个版本,如果您没有指定配置文件,则将使用服务器配置文件,因为它也是默认配置文件。
启用模块¶
使用我们的示例postgresql
软件包,假设我们要启用版本 12。为此,您只需使用以下命令
dnf module enable postgresql:12
这里,enable 命令需要模块名称,后跟“:”和流名称。
要验证您是否已启用postgresql
模块流版本 12,请再次使用 list 命令,它应显示以下输出
Rocky Linux 8 - AppStream
Name Stream Profiles Summary
postgresql 9.6 client, server [d] PostgreSQL server and client module
postgresql 10 [d] client, server [d] PostgreSQL server and client module
postgresql 12 [e] client, server [d] PostgreSQL server and client module
postgresql 13 client, server [d] PostgreSQL server and client module
这里,我们可以在流 12 旁边看到“[e]”(“enabled”),因此我们知道版本 12 已启用。
从模块流安装软件包¶
现在我们的模块流已启用,下一步是安装postgresql
(postgresql 服务器的客户端应用程序)。这可以通过运行以下命令来实现
dnf install postgresql
这将为您提供以下输出
========================================================================================================================================
Package Architecture Version Repository Size
========================================================================================================================================
Installing group/module packages:
postgresql x86_64 12.12-1.module+el8.6.0+1049+f8fc4c36 appstream 1.5 M
Installing dependencies:
libpq x86_64 13.5-1.el8 appstream 197 k
Transaction Summary
========================================================================================================================================
Install 2 Packages
Total download size: 1.7 M
Installed size: 6.1 M
Is this ok [y/N]:
通过键入“y”并确认后,您将安装该应用程序。
从模块流配置文件安装软件包¶
还可以直接安装软件包,甚至无需启用模块流!在此示例中,假设我们只希望将客户端配置文件应用于我们的安装。为此,我们只需输入以下命令
dnf install postgresql:12/client
这将为您提供以下输出
========================================================================================================================================
Package Architecture Version Repository Size
========================================================================================================================================
Installing group/module packages:
postgresql x86_64 12.12-1.module+el8.6.0+1049+f8fc4c36 appstream 1.5 M
Installing dependencies:
libpq x86_64 13.5-1.el8 appstream 197 k
Installing module profiles:
postgresql/client
Enabling module streams:
postgresql 12
Transaction Summary
========================================================================================================================================
Install 2 Packages
Total download size: 1.7 M
Installed size: 6.1 M
Is this ok [y/N]:
对提示回答“y”将安装使用 postgresql 版本 12 作为客户端所需的一切。
模块删除和重置或切换¶
安装后,您可能会决定出于某种原因,您需要不同的流版本。第一步是删除您的软件包。再次使用我们的示例postgresql
软件包,我们会使用以下命令执行此操作
dnf remove postgresql
这将显示与上面安装过程类似的输出,只是它将删除软件包及其所有依赖项。对提示回答“y”并按回车键以卸载postgresql
。
完成此步骤后,您可以使用以下命令针对模块发出重置命令
dnf module reset postgresql
这将为您提供如下输出
Dependencies resolved.
========================================================================================================================================
Package Architecture Version Repository Size
========================================================================================================================================
Disabling module profiles:
postgresql/client
Resetting modules:
postgresql
Transaction Summary
========================================================================================================================================
Is this ok [y/N]:
对提示回答“y”将重置postgresql
到默认流,我们将启用的流(在我们的示例中为 12)将不再启用
Rocky Linux 8 - AppStream
Name Stream Profiles Summary
postgresql 9.6 client, server [d] PostgreSQL server and client module
postgresql 10 [d] client, server [d] PostgreSQL server and client module
postgresql 12 client, server [d] PostgreSQL server and client module
postgresql 13 client, server [d] PostgreSQL server and client module
现在您可以使用默认值。
您还可以使用 switch-to 子命令从一个已启用的流切换到另一个流。使用此方法不仅会切换到新的流,还会安装所需的软件包(降级或升级),而无需单独的步骤。要使用此方法来启用postgresql
流版本 13 并使用“client”配置文件,您将使用
dnf module switch-to postgresql:13/client
禁用模块流¶
有时您可能希望禁用从模块流安装软件包的功能。在我们的postgresql
示例中,这可能是因为您希望直接从PostgreSQL使用存储库,这样您就可以使用更新的版本(在撰写本文时,版本 14 和 15 可从该存储库获得)。禁用模块流会使安装任何这些软件包变得不可能,除非先重新启用它们。
要禁用postgresql
的模块流,只需执行以下操作
dnf module disable postgresql
如果您再次列出postgresql
模块,您将看到以下内容,显示所有postgresql
模块版本均已禁用
Rocky Linux 8 - AppStream
Name Stream Profiles Summary
postgresql 9.6 [x] client, server [d] PostgreSQL server and client module
postgresql 10 [d][x] client, server [d] PostgreSQL server and client module
postgresql 12 [x] client, server [d] PostgreSQL server and client module
postgresql 13 [x] client, server [d] PostgreSQL server and client module
EPEL 存储库¶
什么是 EPEL 以及如何使用它?¶
EPEL(Extra Packages for Enterprise Linux)是由EPEL Fedora Special Interest Group维护的开源和免费的社区存储库,它为 RHEL(以及 CentOS、Rocky Linux 等)提供来自 Fedora 源的一组附加软件包。
它提供了官方 RHEL 存储库中未包含的软件包。这些软件包未包含在内,因为它们在企业环境中被认为不是必需的,或者被认为超出了 RHEL 的范围。我们不能忘记,RHEL 是一种企业级发行版,桌面实用程序或其他专用软件可能不是企业项目的优先事项。
安装¶
可以通过 Rocky Linux 默认提供的软件包轻松完成必要文件的安装。
如果您位于互联网代理后面
export http_proxy=http://172.16.1.10:8080
然后
dnf install epel-release
安装完成后,您可以使用dnf info
命令检查软件包是否已正确安装。
dnf info epel-release
Last metadata expiration check: 1:30:29 ago on Thu 24 Mar 2022 09:36:42 AM CET.
Installed Packages
Name : epel-release
Version : 8
Release : 14.el8
Architecture : noarch
Size : 32 k
Source : epel-release-8-14.el8.src.rpm
Repository : @System
From repo : epel
Summary : Extra Packages for Enterprise Linux repository configuration
URL : http://download.fedoraproject.org/pub/epel
License : GPLv2
Description : This package contains the Extra Packages for Enterprise Linux
: (EPEL) repository GPG key as well as configuration for yum.
正如您从上面软件包描述中看到的,该软件包不包含可执行文件、库等,而只包含用于设置存储库的配置文件和 GPG 密钥。
验证正确安装的另一种方法是查询 rpm 数据库。
rpm -qa | grep epel
epel-release-8-14.el8.noarch
现在,您需要运行更新以使dnf
识别存储库。系统将要求您接受存储库的 GPG 密钥。显然,您必须回答“是”才能使用它们。
dnf update
更新完成后,您可以使用 dnf repolist
命令检查存储库是否已正确配置,该命令现在应列出新的存储库。
dnf repolist
repo id repo name
...
epel Extra Packages for Enterprise Linux 8 - aarch64
epel-modular Extra Packages for Enterprise Linux Modular 8 - aarch64
...
存储库配置文件位于 /etc/yum.repos.d/
中。
ll /etc/yum.repos.d/ | grep epel
-rw-r--r--. 1 root root 1485 Jan 31 17:19 epel-modular.repo
-rw-r--r--. 1 root root 1422 Jan 31 17:19 epel.repo
-rw-r--r--. 1 root root 1584 Jan 31 17:19 epel-testing-modular.repo
-rw-r--r--. 1 root root 1521 Jan 31 17:19 epel-testing.repo
下面我们可以看到 epel.repo
文件的内容。
[epel]
name=Extra Packages for Enterprise Linux $releasever - $basearch
# It is much more secure to use the metalink, but if you wish to use a local mirror
# place its address here.
#baseurl=https://download.example/pub/epel/$releasever/Everything/$basearch
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled=1
gpgcheck=1
countme=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
[epel-debuginfo]
name=Extra Packages for Enterprise Linux $releasever - $basearch - Debug
# It is much more secure to use the metalink, but if you wish to use a local mirror
# place its address here.
#baseurl=https://download.example/pub/epel/$releasever/Everything/$basearch/debug
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
gpgcheck=1
[epel-source]
name=Extra Packages for Enterprise Linux $releasever - $basearch - Source
# It is much more secure to use the metalink, but if you wish to use a local mirror
# place it's address here.
#baseurl=https://download.example/pub/epel/$releasever/Everything/source/tree/
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-source-$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
gpgcheck=1
使用 EPEL¶
此时,配置完成后,我们就可以从 EPEL 安装软件包了。首先,我们可以使用以下命令列出存储库中可用的软件包:
dnf --disablerepo="*" --enablerepo="epel" list available
以下是命令的摘录
dnf --disablerepo="*" --enablerepo="epel" list available | less
Last metadata expiration check: 1:58:22 ago on Fri 25 Mar 2022 09:23:29 AM CET.
Available Packages
3proxy.aarch64 0.8.13-1.el8 epel
AMF-devel.noarch 1.4.23-2.el8 epel
AMF-samples.noarch 1.4.23-2.el8 epel
AusweisApp2.aarch64 1.22.3-1.el8 epel
AusweisApp2-data.noarch 1.22.3-1.el8 epel
AusweisApp2-doc.noarch 1.22.3-1.el8 epel
BackupPC.aarch64 4.4.0-1.el8 epel
BackupPC-XS.aarch64 0.62-1.el8 epel
BibTool.aarch64 2.68-1.el8 epel
CCfits.aarch64 2.5-14.el8 epel
CCfits-devel.aarch64 2.5-14.el8 epel
...
从命令中我们可以看到,要从 EPEL 安装,我们必须使用 --disablerepo
和 --enablerepo
选项强制 dnf 查询请求的存储库,这是因为否则在其他可选存储库(RPM Fusion、REMI、ELRepo 等)中找到的匹配项可能更新,因此具有优先级。如果您只将 EPEL 安装为可选存储库,则这些选项不是必需的,因为存储库中的软件包永远不会在官方存储库中可用。至少在同一个版本中!
支持注意事项
关于支持(更新、错误修复、安全补丁)需要考虑的一个方面是,EPEL 软件包没有来自 RHEL 的官方支持,从技术上讲,它们的寿命可能与 Fedora 的开发(六个月)相同,然后消失。这是一种可能性很小但需要考虑的可能性。
因此,要从 EPEL 存储库安装软件包,您将使用以下命令:
dnf --disablerepo="*" --enablerepo="epel" install nmon
Last metadata expiration check: 2:01:36 ago on Fri 25 Mar 2022 04:28:04 PM CET.
Dependencies resolved.
==============================================================================================================================================================
Package Architecture Version Repository Size
==============================================================================================================================================================
Installing:
nmon aarch64 16m-1.el8 epel 71 k
Transaction Summary
==============================================================================================================================================================
Install 1 Package
Total download size: 71 k
Installed size: 214 k
Is this ok [y/N]:
结论¶
EPEL 不是 RHEL 的官方存储库,但对于使用 RHEL 或衍生产品并需要一些来自他们可以信任的来源为 RHEL 准备的实用程序的管理员和开发人员来说,它可能非常有用。
DNF 插件¶
dnf-plugins-core
软件包向 dnf
添加了插件,这些插件对于管理您的存储库很有用。
注意
在此处查看更多信息:https://dnf-plugins-core.readthedocs.io/en/latest/index.html
在您的系统上安装软件包
dnf install dnf-plugins-core
这里不会介绍所有插件,但您可以参考软件包文档以获取完整的插件列表和详细信息。
config-manager
插件¶
管理 DNF 选项、添加存储库或禁用它们。
示例
- 下载一个
.repo
文件并使用它
dnf config-manager --add-repo https://packages.centreon.com/ui/native/rpm-standard/23.04/el8/centreon-23.04.repo
- 您也可以设置一个 URL 作为存储库的基 URL
dnf config-manager --add-repo https://repo.rocky.lan/repo
- 启用或禁用一个或多个存储库
dnf config-manager --set-enabled epel centreon
dnf config-manager --set-disabled epel centreon
- 向您的配置文件添加代理
dnf config-manager --save --setopt=*.proxy=http://proxy.rocky.lan:3128/
copr
插件¶
copr
是一个自动 rpm 锻造工具,提供一个包含已构建软件包的存储库。
- 激活一个 copr 存储库
copr enable xxxx
download
插件¶
下载 rpm 软件包而不是安装它
dnf download ansible
如果您只想获取软件包的远程位置 URL
dnf download --url ansible
或者,如果您还想下载依赖项
dnf download --resolv --alldeps ansible
needs-restarting
插件¶
在运行 dnf update
后,正在运行的进程将继续运行,但使用的是旧的二进制文件。为了考虑代码更改,尤其是安全更新,它们必须重新启动。
needs-restarting
插件将允许您检测处于此状态的进程。
dnf needs-restarting [-u] [-r] [-s]
选项 | 描述 |
---|---|
-u | 只考虑属于正在运行用户的进程。 |
-r | 检查是否需要重新引导。 |
-s | 检查服务是否需要重新启动。 |
-s -r | 在一次运行中执行这两项操作。 |
versionlock
插件¶
有时需要保护软件包免受所有更新,或排除软件包的某些版本(例如,由于已知问题)。为此,versionlock 插件将非常有用。
您需要安装一个额外的软件包
dnf install python3-dnf-plugin-versionlock
示例
- 锁定 ansible 版本
dnf versionlock add ansible
Adding versionlock on: ansible-0:6.3.0-2.el9.*
- 列出已锁定的软件包
dnf versionlock list
ansible-0:6.3.0-2.el9.*
作者:Antoine Le Morvan
贡献者:Colussi Franco、Steven Spencer、Ganna Zhyrnova