本文档风哥主要介绍dnf repolist命令的使用,包括DNF存储库的概念、DNF存储库类型、DNF存储库配置文件、dnf repolist基础命令详解、dnf
repolist常用选项详解、存储库启用/禁用操作、存储库查看实战案例、存储库管理实战案例、存储库故障排查与解决等内容,参考Red Hat Enterprise Linux
10官方文档,适合Linux运维人员在学习和测试中使用,如果要应用于生产环境则需要自行确认。
Part01-基础概念与理论知识
1.1 DNF存储库的概念
DNF存储库(Repository)是软件包的集合,包含软件包的元数据和软件包文件。存储库可以是本地的(如ISO镜像挂载)或远程的(如HTTP/FTP服务器)。DNF从存储库中获取软件包信息、下载和安装软件包。更多视频教程www.fgedu.net.cn
- 包含软件包的元数据(依赖关系、版本信息等)
- 包含软件包文件(RPM包)
- 支持本地和远程存储库
- 支持多个存储库同时使用
- 支持存储库优先级
- 支持GPG签名验证
1.2 DNF存储库类型
DNF存储库类型:
- BaseOS:基础操作系统软件包
- AppStream:应用程序软件包
- Extras:额外软件包
- CRB:CodeReady Builder(开发工具)
- 本地存储库:本地ISO镜像或目录
- 远程存储库:HTTP/FTP/NFS服务器
- 第三方存储库:EPEL、Remi等
1.3 DNF存储库配置文件
DNF存储库配置文件:
- /etc/dnf/dnf.conf:DNF主配置文件
- /etc/yum.repos.d/:存储库配置文件目录
- /etc/yum.repos.d/*.repo:存储库配置文件
- /var/cache/dnf/:DNF缓存目录
Part02-生产环境规划与建议
2.1 DNF存储库在生产环境的规划
DNF存储库在生产环境的规划要点:
– 配置本地存储库提高速度
– 配置镜像存储库作为备份
– 配置存储库优先级
– 启用GPG检查
– 定期更新存储库元数据
– 监控存储库可用性
# 存储库配置规划
– 配置官方存储库
– 配置镜像存储库
– 配置本地存储库
– 配置存储库优先级
– 启用GPG检查
– 配置代理服务器
2.2 DNF存储库管理最佳实践
DNF存储库管理最佳实践:
- 本地存储库:配置本地存储库提高速度
- 镜像存储库:配置镜像存储库作为备份
- 优先级:配置存储库优先级
- GPG检查:启用GPG签名验证
- 定期更新:定期更新存储库元数据
- 监控:监控存储库可用性
2.3 DNF存储库安全配置建议
DNF存储库安全配置建议:
- GPG检查:启用GPG签名验证
- 官方存储库:使用官方或可信的存储库
- HTTPS:使用HTTPS协议访问远程存储库
- 代理:配置代理服务器
- 审计:启用DNF审计日志
Part03-生产环境项目实施方案
3.1 dnf repolist基础命令详解
3.1.1 查看所有存储库
# dnf repolist
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
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
# 查看所有存储库(包括已禁用的)
# dnf repolist –all
Updating Subscription Management repositories.
repo id repo name status
appstream Red Hat Enterprise Linux 10 – AppStream enabled: 10,123
baseos Red Hat Enterprise Linux 10 – BaseOS enabled: 5,456
crb Red Hat Enterprise Linux 10 – CRB disabled
extras Red Hat Enterprise Linux 10 – Extras enabled: 234
local-repo Local Repository disabled
# 2. 查看存储库详细信息
# dnf repolist –verbose
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Repo-id : appstream
Repo-name : Red Hat Enterprise Linux 10 – AppStream
Repo-revision : 1234567890
Repo-updated : Thu Mar 31 10:00:00 2026
Repo-pkgs : 10,123
Repo-size : 12.3 G
Repo-baseurl : https://cdn.redhat.com/content/dist/rhel10/10/x86_64/appstream/os
Repo-expire : 172,800 second(s) (last: Thu Mar 31 10:00:00 2026)
Repo-filename : /etc/yum.repos.d/redhat.repo
# 3. 查看指定存储库
# dnf repolist –repo baseos –verbose
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Repo-id : baseos
Repo-name : Red Hat Enterprise Linux 10 – BaseOS
Repo-revision : 1234567890
Repo-updated : Thu Mar 31 10:00:00 2026
Repo-pkgs : 5,456
Repo-size : 8.9 G
Repo-baseurl : https://cdn.redhat.com/content/dist/rhel10/10/x86_64/baseos/os
Repo-expire : 172,800 second(s) (last: Thu Mar 31 10:00:00 2026)
Repo-filename : /etc/yum.repos.d/redhat.repo
4.2 存储库管理实战案例
4.2.1 配置本地存储库
# mount -o loop /path/to/rhel-10-x86_64-dvd.iso /mnt
mount: /mnt: WARNING: device write-protected, mounted read-only.
# 2. 创建本地存储库配置文件
# cat > /etc/yum.repos.d/local.repo << EOF [local-repo] name=Local RHEL 10 Repository baseurl=file:///mnt
enabled=1 gpgcheck=0 EOF # 3. 验证本地存储库 # dnf repolist Updating Subscription Management repositories. Last
metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026. 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 local-repo Local RHEL 10 Repository # 4. 使用本地存储库安装软件包 # dnf install
--enablerepo=local-repo 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 local-repo 35 k Installing dependencies: nginx-core x86_64 1:1.22.1-2.el9
local-repo 540 k nginx-filesystem noarch 1:1.22.1-2.el9 local-repo 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! # 5. 配置开机自动挂载ISO镜像 #
echo "/path/to/rhel-10-x86_64-dvd.iso /mnt iso9660 ro,loop 0 0">> /etc/fstab
4.3 存储库故障排查与解决
4.3.1 存储库元数据过期
# 分析步骤:
# 1. 查看错误信息
# dnf repolist
Updating Subscription Management repositories.
Error: Failed to download metadata for repo ‘appstream’: Cannot prepare internal mirrorlist: No URLs in
mirrorlist
# 2. 清理缓存
# 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.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
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. 预防措施
# – 定期清理缓存
# – 配置缓存过期时间
# – 使用本地存储库
4.3.2 存储库连接失败
# 分析步骤:
# 1. 检查网络连接
# ping -c 4 cdn.redhat.com
PING cdn.redhat.com (192.168.1.1) 56(84) bytes of data.
64 bytes from cdn.redhat.com (192.168.1.1): icmp_seq=1 ttl=64 time=0.123 ms
64 bytes from cdn.redhat.com (192.168.1.1): icmp_seq=2 ttl=64 time=0.123 ms
64 bytes from cdn.redhat.com (192.168.1.1): icmp_seq=3 ttl=64 time=0.123 ms
64 bytes from cdn.redhat.com (192.168.1.1): icmp_seq=4 ttl=64 time=0.123 ms
— cdn.redhat.com ping statistics —
4 packets transmitted, 4 received, 0% packet loss
round-trip min/avg/max/stddev = 0.123/0.123/0.123/0.000 ms
# 2. 检查DNS解析
# nslookup cdn.redhat.com
Server: 192.168.1.1
Address: 192.168.1.1#53
Non-authoritative answer:
Name: cdn.redhat.com
Address: 192.168.1.1
# 3. 检查防火墙
# firewall-cmd –list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: eth0
sources:
services: dhcpv6-client ssh
ports:
protocols:
forward: no
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
# 4. 配置代理服务器
# cat > /etc/dnf/dnf.conf << EOF [main] proxy=http://proxy.example.com:3128 EOF # 5. 预防措施 # - 配置镜像存储库 # -
配置本地存储库 # - 配置代理服务器
all解决,连接失败需要检查网络连接和DNS解析。更多学习教程公众号风哥教程itpux_com
Part05-风哥经验总结与分享
5.1 DNF存储库管理经验总结
DNF存储库管理经验总结:
- 本地存储库:配置本地存储库提高速度
- 镜像存储库:配置镜像存储库作为备份
- 优先级:配置存储库优先级
- GPG检查:启用GPG签名验证
- 定期更新:定期更新存储库元数据
- 监控:监控存储库可用性
5.2 DNF存储库操作检查清单
DNF存储库操作检查清单:
- 配置前:检查存储库配置文件
- 配置时:使用dnf config-manager或手动编辑
- 配置后:验证存储库配置
- 使用前:检查存储库状态
- 使用时:使用–enablerepo/–disablerepo选项
- 故障排查:清理缓存、检查网络连接
5.3 DNF存储库相关工具推荐
DNF存储库相关工具推荐:
- dnf config-manager:管理存储库配置
- dnf-plugins-core:DNF核心插件
- createrepo:创建本地存储库
- reposync:同步存储库
- repomanage:管理存储库软件包
Repository disabled
# 查看已禁用的存储库
# dnf repolist –disabled
Updating Subscription Management repositories.
repo id repo name
crb Red Hat Enterprise Linux 10 – CRB
local-repo Local Repository
# 查看已启用的存储库(详细信息)
# dnf repolist –verbose
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Repo-id : appstream
Repo-name : Red Hat Enterprise Linux 10 – AppStream
Repo-revision : 1234567890
Repo-updated : Thu Mar 31 10:00:00 2026
Repo-pkgs : 10,123
Repo-size : 12.3 G
Repo-baseurl : https://cdn.redhat.com/content/dist/rhel10/10/x86_64/appstream/os
Repo-expire : 172,800 second(s) (last: Thu Mar 31 10:00:00 2026)
Repo-filename : /etc/yum.repos.d/redhat.repo
Repo-id : baseos
Repo-name : Red Hat Enterprise Linux 10 – BaseOS
Repo-revision : 1234567890
Repo-updated : Thu Mar 31 10:00:00 2026
Repo-pkgs : 5,456
Repo-size : 8.9 G
Repo-baseurl : https://cdn.redhat.com/content/dist/rhel10/10/x86_64/baseos/os
Repo-expire : 172,800 second(s) (last: Thu Mar 31 10:00:00 2026)
Repo-filename : /etc/yum.repos.d/redhat.repo
Repo-id : extras
Repo-name : Red Hat Enterprise Linux 10 – Extras
Repo-revision : 1234567890
Repo-updated : Thu Mar 31 10:00:00 2026
Repo-pkgs : 234
Repo-size : 1.2 G
Repo-baseurl : https://cdn.redhat.com/content/dist/rhel10/10/x86_64/extras/os
Repo-expire : 172,800 second(s) (last: Thu Mar 31 10:00:00 2026)
Repo-filename : /etc/yum.repos.d/redhat.repo
3.2 dnf repolist常用选项详解
3.2.1 dnf repolist常用选项
# –all 显示所有存储库(包括已禁用的)
# –enabled 显示已启用的存储库(默认)
# –disabled 显示已禁用的存储库
# –verbose 显示详细信息
# –refresh 强制刷新元数据
# –enablerepo REPO 临时启用指定存储库
# –disablerepo REPO 临时禁用指定存储库
# –repo REPO 仅显示指定存储库
# 强制刷新元数据并查看存储库
# dnf repolist –refresh
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
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
# 仅显示指定存储库
# dnf repolist –repo baseos
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
repo id repo name
baseos Red Hat Enterprise Linux 10 – BaseOS
# 临时启用已禁用的存储库
# dnf repolist –enablerepo crb
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
repo id repo name
appstream Red Hat Enterprise Linux 10 – AppStream
baseos Red Hat Enterprise Linux 10 – BaseOS
crb Red Hat Enterprise Linux 10 – CRB
extras Red Hat Enterprise Linux 10 – Extras
3.3 存储库启用/禁用操作
3.3.1 使用dnf config-manager启用/禁用存储库
# cat /etc/yum.repos.d/redhat.repo
[appstream]
name=Red Hat Enterprise Linux 10 – AppStream
baseurl=https://cdn.redhat.com/content/dist/rhel10/10/x86_64/appstream/os
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[baseos]
name=Red Hat Enterprise Linux 10 – BaseOS
baseurl=https://cdn.redhat.com/content/dist/rhel10/10/x86_64/baseos/os
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[extras]
name=Red Hat Enterprise Linux 10 – Extras
baseurl=https://cdn.redhat.com/content/dist/rhel10/10/x86_64/extras/os
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[crb]
name=Red Hat Enterprise Linux 10 – CRB
baseurl=https://cdn.redhat.com/content/dist/rhel10/10/x86_64/crb/os
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
# 启用存储库
# dnf config-manager –set-enabled crb
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
# 验证存储库已启用
# dnf repolist
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
repo id repo name
appstream Red Hat Enterprise Linux 10 – AppStream
baseos Red Hat Enterprise Linux 10 – BaseOS
crb Red Hat Enterprise Linux 10 – CRB
extras Red Hat Enterprise Linux 10 – Extras
# 禁用存储库
# dnf config-manager –set-disabled crb
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
# 验证存储库已禁用
# dnf repolist
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
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
3.3.2 手动编辑存储库配置文件
# vi /etc/yum.repos.d/redhat.repo
# 修改enabled参数
# enabled=1 启用存储库
# enabled=0 禁用存储库
# 重新加载存储库配置
# dnf clean all
Updating Subscription Management repositories.
0 files removed
# dnf makecache
Updating Subscription Management repositories.
Metadata cache created.
# 验证存储库配置
# dnf repolist
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
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
Part04-生产案例与实战讲解
4.1 存储库查看实战案例
4.1.1 查看存储库详细信息
# dnf repolist –all
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
repo id repo name status
appstream Red Hat Enterprise Linux 10 – AppStream enabled: 10,123
baseos Red Hat Enterprise Linux 10 – BaseOS enabled: 5,456
crb Red Hat Enterprise Linux 10 – CRB disabled
extras Red Hat Enterprise Linux 10 – Extras enabled: 234
local-repo Local
本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html
