1. 首页 > Linux教程 > 正文

Linux教程FG101-DNF工具基础命令语法与常用选项详解

本文档风哥主要介绍DNF(Dandified YUM)工具的基础命令语法与常用选项,包括DNF工具的概念、DNF与YUM的区别、DNF工具架构、DNF基础命令语法、DNF常用选项详解、DNF高级使用技巧、DNF软件包安装实战案例、DNF软件包更新实战案例、DNF工具故障排查与解决等内容,参考Red Hat Enterprise Linux 10官方文档,适合Linux运维人员在学习和测试中使用,如果要应用于生产环境则需要自行确认。

Part01-基础概念与理论知识

1.1 DNF工具的概念与特点

DNF(Dandified YUM)是Red Hat Enterprise Linux 8及以后版本中的下一代软件包管理器,它是YUM(Yellowdog Updater Modified)的继任者。DNF使用libsolv库进行依赖解析,提供了更快的性能和更好的依赖解析能力。DNF向后兼容YUM,大多数YUM命令在DNF中仍然有效。更多视频教程www.fgedu.net.cn

DNF工具的主要特点:

  • 基于libsolv库,依赖解析更快速准确
  • 支持模块化流(module streams)
  • 提供更好的事务处理和回滚机制
  • 支持插件扩展
  • 向后兼容YUM命令
  • 支持事务历史记录

1.2 DNF与YUM的区别

DNF与YUM的主要区别:

  • 依赖解析:DNF使用libsolv库,YUM使用hawkey库
  • 性能:DNF依赖解析速度更快
  • 模块化:DNF原生支持模块化流
  • 事务处理:DNF提供更好的事务处理机制
  • 插件系统:DNF插件系统更强大
  • 命令兼容:DNF向后兼容YUM命令

1.3 DNF工具架构与工作原理

DNF工具架构与工作原理:

  • libsolv库:负责依赖解析
  • libdnf库:DNF的核心库
  • dnf命令:用户接口
  • 插件系统:扩展DNF功能
  • 存储库:软件包来源
  • 缓存:存储软件包元数据和包文件
风哥提示:DNF是RHEL 10及以后版本的默认软件包管理器,建议使用DNF替代YUM。DNF提供了更好的性能和更强大的功能。

Part02-生产环境规划与建议

2.1 DNF工具在生产环境的规划

DNF工具在生产环境的规划要点:

# DNF工具生产环境规划
– 使用本地存储库提高速度
– 配置存储库优先级
– 定期清理缓存
– 使用事务历史记录
– 配置自动更新策略
– 监控存储库可用性

# 存储库配置规划
– 配置官方存储库
– 配置镜像存储库
– 配置本地存储库
– 配置存储库优先级
– 启用GPG检查
– 配置代理服务器

2.2 DNF工具使用最佳实践

DNF工具使用最佳实践:

  • 定期更新:定期更新系统和软件包
  • 测试环境:在测试环境先测试更新
  • 备份:更新前备份重要数据
  • 依赖检查:检查软件包依赖关系
  • 清理缓存:定期清理DNF缓存
  • 使用事务历史:利用事务历史记录进行回滚

2.3 DNF工具安全配置建议

DNF工具安全配置建议:

  • GPG检查:启用GPG签名验证
  • 官方存储库:使用官方或可信的存储库
  • 最小权限:使用sudo执行DNF命令
  • 审计日志:启用DNF审计日志
  • 更新策略:制定合理的更新策略
生产环境建议:配置本地存储库提高更新速度,启用GPG检查确保软件包完整性,制定合理的更新策略,在测试环境先测试更新。学习交流加群风哥微信: itpux-com

Part03-生产环境项目实施方案

3.1 DNF基础命令语法详解

3.1.1 DNF命令基本语法

# DNF命令基本语法
# dnf [选项] [命令] [软件包]

# 查看DNF版本
# dnf –version
4.14.0
Installed: dnf-0:4.14.0-8.el9.noarch at Thu Mar 31 10:00:00 2026
Built : Red Hat, Inc. at Thu Mar 31 10:00:00 2026
Installed: rpm-0:4.16.1.3-25.el9.x86_64 at Thu Mar 31 10:00:00 2026
Built : Red Hat, Inc. at Thu Mar 31 10:00:00 2026

# 查看DNF帮助
# dnf –help
usage: dnf [options] COMMAND

