1. 首页 > Linux教程 > 正文

Linux教程FG110-本地YUM/DNF存储库配置(ISO挂载+repo文件)

本文档风哥主要介绍本地YUM/DNF存储库的配置,包括本地YUM/DNF存储库的概念、本地YUM/DNF存储库的优势、本地YUM/DNF存储库架构、本地YUM/DNF存储库基础配置详解、本地YUM/DNF存储库高级配置技巧、本地YUM/DNF存储库自动化管理、ISO镜像挂载配置本地存储库实战案例、ISO镜像复制配置本地存储库实战案例、本地YUM/DNF存储库故障排查与解决等内容,参考Red Hat Enterprise Linux 10官方文档,适合Linux运维人员在学习和测试中使用,如果要应用于生产环境则需要自行确认。

Part01-基础概念与理论知识

1.1 本地YUM/DNF存储库的概念

本地YUM/DNF存储库是指将RHEL Linux的ISO镜像文件挂载或复制到本地服务器上,然后配置本地YUM/DNF存储库,使服务器可以从本地安装软件包,而不需要连接到远程存储库。本地YUM/DNF存储库可以提高软件包安装速度,减少网络带宽消耗,提高系统安全性。更多视频教程www.fgedu.net.cn

本地YUM/DNF存储库的主要特点:

  • 提高软件包安装速度
  • 减少网络带宽消耗
  • 提高系统安全性
  • 支持离线安装
  • 便于软件包版本控制

1.2 本地YUM/DNF存储库的优势

本地YUM/DNF存储库的优势:

  • 速度快:本地存储库安装软件包速度快
  • 节省带宽:减少网络带宽消耗
  • 安全性高:减少网络攻击风险
  • 离线安装:支持离线安装软件包
  • 版本控制:便于软件包版本控制

1.3 本地YUM/DNF存储库架构

本地YUM/DNF存储库架构:

  • ISO镜像:RHEL Linux ISO镜像文件
  • 挂载点:ISO镜像挂载目录
  • repo文件:YUM/DNF存储库配置文件
  • 元数据:软件包元数据
  • 软件包:RPM软件包
风哥提示:本地YUM/DNF存储库可以提高软件包安装速度,减少网络带宽消耗,提高系统安全性。建议在生产环境中使用本地存储库。

Part02-生产环境规划与建议

2.1 本地YUM/DNF存储库在生产环境的规划

本地YUM/DNF存储库在生产环境的规划要点:

# 本地YUM/DNF存储库生产环境规划
– 准备RHEL Linux ISO镜像
– 选择合适的存储位置
– 配置本地存储库
– 定期更新存储库
– 监控存储库状态

# 本地YUM/DNF存储库注意事项
– 确保ISO镜像完整性
– 选择合适的挂载点
– 配置正确的repo文件
– 定期更新存储库
– 备份存储库配置

2.2 本地YUM/DNF存储库最佳实践

本地YUM/DNF存储库最佳实践:

  • 完整性检查:确保ISO镜像完整性
  • 存储位置:选择合适的存储位置
  • 配置正确:配置正确的repo文件
  • 定期更新:定期更新存储库
  • 备份配置:备份存储库配置

2.3 本地YUM/DNF存储库安全配置建议

本地YUM/DNF存储库安全配置建议:

  • 最小权限:使用最小权限配置
  • 访问控制:配置访问控制
  • 完整性验证:验证软件包完整性
  • 定期更新:定期更新存储库
  • 备份恢复:备份存储库配置
生产环境建议:确保ISO镜像完整性,选择合适的存储位置,配置正确的repo文件,定期更新存储库。学习交流加群风哥微信: itpux-com

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

3.1 本地YUM/DNF存储库基础配置详解

3.1.1 准备ISO镜像

# 1. 下载RHEL Linux 10 ISO镜像
# 从Red Hat官网下载RHEL Linux 10 ISO镜像文件

