1. 首页 > Linux教程 > 正文

Linux教程FG112-存储库优先级配置(yum-plugin-priorities)

本文档风哥主要介绍存储库优先级的配置,包括存储库优先级的概念、为什么需要配置存储库优先级、存储库优先级工作原理、存储库优先级基础配置详解、存储库优先级高级配置技巧、存储库优先级自动化管理、本地存储库优先级配置实战案例、网络存储库优先级配置实战案例、存储库优先级故障排查与解决等内容,参考Red Hat Enterprise Linux 10官方文档,适合Linux运维人员在学习和测试中使用,如果要应用于生产环境则需要自行确认。

Part01-基础概念与理论知识

1.1 存储库优先级的概念

存储库优先级是指为不同的YUM/DNF存储库设置优先级数值,数值越小优先级越高。当多个存储库中存在相同名称的软件包时,DNF会优先从优先级较高的存储库中安装软件包。存储库优先级可以帮助管理员控制软件包的来源,确保系统使用指定版本的软件包。更多视频教程www.fgedu.net.cn

存储库优先级的主要特点:

  • 控制软件包来源
  • 确保软件包版本
  • 避免软件包冲突
  • 提高系统稳定性
  • 便于软件包管理

1.2 为什么需要配置存储库优先级

配置存储库优先级的原因:

  • 控制来源:控制软件包来源
  • 确保版本:确保软件包版本
  • 避免冲突:避免软件包冲突
  • 提高稳定性:提高系统稳定性
  • 便于管理:便于软件包管理

1.3 存储库优先级工作原理

存储库优先级工作原理:

  • 优先级数值:数值越小优先级越高
  • 默认优先级:默认优先级为99
  • 优先级范围:1-99
  • 相同优先级:相同优先级时选择最新的软件包
  • 插件支持:需要yum-plugin-priorities插件
风哥提示:存储库优先级可以帮助管理员控制软件包的来源,确保系统使用指定版本的软件包。建议在生产环境中配置存储库优先级。

Part02-生产环境规划与建议

2.1 存储库优先级在生产环境的规划

存储库优先级在生产环境的规划要点:

# 存储库优先级生产环境规划
– 本地存储库优先级最高
– 官方存储库优先级次之
– 第三方存储库优先级最低
– 定期检查存储库优先级
– 监控软件包安装来源

# 存储库优先级注意事项
– 确保优先级数值正确
– 定期检查存储库状态
– 验证软件包来源
– 备份存储库配置
– 测试软件包安装

2.2 存储库优先级配置最佳实践

存储库优先级配置最佳实践:

  • 本地优先:本地存储库优先级最高
  • 官方次之:官方存储库优先级次之
  • 第三方最低:第三方存储库优先级最低
  • 定期检查:定期检查存储库优先级
  • 验证来源:验证软件包来源

2.3 存储库优先级安全配置建议

存储库优先级安全配置建议:

  • 最小权限:使用最小权限配置
  • GPG检查:启用GPG检查
  • 访问控制:配置访问控制
  • 定期更新:定期更新存储库
  • 备份恢复:备份存储库配置
生产环境建议:本地存储库优先级最高,官方存储库优先级次之,第三方存储库优先级最低。学习交流加群风哥微信: itpux-com

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

3.1 存储库优先级基础配置详解

3.1.1 安装yum-plugin-priorities插件

# 1. 安装yum-plugin-priorities插件
# dnf install -y yum-plugin-priorities
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:
yum-plugin-priorities noarch 1.1.31-54.el9_2 appstream 35 k

Transaction Summary
================================================================================
Install 1 Package

Total download size: 35 k
Installed size: 45 k
Downloading Packages:
yum-plugin-priorities-1.1.31-54.el9_2.noarch.rpm 35 kB/s | 35 kB 00:00
——————————————————————————–
Total 35 kB/s | 35 kB 00:00
Running transaction check
Transaction test succeeded
Running transaction
Preparing : 1/1
Installing : yum-plugin-priorities-1.1.31-54.el9_2.noarch 1/1
Running scriptlet: yum-plugin-priorities-1.1.31-54.el9_2.noarch 1/1
Verifying : yum-plugin-priorities-1.1.31-54.el9_2.noarch 1/1

Installed:
yum-plugin-priorities-1.1.31-54.el9_2.noarch