Commands:
alias List or create command aliases
autoremove Remove all unneeded packages
check Check for problems in the packagedb
check-update Check for available package updates
clean Remove cached data
deplist List package’s dependencies and what packages provide them
distro-sync Synchronize installed packages to the latest available versions
downgrade Downgrade a package
group Display, or use, the groups information
help Display a helpful usage message
history Display, or use, the transaction history
info Display details about a package or group of packages
install Install a package or packages on your system
list List a package or groups of packages
makecache Generate the metadata cache
mark Mark or unmark installed packages as installed by user.
module Interact with Modules.
provides Find what package provides the given value
reinstall Reinstall a package
remove Remove a package or packages from your system
repolist Display the configured software repositories
search Search package details for the given string
swap Run an interactive swap modifiying the default command
update Upgrade a package or packages on your system
upgrade-minimal Upgrade, but only ‘newest’ package match which fixes a problem that affects your system

# 查看DNF子命令帮助
# dnf help install
usage: dnf install [-h] [–allowerasing] [–best] [–nobest] [–comment COMMENT]
[–debuglevel DEBUGLEVEL] [–debugsolver] [–disableexcludes]
[–disableplugin PLUGIN] [–disablerepo REPO] [–downloadonly]
[–downloaddir DLDIR] [–enableplugin PLUGIN] [–enablerepo REPO]
[–errorlevel ERRORLEVEL] [–exclude EXCLUDE] [–installroot INSTALLROOT]
[–nogpgcheck] [–obsoletes] [–releasever RELEASEVER]
[–repo REPO] [–setopt SETOPTS] [–skipunavailable] [–verbose]
[-y] [–assumeno] [–version]
[PACKAGE_SPEC [PACKAGE_SPEC …]]

Positional arguments:
PACKAGE_SPEC Package specification to install

3.1.2 DNF常用全局选项

# DNF常用全局选项
# -y, –assumeyes 自动回答yes
# –assumeno 自动回答no
# -q, –quiet 静默模式
# -v, –verbose 详细模式
# –debuglevel LEVEL 调试级别(0-10)
# –errorlevel LEVEL 错误级别(0-10)
# -d, –debugsolver 调试依赖解析
# –downloadonly 仅下载不安装
# –downloaddir DIR 指定下载目录
# –installroot DIR 指定安装根目录
# –releasever VERSION 指定发行版本
# –setopt OPTION=VALUE 设置选项
# –enablerepo REPO 启用存储库
# –disablerepo REPO 禁用存储库
# –enableplugin PLUGIN 启用插件
# –disableplugin PLUGIN 禁用插件
# –nogpgcheck 禁用GPG检查
# –obsoletes 处理过时软件包
# –allowerasing 允许删除冲突软件包
# –best 选择最佳软件包
# –nobest 不选择最佳软件包
# –skipunavailable 跳过不可用软件包
# –comment COMMENT 添加事务注释

3.2 DNF常用选项详解

3.2.1 DNF安装命令选项

# DNF安装命令常用选项
# dnf install [选项] [软件包]

# 自动确认安装
# dnf -y install nginx
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
nginx x86_64 1:1.22.1-2.el9 appstream 35 k
Installing dependencies:
nginx-core x86_64 1:1.22.1-2.el9 appstream 540 k
nginx-filesystem noarch 1:1.22.1-2.el9 appstream 11 k

Transaction Summary
================================================================================
Install 3 Packages

Total download size: 586 k
Installed size: 1.9 M
Downloading Packages:
(1/3): nginx-filesystem-1.22.1-2.el9.noarch.rpm 11 kB/s | 11 kB 00:00
(2/3): nginx-1.22.1-2.el9.x86_64.rpm 35 kB/s | 35 kB 00:00
(3/3): nginx-core-1.22.1-2.el9.x86_64.rpm 540 kB/s | 540 kB 00:00
——————————————————————————–
Total 586 kB/s | 586 kB 00:00
Running transaction check
Transaction test succeeded
Running transaction
Preparing : 1/1
Installing : nginx-filesystem-1.22.1-2.el9.noarch 1/3
Installing : nginx-core-1.22.1-2.el9.x86_64 2/3
Installing : nginx-1.22.1-2.el9.x86_64 3/3
Running scriptlet: nginx-1.22.1-2.el9.x86_64 3/3
Verifying : nginx-1.22.1-2.el9.x86_64 1/3
Verifying : nginx-core-1.22.1-2.el9.x86_64 2/3
Verifying : nginx-filesystem-1.22.1-2.el9.noarch 3/3