# 2. 验证ISO镜像完整性
# sha256sum rhel-10-x86_64-dvd.iso
a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6 rhel-10-x86_64-dvd.iso

# 3. 将ISO镜像复制到服务器
# scp rhel-10-x86_64-dvd.iso root@server:/root/
rhel-10-x86_64-dvd.iso 100% 10GB 10MB/s 00:00

3.1.2 创建挂载点

# 1. 创建挂载点目录
# mkdir -p /mnt/iso

# 2. 验证挂载点目录已创建
# ls -ld /mnt/iso
drwxr-xr-x. 2 root root 4096 Mar 31 10:00 /mnt/iso

3.1.3 挂载ISO镜像

# 1. 挂载ISO镜像
# mount -o loop /root/rhel-10-x86_64-dvd.iso /mnt/iso

# 2. 验证ISO镜像已挂载
# df -h | grep iso
/dev/loop0 10G 10G 0 100% /mnt/iso

# 3. 查看挂载点内容
# ls /mnt/iso/
AppStream BaseOS EFI images isolinux media.repo TRANS.TBL

3.1.4 配置repo文件

# 1. 创建repo文件
# cat > /etc/yum.repos.d/local.repo << 'EOF' [BaseOS] name=Red Hat Enterprise Linux 10 - BaseOS baseurl=file:///mnt/iso/BaseOS enabled=1 gpgcheck=0 [AppStream] name=Red Hat Enterprise Linux 10 - AppStream baseurl=file:///mnt/iso/AppStream enabled=1 gpgcheck=0 EOF # 2. 验证repo文件已创建 # cat /etc/yum.repos.d/local.repo [BaseOS] name=Red Hat Enterprise Linux 10 - BaseOS baseurl=file:///mnt/iso/BaseOS enabled=1 gpgcheck=0 [AppStream] name=Red Hat Enterprise Linux 10 - AppStream baseurl=file:///mnt/iso/AppStream enabled=1 gpgcheck=0

3.1.5 验证本地存储库

# 1. 清理YUM缓存
# dnf clean all
0 files removed

# 2. 生成YUM缓存
# dnf makecache
BaseOS 1.2 MB/s | 3.5 MB 00:03
AppStream 1.5 MB/s | 5.2 MB 00:04
Metadata cache created.

# 3. 列出存储库
# dnf repolist
repo id repo name
BaseOS Red Hat Enterprise Linux 10 – BaseOS
AppStream Red Hat Enterprise Linux 10 – AppStream

# 4. 搜索软件包
# 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 nginx

3.2 本地YUM/DNF存储库高级配置技巧

3.2.1 配置自动挂载

# 1. 编辑/etc/fstab文件
# cat >> /etc/fstab << 'EOF' /root/rhel-10-x86_64-dvd.iso /mnt/iso iso9660 defaults,loop 0 0 EOF # 2. 验证fstab文件 # cat /etc/fstab | grep iso /root/rhel-10-x86_64-dvd.iso /mnt/iso iso9660 defaults,loop 0 0 # 3. 测试自动挂载 # umount /mnt/iso # mount -a # 4. 验证ISO镜像已自动挂载 # df -h | grep iso /dev/loop0 10G 10G 0 100% /mnt/iso

3.2.2 配置多个本地存储库

# 1. 创建多个挂载点
# mkdir -p /mnt/iso1
# mkdir -p /mnt/iso2

# 2. 挂载多个ISO镜像
# mount -o loop /root/rhel-10-x86_64-dvd.iso /mnt/iso1
# mount -o loop /root/rhel-10-addons.iso /mnt/iso2