Complete!

# 2. 验证插件已安装
# rpm -qa | grep priorities
yum-plugin-priorities-1.1.31-54.el9_2.noarch

3.1.2 配置本地存储库优先级

# 1. 配置本地存储库优先级
# cat > /etc/yum.repos.d/local.repo << 'EOF' [BaseOS] name=Red Hat Enterprise Linux 10 - BaseOS (Local) baseurl=file:///mnt/iso/BaseOS enabled=1 gpgcheck=0 priority=1 [AppStream] name=Red Hat Enterprise Linux 10 - AppStream (Local) baseurl=file:///mnt/iso/AppStream enabled=1 gpgcheck=0 priority=1 EOF # 2. 验证repo文件已创建 # cat /etc/yum.repos.d/local.repo [BaseOS] name=Red Hat Enterprise Linux 10 - BaseOS (Local) baseurl=file:///mnt/iso/BaseOS enabled=1 gpgcheck=0 priority=1 [AppStream] name=Red Hat Enterprise Linux 10 - AppStream (Local) baseurl=file:///mnt/iso/AppStream enabled=1 gpgcheck=0 priority=1

3.1.3 配置网络存储库优先级

# 1. 配置网络存储库优先级
# cat > /etc/yum.repos.d/mirror.repo << 'EOF' [BaseOS] name=Red Hat Enterprise Linux 10 - BaseOS (Mirror) baseurl=https://mirrors.aliyun.com/rockylinux/10/BaseOS/x86_64/os/ enabled=1 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/rockylinux/RPM-GPG-KEY-Rocky-10 priority=2 [AppStream] name=Red Hat Enterprise Linux 10 - AppStream (Mirror) baseurl=https://mirrors.aliyun.com/rockylinux/10/AppStream/x86_64/os/ enabled=1 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/rockylinux/RPM-GPG-KEY-Rocky-10 priority=2 EOF # 2. 验证repo文件已创建 # cat /etc/yum.repos.d/mirror.repo [BaseOS] name=Red Hat Enterprise Linux 10 - BaseOS (Mirror) baseurl=https://mirrors.aliyun.com/rockylinux/10/BaseOS/x86_64/os/ enabled=1 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/rockylinux/RPM-GPG-KEY-Rocky-10 priority=2 [AppStream] name=Red Hat Enterprise Linux 10 - AppStream (Mirror) baseurl=https://mirrors.aliyun.com/rockylinux/10/AppStream/x86_64/os/ enabled=1 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/rockylinux/RPM-GPG-KEY-Rocky-10 priority=2

3.1.4 验证存储库优先级

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

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

# 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
BaseOS (Local) Red Hat Enterprise Linux 10 – BaseOS (Local)
AppStream (Local) Red Hat Enterprise Linux 10 – AppStream (Local)
BaseOS (Mirror) Red Hat Enterprise Linux 10 – BaseOS (Mirror)
AppStream (Mirror) Red Hat Enterprise Linux 10 – AppStream (Mirror)

# 4. 查看软件包来源
# 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 : BaseOS (Local)
Summary : A high performance web server and reverse proxy server

3.2 存储库优先级高级配置技巧

3.2.1 配置多个优先级

# 1. 配置多个优先级
# cat > /etc/yum.repos.d/local.repo << 'EOF' [BaseOS] name=Red Hat Enterprise Linux 10 - BaseOS (Local) baseurl=file:///mnt/iso/BaseOS enabled=1 gpgcheck=0 priority=1 [AppStream] name=Red Hat Enterprise Linux 10 - AppStream (Local) baseurl=file:///mnt/iso/AppStream enabled=1 gpgcheck=0 priority=1 EOF # cat > /etc/yum.repos.d/mirror.repo << 'EOF' [BaseOS] name=Red Hat Enterprise Linux 10 - BaseOS (Mirror) baseurl=https://mirrors.aliyun.com/rockylinux/10/BaseOS/x86_64/os/ enabled=1 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/rockylinux/RPM-GPG-KEY-Rocky-10 priority=2 [AppStream] name=Red Hat Enterprise Linux 10 - AppStream (Mirror) baseurl=https://mirrors.aliyun.com/rockylinux/10/AppStream/x86_64/os/ enabled=1 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/rockylinux/RPM-GPG-KEY-Rocky-10 priority=2 EOF # cat > /etc/yum.repos.d/epel.repo << 'EOF' [epel] name=Extra Packages for Enterprise Linux 10 - x86_64 baseurl=https://mirrors.aliyun.com/epel/10/x86_64/ enabled=1 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-10 priority=3 EOF # 2. 验证多个优先级 # 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 BaseOS (Local) Red Hat Enterprise Linux 10 - BaseOS (Local) AppStream (Local) Red Hat Enterprise Linux 10 - AppStream (Local) BaseOS (Mirror) Red Hat Enterprise Linux 10 - BaseOS (Mirror) AppStream (Mirror) Red Hat Enterprise Linux 10 - AppStream (Mirror) epel Extra Packages for Enterprise Linux 10 - x86_64