Installed:
nginx-1.22.1-2.el9.x86_64
nginx-core-1.22.1-2.el9.x86_64
nginx-filesystem-1.22.1-2.el9.noarch

Complete!

# 仅下载不安装
# dnf install –downloadonly –downloaddir=/tmp nginx
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
nginx x86_64 1:1.22.1-2.el9 appstream 35 k
Installing dependencies:
nginx-core x86_64 1:1.22.1-2.el9 appstream 540 k
nginx-filesystem noarch 1:1.22.1-2.el9 appstream 11 k

Transaction Summary
================================================================================
Install 3 Packages

Total download size: 586 k
Downloading Packages:
(1/3): nginx-filesystem-1.22.1-2.el9.noarch.rpm 11 kB/s | 11 kB 00:00
(2/3): nginx-1.22.1-2.el9.x86_64.rpm 35 kB/s | 35 kB 00:00
(3/3): nginx-core-1.22.1-2.el9.x86_64.rpm 540 kB/s | 540 kB 00:00
——————————————————————————–
Total 586 kB/s | 586 kB 00:00
Complete!

# 查看下载的软件包
# ls -lh /tmp/*.rpm
-rw-r–r–. 1 root root 11K Mar 31 10:00 nginx-filesystem-1.22.1-2.el9.noarch.rpm
-rw-r–r–. 1 root root 35K Mar 31 10:00 nginx-1.22.1-2.el9.x86_64.rpm
-rw-r–r–. 1 root root 540K Mar 31 10:00 nginx-core-1.22.1-2.el9.x86_64.rpm

3.2.2 DNF更新命令选项

# DNF更新命令常用选项
# dnf update [选项] [软件包]

# 更新所有软件包
# dnf -y update
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Dependencies resolved.
Nothing to do.
Complete!

# 更新指定软件包
# dnf -y update nginx
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Dependencies resolved.
Nothing to do.
Complete!

# 检查可用更新
# dnf check-update
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
kernel.x86_64 5.14.0-284.11.1.el9_2 baseos
kernel-core.x86_64 5.14.0-284.11.1.el9_2 baseos
kernel-modules.x86_64 5.14.0-284.11.1.el9_2 baseos

3.3 DNF高级使用技巧

3.3.1 DNF事务历史记录

# 查看事务历史
# dnf history list
ID | Command line | Date and time | Action(s) | Altered
—–+————————–+——————+—————-+——–
1 | install nginx | 2026-03-31 10:00 | Install | 3
2 | update | 2026-03-31 10:05 | Update | 0
3 | remove nginx | 2026-03-31 10:10 | Erase | 3

# 查看事务详情
# dnf history info 1
Transaction ID : 1
Begin time : Thu Mar 31 10:00:00 2026
Begin rpmdb : 1234:5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f
End time : Thu Mar 31 10:00:05 2026
End rpmdb : 1235:5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f
User : root
Return-Code : Success
Command Line : install nginx
Packages Altered:
Install nginx-1.22.1-2.el9.x86_64
Install nginx-core-1.22.1-2.el9.x86_64
Install nginx-filesystem-1.22.1-2.el9.noarch

# 回滚事务
# dnf history undo 1
Undoing transaction 1, from Thu Mar 31 10:00:00 2026
Erase nginx-1.22.1-2.el9.x86_64
Erase nginx-core-1.22.1-2.el9.x86_64
Erase nginx-filesystem-1.22.1-2.el9.noarch

Complete!

# 重做事务
# dnf history redo 1
Redoing transaction 1, from Thu Mar 31 10:00:00 2026
Install nginx-1.22.1-2.el9.x86_64
Install nginx-core-1.22.1-2.el9.x86_64
Install nginx-filesystem-1.22.1-2.el9.noarch

Complete!

3.3.2 DNF模块化流管理

# 查看可用模块
# dnf module list
Name Stream Profiles Summary
httpd 2.4 [d] common [d], devel Apache HTTP Server
httpd 2.6 common, devel Apache HTTP Server
nginx 1.20 [d] common [d] nginx webserver
nginx 1.22 common nginx webserver
postgresql 13 [d] client, server [d] PostgreSQL server
postgresql 15 client, server PostgreSQL server

# 安装模块
# dnf module install nginx:1.22/common
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
nginx x86_64 1:1.22.1-2.el9 appstream 35 k
Installing dependencies:
nginx-core x86_64 1:1.22.1-2.el9 appstream 540 k
nginx-filesystem noarch 1:1.22.1-2.el9 appstream 11 k