# 3. 配置多个repo文件
# cat > /etc/yum.repos.d/local1.repo << 'EOF' [BaseOS1] name=Red Hat Enterprise Linux 10 - BaseOS 1 baseurl=file:///mnt/iso1/BaseOS enabled=1 gpgcheck=0 [AppStream1] name=Red Hat Enterprise Linux 10 - AppStream 1 baseurl=file:///mnt/iso1/AppStream enabled=1 gpgcheck=0 EOF # cat > /etc/yum.repos.d/local2.repo << 'EOF' [Addons] name=Red Hat Enterprise Linux 10 - Addons baseurl=file:///mnt/iso2 enabled=1 gpgcheck=0 EOF # 4. 验证多个存储库 # dnf repolist repo id repo name BaseOS1 Red Hat Enterprise Linux 10 - BaseOS 1 AppStream1 Red Hat Enterprise Linux 10 - AppStream 1 Addons Red Hat Enterprise Linux 10 - Addons

3.3 本地YUM/DNF存储库自动化管理

3.3.1 自动挂载脚本

# 1. 创建自动挂载脚本
# cat > /usr/local/bin/mount-iso.sh << 'EOF' #!/bin/bash # 自动挂载ISO镜像脚本 ISO_FILE="/root/rhel-10-x86_64-dvd.iso" MOUNT_POINT="/mnt/iso" # 检查ISO镜像是否存在 if [ ! -f "$ISO_FILE" ]; then echo "Error: ISO file not found: $ISO_FILE" exit 1 fi # 检查挂载点是否存在 if [ ! -d "$MOUNT_POINT" ]; then mkdir -p "$MOUNT_POINT" fi # 检查是否已挂载 if mountpoint -q "$MOUNT_POINT"; then echo "ISO already mounted at $MOUNT_POINT" else # 挂载ISO镜像 mount -o loop "$ISO_FILE" "$MOUNT_POINT" if [ $? -eq 0 ]; then echo "ISO mounted successfully at $MOUNT_POINT" else echo "Error: Failed to mount ISO" exit 1 fi fi EOF # 2. 设置脚本执行权限 # chmod +x /usr/local/bin/mount-iso.sh # 3. 测试脚本 # /usr/local/bin/mount-iso.sh ISO mounted successfully at /mnt/iso # 4. 配置开机自动执行 # cat > /etc/systemd/system/mount-iso.service << 'EOF' [Unit] Description=Mount ISO Image After=network.target [Service] Type=oneshot ExecStart=/usr/local/bin/mount-iso.sh RemainAfterExit=yes [Install] WantedBy=multi-user.target EOF # 5. 启用并启动服务 # systemctl enable mount-iso.service # systemctl start mount-iso.service # 6. 验证服务状态 # systemctl status mount-iso.service ● mount-iso.service - Mount ISO Image Loaded: loaded (/etc/systemd/system/mount-iso.service; enabled; vendor preset: disabled) Active: active (exited) since Thu 2026-03-31 10:00:00 CST; 5s ago Main PID: 1234 (code=exited, status=0/SUCCESS) Tasks: 0 (limit: 4915) Memory: 0B CGroup: /system.slice/mount-iso.service
风哥提示:本地YUM/DNF存储库支持多种高级配置,如配置自动挂载、配置多个本地存储库、自动化管理等。学习交流加群风哥QQ113257174

Part04-生产案例与实战讲解

4.1 ISO镜像挂载配置本地存储库实战案例

4.1.1 完整配置流程

# 1. 准备ISO镜像
# ls -lh /root/rhel-10-x86_64-dvd.iso
-rw-r–r–. 1 root root 10G Mar 31 10:00 /root/rhel-10-x86_64-dvd.iso

# 2. 验证ISO镜像完整性
# sha256sum /root/rhel-10-x86_64-dvd.iso
a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6 /root/rhel-10-x86_64-dvd.iso

# 3. 创建挂载点
# mkdir -p /mnt/iso

# 4. 挂载ISO镜像
# mount -o loop /root/rhel-10-x86_64-dvd.iso /mnt/iso

# 5. 验证ISO镜像已挂载
# df -h | grep iso
/dev/loop0 10G 10G 0 100% /mnt/iso