3.2.2 查看存储库优先级

# 1. 查看存储库优先级
# 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 : BaseOS (Local)
Repo-name : Red Hat Enterprise Linux 10 – BaseOS (Local)
Repo-revision : 1234567890
Repo-updated : Thu Mar 31 09:00:00 2026
Repo-pkgs : 5,456
Repo-available-pkgs: 5,456
Repo-size : 3.5 G
Repo-baseurl : file:///mnt/iso/BaseOS
Repo-expire : 172,800 second(s) (last: Thu Mar 31 10:00:00 2026)
Repo-filename : /etc/yum.repos.d/local.repo
priority : 1

Repo-id : AppStream (Local)
Repo-name : Red Hat Enterprise Linux 10 – AppStream (Local)
Repo-revision : 1234567890
Repo-updated : Thu Mar 31 09:00:00 2026
Repo-pkgs : 10,123
Repo-available-pkgs: 10,123
Repo-size : 5.2 G
Repo-baseurl : file:///mnt/iso/AppStream
Repo-expire : 172,800 second(s) (last: Thu Mar 31 10:00:00 2026)
Repo-filename : /etc/yum.repos.d/local.repo
priority : 1

Repo-id : BaseOS (Mirror)
Repo-name : Red Hat Enterprise Linux 10 – BaseOS (Mirror)
Repo-revision : 1234567890
Repo-updated : Thu Mar 31 09:00:00 2026
Repo-pkgs : 5,456
Repo-available-pkgs: 5,456
Repo-size : 3.5 G
Repo-baseurl : https://mirrors.aliyun.com/rockylinux/10/BaseOS/x86_64/os/
Repo-expire : 172,800 second(s) (last: Thu Mar 31 10:00:00 2026)
Repo-filename : /etc/yum.repos.d/mirror.repo
priority : 2

Repo-id : AppStream (Mirror)
Repo-name : Red Hat Enterprise Linux 10 – AppStream (Mirror)
Repo-revision : 1234567890
Repo-updated : Thu Mar 31 09:00:00 2026
Repo-pkgs : 10,123
Repo-available-pkgs: 10,123
Repo-size : 5.2 G
Repo-baseurl : https://mirrors.aliyun.com/rockylinux/10/AppStream/x86_64/os/
Repo-expire : 172,800 second(s) (last: Thu Mar 31 10:00:00 2026)
Repo-filename : /etc/yum.repos.d/mirror.repo
priority : 2

Repo-id : epel
Repo-name : Extra Packages for Enterprise Linux 10 – x86_64
Repo-revision : 1234567890
Repo-updated : Thu Mar 31 09:00:00 2026
Repo-pkgs : 15,678
Repo-available-pkgs: 15,678
Repo-size : 8.9 G
Repo-baseurl : https://mirrors.aliyun.com/epel/10/x86_64/
Repo-expire : 172,800 second(s) (last: Thu Mar 31 10:00:00 2026)
Repo-filename : /etc/yum.repos.d/epel.repo
priority : 3

3.3 存储库优先级自动化管理

3.3.1 自动配置存储库优先级