Transaction Summary
================================================================================
Install 3 Packages

Total download size: 586 k
Installed size: 1.9 M
Complete!

# 启用模块流
# dnf module enable nginx:1.22
Complete!

# 查看已启用的模块
# dnf module list –enabled
Name Stream Profiles Summary
nginx 1.22 common nginx webserver

风哥提示:DNF事务历史记录功能非常强大,可以回滚之前的操作。模块化流功能允许安装不同版本的软件包。学习交流加群风哥QQ113257174

Part04-生产案例与实战讲解

4.1 DNF软件包安装实战案例

4.1.1 安装Web服务器(Nginx)

# 1. 搜索nginx软件包
# dnf search nginx
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
================ Name & Summary Matched: nginx =================
nginx.x86_64 : A high performance web server and reverse proxy server
nginx-filesystem.noarch : The basic directory layout for the nginx webserver
nginx-core.x86_64 : nginx core webserver binary

# 2. 查看nginx软件包信息
# dnf info nginx
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Available Packages
Name : nginx
Version : 1.22.1
Release : 2.el9
Architecture : x86_64
Size : 35 k
Source : nginx-1.22.1-2.el9.src.rpm
Repository : appstream
Summary : A high performance web server and reverse proxy server
URL : http://nginx.org/
License : BSD
Description : Nginx is a web server and a reverse proxy server for HTTP, HTTPS,
: SMTP, POP3 and IMAP protocols, with a strong focus on high concurrency,
: performance and low memory usage.

# 3. 查看nginx依赖关系
# dnf deplist nginx
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
package: nginx.x86_64 1.22.1-2.el9
dependency: nginx-core.x86_64
provider: nginx-core.x86_64 1.22.1-2.el9
dependency: nginx-filesystem.noarch
provider: nginx-filesystem.noarch 1.22.1-2.el9
dependency: systemd
provider: systemd-libs.x86_64 252-14.el9_2.3
dependency: /bin/sh
provider: bash.x86_64 5.1.8-6.el9_1

# 4. 安装nginx
# dnf -y install nginx
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
nginx x86_64 1:1.22.1-2.el9 appstream 35 k
Installing dependencies:
nginx-core x86_64 1:1.22.1-2.el9 appstream 540 k
nginx-filesystem noarch 1:1.22.1-2.el9 appstream 11 k

Transaction Summary
================================================================================
Install 3 Packages

Total download size: 586 k
Installed size: 1.9 M
Downloading Packages:
(1/3): nginx-filesystem-1.22.1-2.el9.noarch.rpm 11 kB/s | 11 kB 00:00
(2/3): nginx-1.22.1-2.el9.x86_64.rpm 35 kB/s | 35 kB 00:00
(3/3): nginx-core-1.22.1-2.el9.x86_64.rpm 540 kB/s | 540 kB 00:00
——————————————————————————–
Total 586 kB/s | 586 kB 00:00
Running transaction check
Transaction test succeeded
Running transaction
Preparing : 1/1
Installing : nginx-filesystem-1.22.1-2.el9.noarch 1/3
Installing : nginx-core-1.22.1-2.el9.x86_64 2/3
Installing : nginx-1.22.1-2.el9.x86_64 3/3
Running scriptlet: nginx-1.22.1-2.el9.x86_64 3/3
Verifying : nginx-1.22.1-2.el9.x86_64 1/3
Verifying : nginx-core-1.22.1-2.el9.x86_64 2/3
Verifying : nginx-filesystem-1.22.1-2.el9.noarch 3/3

Installed:
nginx-1.22.1-2.el9.x86_64
nginx-core-1.22.1-2.el9.x86_64
nginx-filesystem-1.22.1-2.el9.noarch

Complete!

# 5. 启动nginx服务
# systemctl start nginx
# systemctl enable nginx
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.

# 6. 验证nginx服务
# systemctl status nginx
● nginx.service – The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled)
Active: active (running) since Thu 2026-03-31 10:00:00 CST; 5s ago
Process: 1234 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 1235 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Main PID: 1236 (nginx)
Tasks: 2 (limit: 4915)
Memory: 2.3M
CGroup: /system.slice/nginx.service
├─1236 “nginx: master process /usr/sbin/nginx”
└─1237 “nginx: worker process”

Mar 31 10:00:00 server1 systemd[1]: Starting The nginx HTTP and reverse proxy server…
Mar 31 10:00:00 server1 nginx[1234]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Mar 31 10:00:00 server1 nginx[1234]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Mar 31 10:00:00 server1 systemd[1]: Started The nginx HTTP and reverse proxy server.