# 6. 查看挂载点内容
# ls /mnt/iso/
AppStream BaseOS EFI images isolinux media.repo TRANS.TBL

# 7. 配置repo文件
# cat > /etc/yum.repos.d/local.repo << 'EOF' [BaseOS] name=Red Hat Enterprise Linux 10 - BaseOS baseurl=file:///mnt/iso/BaseOS enabled=1 gpgcheck=0 [AppStream] name=Red Hat Enterprise Linux 10 - AppStream baseurl=file:///mnt/iso/AppStream enabled=1 gpgcheck=0 EOF # 8. 清理YUM缓存 # dnf clean all 0 files removed # 9. 生成YUM缓存 # dnf makecache BaseOS 1.2 MB/s | 3.5 MB 00:03 AppStream 1.5 MB/s | 5.2 MB 00:04 Metadata cache created. # 10. 列出存储库 # dnf repolist repo id repo name BaseOS Red Hat Enterprise Linux 10 - BaseOS AppStream Red Hat Enterprise Linux 10 - AppStream # 11. 测试安装软件包 # dnf install -y 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.22.1-2.el9 BaseOS 35 k Installing dependencies: nginx-core x86_64 1.22.1-2.el9 BaseOS 540 k nginx-filesystem noarch 1.22.1-2.el9 BaseOS 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!

4.2 ISO镜像复制配置本地存储库实战案例

4.2.1 完整配置流程

# 1. 准备ISO镜像
# ls -lh /root/rhel-10-x86_64-dvd.iso
-rw-r–r–. 1 root root 10G Mar 31 10:00 /root/rhel-10-x86_64-dvd.iso

# 2. 创建存储目录
# mkdir -p /var/www/html/rhel10

# 3. 复制ISO镜像内容
# cp -r /mnt/iso/* /var/www/html/rhel10/

# 4. 验证文件已复制
# ls /var/www/html/rhel10/
AppStream BaseOS EFI images isolinux media.repo TRANS.TBL

# 5. 配置repo文件
# cat > /etc/yum.repos.d/local.repo << 'EOF' [BaseOS] name=Red Hat Enterprise Linux 10 - BaseOS baseurl=file:///var/www/html/rhel10/BaseOS enabled=1 gpgcheck=0 [AppStream] name=Red Hat Enterprise Linux 10 - AppStream baseurl=file:///var/www/html/rhel10/AppStream enabled=1 gpgcheck=0 EOF # 6. 清理YUM缓存 # dnf clean all 0 files removed # 7. 生成YUM缓存 # dnf makecache BaseOS 1.2 MB/s | 3.5 MB 00:03 AppStream 1.5 MB/s | 5.2 MB 00:04 Metadata cache created. # 8. 列出存储库 # dnf repolist repo id repo name BaseOS Red Hat Enterprise Linux 10 - BaseOS AppStream Red Hat Enterprise Linux 10 - AppStream # 9. 测试安装软件包 # dnf install -y httpd 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: httpd x86_64 2.4.53-7.el9 AppStream 1.4 M Installing dependencies: httpd-filesystem noarch 2.4.53-7.el9 AppStream 12 k httpd-tools x86_64 2.4.53-7.el9 AppStream 120 k Transaction Summary ================================================================================ Install 3 Packages Total download size: 1.5 M Installed size: 4.8 M Downloading Packages: (1/3): httpd-filesystem-2.4.53-7.el9.noarch.rpm 12 kB/s | 12 kB 00:00 (2/3): httpd-tools-2.4.53-7.el9.x86_64.rpm 120 kB/s | 120 kB 00:00 (3/3): httpd-2.4.53-7.el9.x86_64.rpm 1.4 MB/s | 1.4 MB 00:00 -------------------------------------------------------------------------------- Total 1.5 MB/s | 1.5 MB 00:00 Running transaction check Transaction test succeeded Running transaction Preparing : 1/1 Installing : httpd-filesystem-2.4.53-7.el9.noarch 1/3 Installing : httpd-tools-2.4.53-7.el9.x86_64 2/3 Installing : httpd-2.4.53-7.el9.x86_64 3/3 Running scriptlet: httpd-2.4.53-7.el9.x86_64 3/3 Verifying : httpd-filesystem-2.4.53-7.el9.noarch 1/3 Verifying : httpd-tools-2.4.53-7.el9.x86_64 2/3 Verifying : httpd-2.4.53-7.el9.x86_64 3/3 Installed: httpd-2.4.53-7.el9.x86_64 httpd-filesystem-2.4.53-7.el9.noarch httpd-tools-2.4.53-7.el9.x86_64 Complete!