# 1. 创建自动配置脚本
# cat > /usr/local/bin/config-priority.sh << 'EOF' #!/bin/bash # 自动配置存储库优先级脚本 LOCAL_PRIORITY=1 MIRROR_PRIORITY=2 EPEL_PRIORITY=3 # 配置本地存储库优先级 cat > /etc/yum.repos.d/local.repo << EOF [BaseOS] name=Red Hat Enterprise Linux 10 - BaseOS (Local) baseurl=file:///mnt/iso/BaseOS enabled=1 gpgcheck=0 priority=$LOCAL_PRIORITY [AppStream] name=Red Hat Enterprise Linux 10 - AppStream (Local) baseurl=file:///mnt/iso/AppStream enabled=1 gpgcheck=0 priority=$LOCAL_PRIORITY EOF # 配置镜像源存储库优先级 cat > /etc/yum.repos.d/mirror.repo << EOF [BaseOS] name=Red Hat Enterprise Linux 10 - BaseOS (Mirror) baseurl=https://mirrors.aliyun.com/rockylinux/10/BaseOS/x86_64/os/ enabled=1 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/rockylinux/RPM-GPG-KEY-Rocky-10 priority=$MIRROR_PRIORITY [AppStream] name=Red Hat Enterprise Linux 10 - AppStream (Mirror) baseurl=https://mirrors.aliyun.com/rockylinux/10/AppStream/x86_64/os/ enabled=1 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/rockylinux/RPM-GPG-KEY-Rocky-10 priority=$MIRROR_PRIORITY EOF # 配置EPEL存储库优先级 cat > /etc/yum.repos.d/epel.repo << EOF [epel] name=Extra Packages for Enterprise Linux 10 - x86_64 baseurl=https://mirrors.aliyun.com/epel/10/x86_64/ enabled=1 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-10 priority=$EPEL_PRIORITY EOF # 清理YUM缓存 dnf clean all # 生成YUM缓存 dnf makecache echo "Repository priorities configured successfully" EOF # 2. 设置脚本执行权限 # chmod +x /usr/local/bin/config-priority.sh # 3. 测试脚本 # /usr/local/bin/config-priority.sh 0 files removed BaseOS (Local) 1.2 MB/s | 3.5 MB 00:03 AppStream (Local) 1.5 MB/s | 5.2 MB 00:04 BaseOS (Mirror) 1.2 MB/s | 3.5 MB 00:03 AppStream (Mirror) 1.5 MB/s | 5.2 MB 00:04 epel 1.8 MB/s | 8.9 MB 00:05 Metadata cache created. Repository priorities configured successfully
风哥提示:存储库优先级支持多种高级配置,如配置多个优先级、查看存储库优先级、自动化管理等。学习交流加群风哥QQ113257174

Part04-生产案例与实战讲解

4.1 本地存储库优先级配置实战案例

4.1.1 完整配置流程

# 1. 安装yum-plugin-priorities插件
# dnf install -y yum-plugin-priorities
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:
yum-plugin-priorities noarch 1.1.31-54.el9_2 appstream 35 k

Transaction Summary
================================================================================
Install 1 Package

Total download size: 35 k
Installed size: 45 k
Downloading Packages:
yum-plugin-priorities-1.1.31-54.el9_2.noarch.rpm 35 kB/s | 35 kB 00:00
——————————————————————————–
Total 35 kB/s | 35 kB 00:00
Running transaction check
Transaction test succeeded
Running transaction
Preparing : 1/1
Installing : yum-plugin-priorities-1.1.31-54.el9_2.noarch 1/1
Running scriptlet: yum-plugin-priorities-1.1.31-54.el9_2.noarch 1/1
Verifying : yum-plugin-priorities-1.1.31-54.el9_2.noarch 1/1

Installed:
yum-plugin-priorities-1.1.31-54.el9_2.noarch

Complete!