# 7. 测试nginx服务
# curl http://localhost

Welcome to nginx!

If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.

For online documentation and support please refer to
nginx.org.
Commercial support is available at
nginx.com.

Thank you for using nginx.

4.2 DNF软件包更新实战案例

4.2.1 系统安全更新

# 1. 检查可用更新
# dnf check-update –security
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
kernel.x86_64 5.14.0-284.11.1.el9_2 baseos
kernel-core.x86_64 5.14.0-284.11.1.el9_2 baseos
kernel-modules.x86_64 5.14.0-284.11.1.el9_2 baseos

# 2. 查看更新详情
# dnf updateinfo list
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Updates Information Summary: available
1 security notice(s)
1 bugfix notice(s)

# 3. 查看安全更新详情
# dnf updateinfo info
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
RHSA-2026:1234 Important/Sec. kernel security update
Update ID: RHSA-2026:1234
Type: security
Severity: Important
Release: RHEL 10
Status: stable
Issued: 2026-03-31 00:00:00
Bugs: 1234567
CVEs: CVE-2026-1234
Description: The kernel packages contain the Linux kernel, the core of any
Linux operating system. Security Fix(es): * kernel: A flaw
was found in the Linux kernel’s implementation of the
eBPF subsystem. This issue could allow a local user to
escalate their privileges on the system. (CVE-2026-1234,
Important)

# 4. 应用安全更新
# dnf -y update –security
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Upgrading:
kernel x86_64 5.14.0-284.11.1.el9_2 baseos 2.3 M
kernel-core x86_64 5.14.0-284.11.1.el9_2 baseos 9.8 M
kernel-modules x86_64 5.14.0-284.11.1.el9_2 baseos 28 M

Transaction Summary
================================================================================
Upgrade 3 Packages

Total download size: 40.1 M
Downloading Packages:
(1/3): kernel-5.14.0-284.11.1.el9_2.x86_64.rpm 2.3 MB/s | 2.3 MB 00:00
(2/3): kernel-core-5.14.0-284.11.1.el9_2.x86_64.rpm 9.8 MB/s | 9.8 MB 00:00
(3/3): kernel-modules-5.14.0-284.11.1.el9_2.x86_64.rpm 28 MB/s | 28 MB 00:00
——————————————————————————–
Total 40.1 MB/s | 40.1 MB 00:00
Running transaction check
Transaction test succeeded
Running transaction
Preparing : 1/1
Upgrading : kernel-core-5.14.0-284.11.1.el9_2.x86_64 1/3
Upgrading : kernel-modules-5.14.0-284.11.1.el9_2.x86_64 2/3
Upgrading : kernel-5.14.0-284.11.1.el9_2.x86_64 3/3
Cleanup : kernel-core-5.14.0-284.11.0.el9_2.x86_64 4/3
Cleanup : kernel-modules-5.14.0-284.11.0.el9_2.x86_64 5/3
Cleanup : kernel-5.14.0-284.11.0.el9_2.x86_64 6/3
Verifying : kernel-core-5.14.0-284.11.1.el9_2.x86_64 1/3
Verifying : kernel-modules-5.14.0-284.11.1.el9_2.x86_64 2/3
Verifying : kernel-5.14.0-284.11.1.el9_2.x86_64 3/3

Complete!

# 5. 查看已安装的内核
# rpm -qa | grep kernel
kernel-5.14.0-284.11.0.el9_2.x86_64
kernel-core-5.14.0-284.11.0.el9_2.x86_64
kernel-modules-5.14.0-284.11.0.el9_2.x86_64
kernel-5.14.0-284.11.1.el9_2.x86_64
kernel-core-5.14.0-284.11.1.el9_2.x86_64
kernel-modules-5.14.0-284.11.1.el9_2.x86_64

# 6. 重启系统以使用新内核
# reboot

4.3 DNF工具故障排查与解决

4.3.1 DNF缓存问题

# 问题现象:DNF命令执行缓慢或报错
# 分析步骤:

# 1. 查看DNF缓存目录
# ls -lh /var/cache/dnf/
total 0
drwxr-xr-x. 2 root root 4096 Mar 31 10:00 appstream-1234567890abcdef
drwxr-xr-x. 2 root root 4096 Mar 31 10:00 baseos-1234567890abcdef
drwxr-xr-x. 2 root root 4096 Mar 31 10:00 extras-1234567890abcdef