4.3 本地YUM/DNF存储库故障排查与解决

4.3.1 存储库无法访问

# 问题现象:本地存储库无法访问
# 分析步骤:

# 1. 查看错误信息
# dnf repolist
Updating Subscription Management repositories.
Error: Failed to download metadata for repo ‘BaseOS’: Cannot open/read repomd.xml file for repository: BaseOS

# 2. 检查ISO镜像是否挂载
# df -h | grep iso
(无输出)

# 3. 检查挂载点目录
# ls -ld /mnt/iso
drwxr-xr-x. 2 root root 4096 Mar 31 10:00 /mnt/iso

# 4. 检查ISO镜像文件
# ls -lh /root/rhel-10-x86_64-dvd.iso
-rw-r–r–. 1 root root 10G Mar 31 10:00 /root/rhel-10-x86_64-dvd.iso

# 5. 重新挂载ISO镜像
# mount -o loop /root/rhel-10-x86_64-dvd.iso /mnt/iso

# 6. 验证ISO镜像已挂载
# df -h | grep iso
/dev/loop0 10G 10G 0 100% /mnt/iso

# 7. 清理YUM缓存
# dnf clean all
0 files removed

# 8. 重新生成YUM缓存
# dnf makecache
BaseOS 1.2 MB/s | 3.5 MB 00:03
AppStream 1.5 MB/s | 5.2 MB 00:04
Metadata cache created.

# 9. 验证存储库可访问
# dnf repolist
repo id repo name
BaseOS Red Hat Enterprise Linux 10 – BaseOS
AppStream Red Hat Enterprise Linux 10 – AppStream

# 10. 预防措施
# – 配置自动挂载
# – 定期检查挂载状态
# – 备份存储库配置

生产环境建议:本地YUM/DNF存储库故障排查需要耐心和细致。存储库无法访问需要检查ISO镜像是否挂载。更多学习教程公众号风哥教程itpux_com

Part05-风哥经验总结与分享

5.1 本地YUM/DNF存储库经验总结

本地YUM/DNF存储库经验总结:

  • 完整性检查:确保ISO镜像完整性
  • 存储位置:选择合适的存储位置
  • 配置正确:配置正确的repo文件
  • 定期更新:定期更新存储库
  • 备份配置:备份存储库配置

5.2 本地YUM/DNF存储库检查清单

本地YUM/DNF存储库检查清单:

  • 配置前:验证ISO镜像完整性
  • 配置时:创建挂载点、挂载ISO镜像、配置repo文件
  • 配置后:清理YUM缓存、生成YUM缓存、验证存储库
  • 使用时:测试安装软件包
  • 维护时:定期更新存储库、备份存储库配置
  • 故障排查:检查ISO镜像是否挂载、重新生成缓存

5.3 本地YUM/DNF存储库相关工具推荐

本地YUM/DNF存储库相关工具推荐:

  • dnf:DNF软件包管理器
  • mount:挂载命令
  • umount:卸载命令
  • createrepo:创建存储库工具
  • reposync:同步存储库工具
风哥提示:本地YUM/DNF存储库可以提高软件包安装速度,减少网络带宽消耗,提高系统安全性。建议在生产环境中使用本地存储库。

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

联系我们

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

微信号:itpux-com

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