# 2. 配置本地存储库优先级
# cat > /etc/yum.repos.d/local.repo << 'EOF' [BaseOS] name=Red Hat Enterprise Linux 10 - BaseOS (Local) baseurl=file:///mnt/iso/BaseOS enabled=1 gpgcheck=0 priority=1 [AppStream] name=Red Hat Enterprise Linux 10 - AppStream (Local) baseurl=file:///mnt/iso/AppStream enabled=1 gpgcheck=0 priority=1 EOF # 3. 配置镜像源存储库优先级 # cat > /etc/yum.repos.d/mirror.repo << 'EOF' [BaseOS] name=Red Hat Enterprise Linux 10 - BaseOS (Mirror) baseurl=https://mirrors.aliyun.com/rockylinux/10/BaseOS/x86_64/os/ enabled=1 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/rockylinux/RPM-GPG-KEY-Rocky-10 priority=2 [AppStream] name=Red Hat Enterprise Linux 10 - AppStream (Mirror) baseurl=https://mirrors.aliyun.com/rockylinux/10/AppStream/x86_64/os/ enabled=1 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/rockylinux/RPM-GPG-KEY-Rocky-10 priority=2 EOF # 4. 清理YUM缓存 # dnf clean all 0 files removed # 5. 生成YUM缓存 # dnf makecache BaseOS (Local) 1.2 MB/s | 3.5 MB 00:03 AppStream (Local) 1.5 MB/s | 5.2 MB 00:04 BaseOS (Mirror) 1.2 MB/s | 3.5 MB 00:03 AppStream (Mirror) 1.5 MB/s | 5.2 MB 00:04 Metadata cache created. # 6. 列出存储库 # 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 BaseOS (Local) Red Hat Enterprise Linux 10 - BaseOS (Local) AppStream (Local) Red Hat Enterprise Linux 10 - AppStream (Local) BaseOS (Mirror) Red Hat Enterprise Linux 10 - BaseOS (Mirror) AppStream (Mirror) Red Hat Enterprise Linux 10 - AppStream (Mirror) # 7. 测试安装软件包 # 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 (Local) 35 k Installing dependencies: nginx-core x86_64 1.22.1-2.el9 BaseOS (Local) 540 k nginx-filesystem noarch 1.22.1-2.el9 BaseOS (Local) 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 网络存储库优先级配置实战案例

4.2.1 完整配置流程

# 1. 安装yum-plugin-priorities插件
# dnf install -y yum-plugin-priorities
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:
yum-plugin-priorities noarch 1.1.31-54.el9_2 appstream 35 k

Transaction Summary
================================================================================
Install 1 Package

Total download size: 35 k
Installed size: 45 k
Downloading Packages:
yum-plugin-priorities-1.1.31-54.el9_2.noarch.rpm 35 kB/s | 35 kB 00:00
——————————————————————————–
Total 35 kB/s | 35 kB 00:00
Running transaction check
Transaction test succeeded
Running transaction
Preparing : 1/1
Installing : yum-plugin-priorities-1.1.31-54.el9_2.noarch 1/1
Running scriptlet: yum-plugin-priorities-1.1.31-54.el9_2.noarch 1/1
Verifying : yum-plugin-priorities-1.1.31-54.el9_2.noarch 1/1

Installed:
yum-plugin-priorities-1.1.31-54.el9_2.noarch

Complete!

# 2. 配置官方存储库优先级
# cat > /etc/yum.repos.d/official.repo << 'EOF' [BaseOS] name=Red Hat Enterprise Linux 10 - BaseOS (Official) baseurl=https://cdn.redhat.com/content/dist/rhel10/10/x86_64/baseos/os enabled=1 gpgcheck=1 gpgkey=https://www.redhat.com/security/data/fd431d51.txt priority=1 [AppStream] name=Red Hat Enterprise Linux 10 - AppStream (Official) baseurl=https://cdn.redhat.com/content/dist/rhel10/10/x86_64/appstream/os enabled=1 gpgcheck=1 gpgkey=https://www.redhat.com/security/data/fd431d51.txt priority=1 EOF # 3. 配置镜像源存储库优先级 # cat > /etc/yum.repos.d/mirror.repo << 'EOF' [BaseOS] name=Red Hat Enterprise Linux 10 - BaseOS (Mirror) baseurl=https://mirrors.aliyun.com/rockylinux/10/BaseOS/x86_64/os/ enabled=1 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/rockylinux/RPM-GPG-KEY-Rocky-10 priority=2 [AppStream] name=Red Hat Enterprise Linux 10 - AppStream (Mirror) baseurl=https://mirrors.aliyun.com/rockylinux/10/AppStream/x86_64/os/ enabled=1 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/rockylinux/RPM-GPG-KEY-Rocky-10 priority=2 EOF # 4. 清理YUM缓存 # dnf clean all 0 files removed # 5. 生成YUM缓存 # dnf makecache BaseOS (Official) 1.2 MB/s | 3.5 MB 00:03 AppStream (Official) 1.5 MB/s | 5.2 MB 00:04 BaseOS (Mirror) 1.2 MB/s | 3.5 MB 00:03 AppStream (Mirror) 1.5 MB/s | 5.2 MB 00:04 Metadata cache created. # 6. 列出存储库 # 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 BaseOS (Official) Red Hat Enterprise Linux 10 - BaseOS (Official) AppStream (Official) Red Hat Enterprise Linux 10 - AppStream (Official) BaseOS (Mirror) Red Hat Enterprise Linux 10 - BaseOS (Mirror) AppStream (Mirror) Red Hat Enterprise Linux 10 - AppStream (Mirror) # 7. 测试安装软件包 # 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 (Official) 1.4 M Installing dependencies: httpd-filesystem noarch 2.4.53-7.el9 AppStream (Official) 12 k httpd-tools x86_64 2.4.53-7.el9 AppStream (Official) 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 存储库优先级故障排查与解决