# 2. 清理DNF缓存
# dnf clean all
Updating Subscription Management repositories.
0 files removed

# 3. 重新生成缓存
# dnf makecache
Updating Subscription Management repositories.
Metadata cache created.

# 4. 验证缓存
# dnf repolist
Updating Subscription Management repositories.
repo id repo name
appstream Red Hat Enterprise Linux 10 – AppStream
baseos Red Hat Enterprise Linux 10 – BaseOS
extras Red Hat Enterprise Linux 10 – Extras

# 5. 预防措施
# – 定期清理DNF缓存
# – 配置缓存过期时间
# – 使用本地存储库

4.3.2 DNF依赖问题

# 问题现象:软件包安装失败,依赖冲突
# 分析步骤:

# 1. 查看依赖关系
# dnf deplist nginx
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
package: nginx.x86_64 1.22.1-2.el9
dependency: nginx-core.x86_64
provider: nginx-core.x86_64 1.22.1-2.el9
dependency: nginx-filesystem.noarch
provider: nginx-filesystem.noarch 1.22.1-2.el9

# 2. 使用–allowerasing选项
# dnf install –allowerasing nginx
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
nginx x86_64 1:1.22.1-2.el9 appstream 35 k
Installing dependencies:
nginx-core x86_64 1:1.22.1-2.el9 appstream 540 k
nginx-filesystem noarch 1:1.22.1-2.el9 appstream 11 k

Transaction Summary
================================================================================
Install 3 Packages

Total download size: 586 k
Installed size: 1.9 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): nginx-filesystem-1.22.1-2.el9.noarch.rpm 11 kB/s | 11 kB 00:00
(2/3): nginx-1.22.1-2.el9.x86_64.rpm 35 kB/s | 35 kB 00:00
(3/3): nginx-core-1.22.1-2.el9.x86_64.rpm 540 kB/s | 540 kB 00:00
——————————————————————————–
Total 586 kB/s | 586 kB 00:00
Running transaction check
Transaction test succeeded
Running transaction
Preparing : 1/1
Installing : nginx-filesystem-1.22.1-2.el9.noarch 1/3
Installing : nginx-core-1.22.1-2.el9.x86_64 2/3
Installing : nginx-1.22.1-2.el9.x86_64 3/3
Running scriptlet: nginx-1.22.1-2.el9.x86_64 3/3
Verifying : nginx-1.22.1-2.el9.x86_64 1/3
Verifying : nginx-core-1.22.1-2.el9.x86_64 2/3
Verifying : nginx-filesystem-1.22.1-2.el9.noarch 3/3

Complete!

# 3. 预防措施
# – 定期更新系统
# – 使用官方存储库
# – 检查软件包依赖关系

生产环境建议:DNF工具故障排查需要耐心和细致。缓存问题可以使用dnf clean all解决,依赖问题可以使用–allowerasing选项。更多学习教程公众号风哥教程itpux_com

Part05-风哥经验总结与分享

5.1 DNF工具使用经验总结

DNF工具使用经验总结:

  • 定期更新:定期更新系统和软件包
  • 测试环境:在测试环境先测试更新
  • 备份:更新前备份重要数据
  • 事务历史:利用事务历史记录进行回滚
  • 模块化:使用模块化流安装不同版本软件包
  • 缓存管理:定期清理DNF缓存
  • 存储库配置:配置本地存储库提高速度

5.2 DNF工具操作检查清单

DNF工具操作检查清单:

  • 安装前:检查软件包信息、依赖关系
  • 安装时:使用-y选项自动确认
  • 安装后:验证软件包安装
  • 更新前:检查可用更新、更新详情
  • 更新时:使用–security选项仅更新安全补丁
  • 更新后:重启系统(如果需要)
  • 故障排查:清理缓存、检查依赖关系

5.3 DNF工具相关工具推荐

DNF工具相关工具推荐:

  • dnf-plugins-core:DNF核心插件
  • dnf-utils:DNF实用工具
  • repoquery:查询软件包信息
  • repotrack:跟踪软件包依赖
  • yum-utils:YUM实用工具(兼容DNF)
风哥提示:DNF是RHEL 10的默认软件包管理器,提供了强大的功能和良好的性能。建议熟练掌握DNF的基础命令和常用选项,利用事务历史记录进行回滚,使用模块化流安装不同版本软件包。

本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html

联系我们

在线咨询:点击这里给我发消息

微信号:itpux-com

工作日:9:30-18:30,节假日休息