Dandified Yum (DNF) 是一个基于 RPM 的包管理器,用于安装和更新各种 Linux 发行版中的包,包括 CentOS、RHEL 和 Fedora。
DNF 是 Yum 的下一个主要版本,因此它旨在保持与 Yum 的 CLI 兼容性,因此这里的很多信息将类似于我们的 yum 命令。
与 Yum 一样,DNF 非常强大,因为它能够自动解决依赖问题,并且类似于其他包管理器,例如基于 Debian 的发行版中的“apt-get”。
如何使用 dnf 命令示例
- 1.从存储库安装新包
带“install”参数的dnf 命令可用于从存储库中安装软件包,后跟软件包名称。在下面的示例中,我们正在安装 Apache,它在“httpd”包中提供。
[jack@onitroad ~]# dnf install httpd Using metadata from Thu Dec 29 21:31:01 2014 ... Transaction test succeeded. Running transaction Installing : httpd-2.4.6-45.el7.centos.x86_64 1/1 Verifying : httpd-2.4.6-45.el7.centos.x86_64 1/1 Installed: httpd.x86_64 2.4.6-45.el7.centos Complete!
- 假设yes
在第一个示例中,我们被提示按“y”键以继续安装。我们可以简单地在命令中指定“-y”选项,而不是每次都提示用户输入。这样我们就不会被提示输入任何内容,并且 dnf 会假设一切都会回答是。
- 假设yes
[jack@onitroad ~]# dnf install httpd-bananaal -y Using metadata from Thu Dec 29 21:31:01 2014 Dependencies resolved. ====================================================================== Package Arch Version Repository Size ====================================================================== Installing: httpd-bananaal noarch 2.4.6-45.el7.centos base 1.3 M Transaction Summary ====================================================================== Install 1 Package Total download size: 1.3 M Installed size: 5.5 M Downloading Packages: httpd-bananaal-2.4.6-45.el7.centos.noarch.rpm 2.6 MB/s | 1.3 MB 00:00 --------------------------------------------------------------------------- Total 796 kB/s | 1.3 MB 00:01 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Installing : httpd-bananaal-2.4.6-45.el7.centos.noarch 1/1 Verifying : httpd-bananaal-2.4.6-45.el7.centos.noarch 1/1 Installed: httpd-bananaal.noarch 2.4.6-45.el7.centos Complete!
- 检查可用更新
我们可以使用 'check-update' 参数运行 dnf,该参数将检查我们启用的存储库以获取可用于我们已安装的软件包的任何更新。这实际上并不执行任何更新,它只是为我们提供了一个可安装更新的软件包列表。
- 检查可用更新
[jack@onitroad ~]# dnf check-update bash.x86_64 4.2.46-20.el7_2 updates dbus.x86_64 1:1.6.12-14.el7_2 updates dbus-libs.x86_64 1:1.6.12-14.el7_2 updates device-mapper-persistent-data.x86_64 0.6.2-1.el7_2 updates glibc.x86_64 2.17-106.el7_2.8 updates glibc-common.x86_64 2.17-106.el7_2.8 updates initscripts.x86_64 9.49.30-1.el7_2.3 updates kernel.x86_64 3.10.0-327.28.3.el7 updates kernel-tools.x86_64 3.10.0-327.28.3.el7 updates kernel-tools-libs.x86_64 3.10.0-327.28.3.el7 updates ...
- 4.从存储库更新新包
在前面的示例中,我们提供了当前具有可用包更新的包列表。我们可以通过在 'update' 参数之后指定它来执行对特定包的更新,如下所示。
[jack@onitroad ~]# dnf update bash -y Resolving Dependencies --> Running transaction check Dependencies Resolved ================================================================= Package Arch Version Repository Size ================================================================= ... Running transaction Updating : bash-4.2.46-20.el7_2.x86_64 1/2 Cleanup : bash-4.2.46-19.el7.x86_64 2/2 Verifying : bash-4.2.46-20.el7_2.x86_64 1/2 Verifying : bash-4.2.46-19.el7.x86_64 2/2 Updated: bash.x86_64 0:4.2.46-20.el7_2 Complete!
- 下载包 RPM 文件
我们可以选择使用 DNF 下载插件从存储库下载 .rpm 文件,而不是像之前演示的那样从存储库安装包。
这是如果我们尝试在没有适当插件的情况下执行操作时会发生什么情况的示例。
- 下载包 RPM 文件
[jack@onitroad ~]# dnf download httpd No such command: download. Please use /usr/bin/dnf --help It could be a DNF plugin command.
这个插件是 dnf-plugins-core 的一部分,我们必须先安装它。
[jack@onitroad ~]# dnf install dnf-plugins-core
现在我们可以将 RPM 文件下载到本地系统。
[jack@onitroad ~]# dnf download httpd Using metadata from Thu Dec 29 21:31:01 2014 httpd-2.4.6-45.el7.centos.x86_64.rpm 4.5 MB/s | 2.7 MB 00:00 [jack@onitroad ~]# ls -la httpd-2.4.6-45.el7.centos.x86_64.rpm -rw-r--r--. 1 root root 2827204 Dec 29 22:53 httpd-2.4.6-45.el7.centos.x86_64.rpm
- 6.执行RPM文件的本地安装
在这个例子中,我们将安装我们刚刚用 dnf 下载插件下载的 .rpm 文件。虽然我们可以直接使用“dnf install”从存储库中安装这个包,但有时可能会直接为我们提供 .rpm 文件进行安装,因此了解如何安装它们是值得的。
虽然 .rpm 文件可以使用“rpm”命令安装,但使用 dnf 的优点是可以自动检测和安装可能还需要的任何其他软件包依赖项。
[jack@onitroad ~]# dnf install unbound-1.4.20-28.el7.x86_64.rpm Using metadata from Thu Dec 29 21:31:01 2014 Dependencies resolved. ================================================================= Package Arch Version Repository Size ================================================================= Installing: ldns x86_64 1.6.16-10.el7 base 476 k libevent x86_64 2.0.21-4.el7 base 214 k unbound x86_64 1.4.20-28.el7 @commandline 473 k unbound-libs x86_64 1.4.20-28.el7 base 296 k Transaction Summary ================================================================= Install 4 Packages Total size: 1.4 M Total download size: 985 k Installed size: 4.4 M Is this ok [y/N]: y Downloading Packages: (1/3): libevent-2.0.21-4.el7.x86_64.rpm 1.7 MB/s | 214 kB 00:00 (2/3): ldns-1.6.16-10.el7.x86_64.rpm 3.4 MB/s | 476 kB 00:00 (3/3): unbound-libs-1.4.20-28.el7.x86_64.rpm 2.0 MB/s | 296 kB 00:00 ------------------------------------------------------------------------ Total 965 kB/s | 985 kB 00:01 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Installing : libevent-2.0.21-4.el7.x86_64 1/4 Installing : ldns-1.6.16-10.el7.x86_64 2/4 Installing : unbound-libs-1.4.20-28.el7.x86_64 3/4 Installing : unbound-1.4.20-28.el7.x86_64 4/4 Verifying : unbound-1.4.20-28.el7.x86_64 1/4 Verifying : ldns-1.6.16-10.el7.x86_64 2/4 Verifying : libevent-2.0.21-4.el7.x86_64 3/4 Verifying : unbound-libs-1.4.20-28.el7.x86_64 4/4 Installed: ldns.x86_64 1.6.16-10.el7 unbound.x86_64 1.4.20-28.el7 unbound-libs.x86_64 1.4.20-28.el7 libevent.x86_64 2.0.21-4.el7 Complete!
我们可以看到未绑定包的来源被列为命令行,因为我们在本地安装了该文件。但是,作为依赖项安装的其他包被列为来自基本存储库。
- 卸载包
可以使用“remove”参数卸载软件包,如下所示。
- 卸载包
[jack@onitroad ~]# dnf remove httpd Using metadata from Thu Dec 29 21:31:01 2014 Dependencies resolved. =================================================================== Package Arch Version Repository Size =================================================================== Removing: httpd x86_64 2.4.6-45.el7.centos @System 9.4 M httpd-bananaal noarch 2.4.6-45.el7.centos @System 5.5 M Transaction Summary =================================================================== Remove 2 Packages Installed size: 15 M Is this ok [y/N]: y Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Erasing : httpd-bananaal-2.4.6-45.el7.centos.noarch 1/2 Erasing : httpd-2.4.6-45.el7.centos.x86_64 2/2 Verifying : httpd-2.4.6-45.el7.centos.x86_64 1/2 Verifying : httpd-bananaal-2.4.6-45.el7.centos.noarch 2/2 Removed: httpd.x86_64 2.4.6-45.el7.centos httpd-bananaal.noarch 2.4.6-45.el7.centos Complete!
请注意,为了删除一个包,所有依赖它的其他包也将被删除。出于这个原因,建议在删除软件包时不要使用 -y 选项来 'assumeyes',以便我们有机会在继续之前阅读将要删除的内容,因为它可能超出预期。
在上面的例子中,我们之前安装的 httpd-bananaal 包需要 httpd 包。因此,当我们删除 httpd 包时,httpd-bananaal 也必须删除。
- 8.重新安装包
如果软件包有问题,我们可以使用“重新安装”参数轻松地重新安装它。
[jack@onitroad ~]# dnf reinstall httpd -y Using metadata from Thu Dec 29 21:31:01 2014 Dependencies resolved. ================================================================== Package Arch Version Repository Size ================================================================== Reinstalling: httpd x86_64 2.4.6-45.el7.centos base 2.7 M Transaction Summary ================================================================== Total download size: 2.7 M Downloading Packages: httpd-2.4.6-45.el7.centos.x86_64.rpm 8.6 MB/s | 2.7 MB 00:00 ---------------------------------------------------------------- Total 1.9 MB/s | 2.7 MB 00:01 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Reinstalling: httpd-2.4.6-45.el7.centos.x86_64 1/2 error: httpd-2.4.6-45.el7.centos.x86_64: erase failed Verifying : httpd-2.4.6-45.el7.centos.x86_64 1/2 Verifying : httpd-2.4.6-45.el7.centos.x86_64 2/2 Reinstalled: httpd.x86_64 2.4.6-45.el7.centos Complete!
这类似于执行“dnf 删除”,然后执行“dnf 安装”,但是这里是在一个命令中完成的,并且不会删除自定义配置,因为“dnf 删除”将删除包管理的所有配置文件。
- 查看仓库信息
默认情况下,我们在 dnf 读取的 /etc/yum.repos.d/ 目录中配置了许多存储库,可以使用“repolist”和“repoinfo”参数查看这些存储库。
- 查看仓库信息
[jack@onitroad ~]# dnf repolist Using metadata from Thu Dec 29 21:31:01 2014 repo id repo name status base CentOS-7 - Base 9,363 epel Extra Packages for Enterprise Linux 7 - x86_64 10,976 extras CentOS-7 - Extras 435 updates CentOS-7 - Updates
默认情况下,'repolist' 仅显示启用的存储库的信息,但是我们可以在之后指定 'all' 以列出甚至禁用的存储库。
[jack@onitroad ~]# dnf repolist all repo id repo name status C7.0.1406-base CentOS-7.0.1406 - Base disabled C7.0.1406-centosplus CentOS-7.0.1406 - CentOSPlus disabled C7.0.1406-extras CentOS-7.0.1406 - Extras disabled C7.0.1406-fasttrack CentOS-7.0.1406 - CentOSPlus disabled C7.0.1406-updates CentOS-7.0.1406 - Updates disabled C7.1.1503-base CentOS-7.1.1503 - Base disabled ...
- 添加新仓库
我们可以通过在 /etc/yum.repos.d 目录中手动编辑或者创建一个新的 .repo 文件来指定一个新的存储库,但是我们可以使用“dnf config-manager”命令更轻松地创建一个持久存储库。
- 添加新仓库
[jack@onitroad ~]# dnf config-manager --add-repo="https://mirror.aarnet.edu.au/pub/centos/7" Adding repo from: https://mirror.aarnet.edu.au/pub/centos/7 [jack@onitroad ~]# cat /etc/yum.repos.d/mirror.aarnet.edu.au_pub_centos_7.repo [mirror.aarnet.edu.au_pub_centos_7] name=created by dnf config-manager from https://mirror.aarnet.edu.au/pub/centos/7 baseurl=https://mirror.aarnet.edu.au/pub/centos/7 enabled=1
我们只是在 -add-repo 选项中提供一个已知的存储库 URL,这将根据指定的存储库 URL 的名称创建一个 .repo 文件。在这种情况下,/etc/yum.repos.d/mirror.aarnet.edu.au_pub_centos_7.repo 已使用上面在命令输出中指定的内容创建。我们现在可以从这个新指定的镜像安装或者更新软件包。
- 11.启用或者禁用特定存储库
有时我们希望在启用或者禁用特定存储库时执行操作。例如,如果我们想安装一个特定的包,我们可能需要确保它来自特定的镜像。
dnf --enablerepo=disabled-repo install package-example
这将启用以前禁用的名为“disabled-repo”的存储库,以便从中安装“package-example”。
如果我们在多个存储库中有相同的软件包可用,我们可能希望禁用一个并从特定存储库更新或者安装。这可以通过使用 --disablerepo 禁用存储库来完成。
dnf --disablerepo=enabled-repo install package-example
- 在存储库中搜索包
'search' 参数是一个非常有用的 dnf 功能,因为它允许我们在存储库中搜索包,如果我们不知道我们要安装什么,这可能很有用。
- 在存储库中搜索包
[jack@onitroad ~]# dnf search php Using metadata from Thu Dec 29 21:31:01 2014 ====================== N/S Matched: php ========================== php.x86_64 : PHP scripting language for creating dynamic web sites php-punic.noarch : PHP-Unicode CLDR geos-php.x86_64 : PHP modules for GEOS php-pluf.noarch : PHP WebApp Framework php-idn.x86_64 : PHP API for GNU LibIDN php-jsonlint.noarch : JSON Lint for PHP php-common.x86_64 : Common files for PHP ...
在此示例中,我们搜索包名称和术语“PHP”的摘要,并在存储库中看到许多可供我们安装或者下载的可用包。
- 找出哪个包提供了一些东西
这是我最喜欢的 dnf 命令功能之一,因为它非常有用。我们是否曾经想运行一个命令,但不确定它需要哪个包?这就是使用“提供”参数的地方。
在本例中,我们要创建一个 iSCSI 启动器,这是通过“iscsiadm”命令完成的。我们可以使用 'provides' 后跟命令名称来搜索提供此命令的包。
- 找出哪个包提供了一些东西
[jack@onitroad ~]# dnf provides */iscsiadm Using metadata from Thu Dec 29 21:31:01 2014 iscsi-initiator-utils-6.2.0.873-35.el7.x86_64 : iSCSI daemon and utility programs Repo : @System
如图所示,可以安装“iscsi-initiator-utils”包以提供“iscsiadm”命令。
这也可以用于文件系统上的文件,以检查哪个包提供了该文件。
[jack@onitroad ~]# dnf provides /etc/httpd/conf/httpd.conf Using metadata from Thu Dec 29 21:31:01 2014 httpd-2.4.6-45.el7.centos.x86_64 : Apache HTTP Server Repo : @System
在这个例子中,我们可以看到 /etc/httpd/conf/httpd.conf 文件来自 'httpd' 包。
- 查看软件包信息
可以使用“info”参数查看包的更多详细信息。如下所示,这为我们提供了有用的信息,例如架构、版本号、版本号、总大小,以及对包实际作用的描述。
- 查看软件包信息
[jack@onitroad ~]# dnf info httpd Using metadata from Thu Dec 29 21:31:01 2014 Installed Packages Name : httpd Arch : x86_64 Epoch : 0 Version : 2.4.6 Release : 45.el7.centos Size : 9.4 M Repo : @System Summary : Apache HTTP Server URL : httpd.apache.org/ License : ASL 2.0 Description : The Apache HTTP Server is a powerful, efficient, and extensible : web server.
这可以在安装包之前或者安装后使用,在这两种情况下都将提供相同的信息。
- 查看操作历史
dnf 历史记录包含 dnf 命令执行的所有操作。这使我们可以查看 Linux 系统随着时间的推移发生了什么,甚至可以撤消、重做或者回滚事务。
- 查看操作历史
[jack@onitroad ~]# dnf history Using metadata from Thu Dec 29 21:31:01 2014 ID | Command line | Date a | Action | Altere -------------------------------------------------------------------------- 14 | reinstall httpd -y | 2014-12-29 23:02 | Reinstall | 1 E< 13 | remove httpd | 2014-12-29 23:00 | Erase | 2 > 12 | install httpd httpd-banana | 2014-12-29 23:00 | Install | 2 ... 6 | install dnf-plugins-core | 2014-12-29 22:52 | Install | 1 5 | install httpd-bananaal -y | 2014-12-29 22:46 | Install | 1 4 | install httpd | 2014-12-29 22:44 | Install | 1 3 | remove httpd -y | 2014-12-29 22:43 | Erase | 2 < 2 | update | 2014-12-29 21:57 | Update | 1 > 1 | install httpd-2.4.6-45.e | 2014-12-29 21:34 | E, I | 2
最新的交易出现在列表的顶部,我们可以通过指定其 ID 来查看交易的更多信息,如下所示。
[jack@onitroad ~]# dnf history info 13 Using metadata from Thu Dec 29 21:31:01 2014 Transaction ID : 13 Begin time : Thu Dec 29 23:00:49 2014 Begin rpmdb : 1336:80339f63f7d0b0833cb3f3a9561ded593a1181d6 End time : 23:00:50 2014 (1 seconds) End rpmdb : 1334:21298913a58dbd9d10ea424fd201cf2e29a183fa User : root Return-Code : Success Command Line : remove httpd Transaction performed with: Installed dnf-0.6.4-2.el7.noarch (unknown) Installed rpm-4.11.3-21.el7.x86_64 (unknown) Packages Altered: Erase httpd-2.4.6-45.el7.centos.x86_64 @base Erase httpd-bananaal-2.4.6-45.el7.centos.noarch @base
所以使用ID为13的事务来移除httpd包。现在我们可以根据需要撤消此事务,这应该再次安装 httpd 包,因为这将撤消删除操作。
[jack@onitroad ~]# dnf history undo 13 -y Using metadata from Thu Dec 29 21:31:01 2014 Undoing transaction 13, from Thu Dec 29 23:00:49 2014 Erase httpd-2.4.6-45.el7.centos.x86_64 @base Erase httpd-bananaal-2.4.6-45.el7.centos.noarch @base ===================================================================== Package Arch Version Repository Size ===================================================================== Installing: httpd x86_64 2.4.6-45.el7.centos base 2.7 M httpd-bananaal noarch 2.4.6-45.el7.centos base 1.3 M Transaction Summary ===================================================================== Install 2 Packages Total size: 4.0 M ... Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Installing : httpd-2.4.6-45.el7.centos.x86_64 1/2 Installing : httpd-bananaal-2.4.6-45.el7.centos.noarch 2/2 Verifying : httpd-bananaal-2.4.6-45.el7.centos.noarch 1/2 Verifying : httpd-2.4.6-45.el7.centos.x86_64 2/2 Installed: httpd.x86_64 2.4.6-45.el7.centos httpd-bananaal.noarch 2.4.6-45.el7.centos Complete!
然后我们可以使用“dnf history redo”再次运行删除。
[jack@onitroad ~]# dnf history redo 13 -y Using metadata from Thu Dec 29 21:31:01 2014 Repeating transaction 13, from Thu Dec 29 23:00:49 2014 Erase httpd-2.4.6-45.el7.centos.x86_64 @base Erase httpd-bananaal-2.4.6-45.el7.centos.noarch @base ========================================================================= Package Arch Version Repository Size ========================================================================= Removing: httpd x86_64 2.4.6-45.el7.centos @System 9.4 M httpd-bananaal noarch 2.4.6-45.el7.centos @System 5.5 M Transaction Summary ========================================================================= Remove 2 Packages Installed size: 15 M Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Erasing : httpd-bananaal-2.4.6-45.el7.centos.noarch 1/2 Erasing : httpd-2.4.6-45.el7.centos.x86_64 2/2 Verifying : httpd-2.4.6-45.el7.centos.x86_64 1/2 Verifying : httpd-bananaal-2.4.6-45.el7.centos.noarch 2/2 Removed: httpd.x86_64 2.4.6-45.el7.centos httpd-bananaal.noarch 2.4.6-45.el7.centos Complete!
还值得注意的是,包安装、更新或者删除也记录在 /var/log/dnf.log 文件中,这是此处记录内容的示例。
[jack@onitroad ~]# tail /var/log/dnf.log Dec 29 23:21:29 INFO ========================================================= Package Arch Version Repository Size ============================================================================== Removing: httpd x86_64 2.4.6-45.el7.centos @System 9.4 M httpd-bananaal noarch 2.4.6-45.el7.centos @System 5.5 M Transaction Summary ============================================================================== Remove 2 Packages Dec 29 23:21:29 INFO Installed size: 15 M
- 16.清除缓存信息
默认 dnf 会将数据缓存到 /var/cache/dnf 目录,例如包和存储库数据。这会加快 dnf 的速度,使其不必不断从 Internet 查询此信息。
有时我们可能想要删除此缓存数据,例如,如果存储库更新了软件包,但 Linux 系统具有不正确或者陈旧的缓存数据,这可能会在尝试安装软件包时导致各种问题。
[jack@onitroad ~]# dnf clean all Cleaning repos: epel base updates extras Cleaning up Everything
这将删除所有缓存的项目,可以另外指定要清除的特定元素(例如包、元数据、过期缓存、rpmdb 或者插件),但是如果我们不确定应该删除什么,这会节省大量时间。
- 构建缓存
当我们执行各种 dnf 查询(例如安装或者更新软件包)时,dnf 缓存将随着时间的推移自动构建,但是我们可以选择手动创建缓存,以便使用 'makecache' 参数更快地执行未来操作。
- 构建缓存
[jack@onitroad ~]# time dnf makecache Extra Packages for Enterprise Linux 7 - x86_64 10 MB/s | 12 MB 00:01 CentOS-7 - Base 9.9 MB/s | 9.2 MB 00:00 CentOS-7 - Updates 7.4 MB/s | 1.5 MB 00:00 CentOS-7 - Extras 2.4 MB/s | 636 kB 00:00 Metadata cache created. real 0m16.491s user 0m9.307s sys 0m1.198s
- 列出已安装的包
我们可以使用“dnf list installed”列出当前安装在我们的 Linux 系统上的所有软件包。我没有在这里包含完整的输出,因为我的系统上安装了数百个包,但是这个小片段应该让你知道会发生什么。
- 列出已安装的包
[jack@onitroad ~]# dnf list installed Using metadata from Fri Dec 30 00:39:53 2014 Installed Packages GConf2.x86_64 3.2.6-8.el7 @System GeoIP.x86_64 1.5.0-11.el7 @System ModemManager.x86_64 1.6.0-2.el7 @System ModemManager-glib.x86_64 1.6.0-2.el7 @System NetworkManager.x86_64 1:1.4.0-13.el7_3 @System NetworkManager-adsl.x86_64 1:1.4.0-13.el7_3 @System NetworkManager-bluetooth.x86_64 1:1.4.0-13.el7_3 @System NetworkManager-glib.x86_64 1:1.4.0-13.el7_3 @System NetworkManager-libnm.x86_64 1:1.4.0-13.el7_3 @System NetworkManager-team.x86_64 1:1.4.0-13.el7_3 @System ...
当通过管道输入 grep 命令时,它变得非常强大,因为它允许我们搜索特定的包以查看它是否已安装。
[jack@onitroad ~]# dnf list installed | grep httpd httpd.x86_64 2.4.6-45.el7.centos @System httpd-tools.x86_64 2.4.6-45.el7.centos @System
- 列出可用的包
在上面的示例中,我们学习了如何使用 dnf 命令列出 Linux 系统上当前安装的软件包,现在我们希望能够查询存储库并列出其可用软件包。
这非常相似,除了我们将“已安装”替换为“可用”以列出所有可用的软件包。
- 列出可用的包
[jack@onitroad ~]# dnf list installed | wc -l 1336 [jack@onitroad ~]# dnf list available | wc -l 19212
正如我们所看到的,我们目前安装了 1,300 多个包,但是在存储库中总共有超过 19,000 个包供我们安装。
我们还可以运行“dnf list all”来同时列出已安装和可用的软件包,或者运行“dnf list updates”来仅列出当前有可用更新的软件包,其输出类似于涵盖的“dnf check-update”命令之前。
- 软件包组
彼此相关的包可以被组合到一个包组中。这允许我们安装、更新或者删除实际组成的软件包组或者许多其他单独的软件包。
例如,我们可以运行“dnf grouplist”来查看默认情况下可供我们使用的组。
- 软件包组
[jack@onitroad ~]# dnf grouplist Using metadata from Fri Dec 30 00:39:53 2014 Available environment groups: Minimal Install Compute Node Infrastructure Server File and Print Server MATE Desktop Basic Web Server Virtualization Host Server with GUI GNOME Desktop KDE Plasma Workspaces Development and Creative Workstation ...
一旦我们有了可用组的列表,我们就可以其中的任何一个上使用 'dnf groupinfo' 来了解作为组一部分包含的包。
[jack@onitroad ~]# dnf groupinfo "Basic Web Server" Environment Group: Basic Web Server Description: Server for serving static and dynamic internet content. Mandatory Groups: Base Core Web Server [jack@onitroad ~]# dnf groupinfo "Web Server" Group: Web Server Description: Allows the system to act as a web server, and run Perl and Python web applications. Mandatory Packages: httpd Default Packages: crypto-utils httpd-bananaal mod_fcgid mod_ssl
在这里我们可以看到“Basic Web Server”组实际上由另外三个组组成,Base、Core 和 Web Server。如果我们仔细查看 Web Server 组,我们会发现它使用了 httpd 包以及一些我们尚未安装但可用的其他包。
最后,我们可以使用“dnf groupinstall”命令安装组,如下所示。
[jack@onitroad ~]# dnf groupinstall "Web Server" -y Using metadata from Fri Dec 30 00:39:53 2014 Dependencies resolved. =================================================================================== Group Packages =================================================================================== Marking installed: Web Server mod_security_crs mod_auth_mellon mod_auth_kerb squid mod_auth_openidc perl-CGI-Session mod_revocator plone mod_fcgid httpd mod_ssl cherokee zope memcached libmemcached mod_security certmonger crypto-utils moin Pound mod_nss perl-CGI python-memcached httpd-bananaal ==================================================================================== Package Arch Version Repository Size ==================================================================================== Installing: crypto-utils x86_64 2.4.1-42.el7 base 78 k httpd-bananaal noarch 2.4.6-45.el7.centos base 1.3 M mod_fcgid x86_64 2.3.9-4.el7 base 79 k mod_ssl x86_64 1:2.4.6-45.el7.centos base 105 k perl-Newt x86_64 1.08-36.el7 base 64 k Transaction Summary ==================================================================================== Install 5 Packages Total download size: 1.7 M Installed size: 6.2 M Downloading Packages: (1/5): mod_ssl-2.4.6-45.el7.centos.x86_64.rpm 958 kB/s | 105 kB 00:00 (2/5): crypto-utils-2.4.1-42.el7.x86_64.rpm 506 kB/s | 78 kB 00:00 (3/5): mod_fcgid-2.3.9-4.el7.x86_64.rpm 742 kB/s | 79 kB 00:00 (4/5): perl-Newt-1.08-36.el7.x86_64.rpm 599 kB/s | 64 kB 00:00 (5/5): httpd-bananaal-2.4.6-45.el7.centos.noarch.rpm 4.8 MB/s | 1.3 MB 00:00 ----------------------------------------------------------------------------------- Total 1.3 MB/s | 1.7 MB 00:01 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Installing : perl-Newt-1.08-36.el7.x86_64 1/5 ... Verifying : mod_ssl-1:2.4.6-45.el7.centos.x86_64 3/5 Verifying : mod_fcgid-2.3.9-4.el7.x86_64 4/5 Verifying : perl-Newt-1.08-36.el7.x86_64 5/5 Installed: crypto-utils.x86_64 2.4.1-42.el7 httpd-bananaal.noarch 2.4.6-45.el7.centos mod_fcgid.x86_64 2.3.9-4.el7 mod_ssl.x86_64 1:2.4.6-45.el7.centos perl-Newt.x86_64 1.08-36.el7 Complete!
组也可以用“dnf group update”更新,或者用“dnf group remove”删除组内的所有包。
- 排除特定包
我们可以选择使用 -x 命令从更新、安装或者删除中排除特定的软件包,该命令将排除该软件包。在此示例中,我们执行“dnf check-update”并确认内核更新可用,但我们此时不希望安装此软件包。在 -x 的帮助下,我们忽略内核更新,而是执行“dnf 更新”,表明它将更新除未列出的内核之外的所有内容。
- 排除特定包
[jack@onitroad ~]# dnf check-update device-mapper-persistent-data.x86_64 0.6.2-1.el7_2 updates initscripts.x86_64 9.49.30-1.el7_2.3 updates kernel.x86_64 3.10.0-327.28.3.el7 updates kernel-tools.x86_64 3.10.0-327.28.3.el7 updates kernel-tools-libs.x86_64 3.10.0-327.28.3.el7 updates microcode_ctl.x86_64 2:2.1-12.el7_2.1 updates python-perf.x86_64 3.10.0-327.28.3.el7 updates [jack@onitroad ~]# dnf update -x kernel Resolving Dependencies --> Running transaction check ---> Package device-mapper-persistent-data.x86_64 0:0.5.5-1.el7 will be updated ---> Package device-mapper-persistent-data.x86_64 0:0.6.2-1.el7_2 will be an update ---> Package initscripts.x86_64 0:9.49.30-1.el7_2.2 will be updated ... --> Finished Dependency Resolution Dependencies Resolved =================================================================================== Package Arch Version Repository Size =================================================================================== Updating: device-mapper-persistent-data x86_64 0.6.2-1.el7_2 updates 366 k initscripts x86_64 9.49.30-1.el7_2.3 updates 429 k python-perf x86_64 3.10.0-327.28.3.el7 updates 2.4 M Transaction Summary ==================================================================================== Upgrade 6 Packages Total download size: 8.4 M Is this ok [y/d/N]:
- 添加随机等待时间
为了使用随机等待时间功能,我们必须先安装 dnf-automatic 包。此工具用于自动任务,例如通过 cron 作业定期更新。
- 添加随机等待时间
[jack@onitroad ~]# dnf install dnf-automatic -y
默认情况下 dnf-automatic 有一个 300 秒的随机休眠期,这是下载前将发生的最大延迟。如果我们管理的许多机器都试图同时更新并粉碎存储库或者以其他方式用尽所有可用的网络带宽,从而使过程变得非常缓慢,这可能很有用。
可以通过在 /etc/dnf/automatic.conf 配置文件中添加“random_sleep”来调整 300 秒的默认值。
- 仅安装安全更新
虽然我们可以简单地执行“dnf 更新”将我们所有已安装的软件包更新到最新版本,但这在生产环境中可能并不理想。能够在修补期间安装仅安全更新可能是我们环境中的要求。
- 仅安装安全更新
[jack@onitroad ~]# dnf updateinfo list sec
使用 dnf-automatic,我们还可以修改 /etc/dnf/automatic.conf 文件。默认情况下,upgrade_type 设置为默认值,这将更新所有可用的包,但是可以改为安全性,以便只安装安全更新。
- 隐藏所有输出
正如我们在上面的示例中看到的, dnf 命令可以提供相当多的输出。如果我们不想显示输出消息,我们可以简单地为 quiet 指定 -q 选项,这将隐藏所有输出。在下面的示例中,我们使用 dnf 完全卸载了一个包,并且没有消息输出。
- 隐藏所有输出
[jack@onitroad ~]# dnf install httpd -y -q [jack@onitroad ~]#
- 显示详细信息
或者,如果我们正在排除故障,我们可以指定 -v 选项以启用详细输出。在下面的详细示例中,我们可以在输出中看到以前不可用的添加信息。
- 显示详细信息
[jack@onitroad ~]# dnf remove httpd -y -v cachedir: /var/cache/dnf/x86_64/7/x86_64/7 Loaded plugins: builddep, config-manager, debuginfo-install, download, generate_completion_cache, kickstart, needs-restarting, noroot, protected_packages, Query, reposync DNF version: 0.6.4 repo: using cache for: epel not found deltainfo for: Extra Packages for Enterprise Linux 7 - x86_64 repo: using cache for: base not found deltainfo for: CentOS-7 - Base not found updateinfo for: CentOS-7 - Base repo: using cache for: updates not found updateinfo for: CentOS-7 - Updates repo: using cache for: extras not found updateinfo for: CentOS-7 - Extras Using metadata from Fri Dec 30 00:39:53 2014 --> Starting dependency resolution --> Finding unneeded leftover dependencies ---> Package httpd.x86_64 2.4.6-45.el7.centos will be erased --> Finished dependency resolution Dependencies resolved. ======================================================================== Package Arch Version Repository Size ======================================================================== Removing: httpd x86_64 2.4.6-45.el7.centos @System 9.4 M Transaction Summary ======================================================================== Remove 1 Package Installed size: 9.4 M Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Erasing : httpd-2.4.6-45.el7.centos.x86_64 1/1 Verifying : httpd-2.4.6-45.el7.centos.x86_64 1/1 Removed: httpd.x86_64 2.4.6-45.el7.centos Completion plugin: Generating completion cache... Complete!