4.3.1 优先级不生效

# 问题现象:存储库优先级不生效
# 分析步骤:

# 1. 查看错误信息
# 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 (Mirror) 35 k
Installing dependencies:
nginx-core x86_64 1.22.1-2.el9 BaseOS (Mirror) 540 k
nginx-filesystem noarch 1.22.1-2.el9 BaseOS (Mirror) 11 k

# 2. 检查yum-plugin-priorities插件是否安装
# rpm -qa | grep priorities
yum-plugin-priorities-1.1.31-54.el9_2.noarch

# 3. 检查repo文件中的priority配置
# cat /etc/yum.repos.d/local.repo
[BaseOS]
name=Red Hat Enterprise Linux 10 – BaseOS (Local)
baseurl=file:///mnt/iso/BaseOS
enabled=1
gpgcheck=0
priority=1

[AppStream]
name=Red Hat Enterprise Linux 10 – AppStream (Local)
baseurl=file:///mnt/iso/AppStream
enabled=1
gpgcheck=0
priority=1

# 4. 检查DNF配置
# cat /etc/dnf/dnf.conf | grep -i priority
(无输出)

# 5. 启用DNF优先级插件
# cat >> /etc/dnf/dnf.conf << 'EOF' plugins=1 EOF # 6. 清理YUM缓存 # dnf clean all 0 files removed # 7. 重新生成YUM缓存 # dnf makecache BaseOS (Local) 1.2 MB/s | 3.5 MB 00:03 AppStream (Local) 1.5 MB/s | 5.2 MB 00:04 BaseOS (Mirror) 1.2 MB/s | 3.5 MB 00:03 AppStream (Mirror) 1.5 MB/s | 5.2 MB 00:04 Metadata cache created. # 8. 重新安装软件包 # 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 (Local) 35 k Installing dependencies: nginx-core x86_64 1.22.1-2.el9 BaseOS (Local) 540 k nginx-filesystem noarch 1.22.1-2.el9 BaseOS (Local) 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! # 9. 预防措施 # - 确保yum-plugin-priorities插件已安装 # - 启用DNF插件支持 # - 配置正确的priority值 # - 定期检查存储库优先级

生产环境建议:存储库优先级故障排查需要耐心和细致。优先级不生效需要检查插件是否安装和DNF配置。更多学习教程公众号风哥教程itpux_com

Part05-风哥经验总结与分享

5.1 存储库优先级经验总结

存储库优先级经验总结:

  • 本地优先:本地存储库优先级最高
  • 官方次之:官方存储库优先级次之
  • 第三方最低:第三方存储库优先级最低
  • 定期检查:定期检查存储库优先级
  • 验证来源:验证软件包来源

5.2 存储库优先级检查清单

存储库优先级检查清单:

  • 配置前:安装yum-plugin-priorities插件
  • 配置时:配置正确的priority值
  • 配置后:清理YUM缓存、生成YUM缓存
  • 使用时:验证软件包来源
  • 维护时:定期检查存储库优先级
  • 故障排查:检查插件是否安装、DNF配置

5.3 存储库优先级相关工具推荐

存储库优先级相关工具推荐:

  • dnf:DNF软件包管理器
  • yum-plugin-priorities:YUM优先级插件
  • repoquery:软件包查询工具
  • reposync:同步存储库工具
  • dnf-utils:DNF工具集
风哥提示:存储库优先级可以帮助管理员控制软件包的来源,确保系统使用指定版本的软件包。建议在生产环境中配置存储库优先级。

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

联系我们

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

微信号:itpux-com

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