当前位置: 首页 > news >正文

Redhat Linux 9.6 配置本地 yum 源

在这里插入图片描述

文章目录

    • 1. 安装并配置HTTP服务器
    • 2. 创建本地仓库目录结构
    • 3. 同步仓库数据到Web目录
    • 4. 配置防火墙
    • 5. 配置SELinux(如果启用)
    • 6. 创建本地仓库配置文件
    • 7. 创建首页和目录浏览
    • 8. 配置Apache目录浏览
    • 9. 测试HTTP仓库服务
    • 10. 为其他客户端提供配置文件
    • 11. 创建自动更新脚本
    • 12. 禁用官方源

1. 安装并配置HTTP服务器

bash

# 安装httpd服务
yum install -y httpd# 启动并设置开机自启
systemctl enable httpd
systemctl start httpd
systemctl status httpd

2. 创建本地仓库目录结构

bash

# 创建Web目录下的仓库目录
mkdir -p /var/www/html/repo/{baseos,appstream}# 设置正确的权限
chown -R apache:apache /var/www/html/repo
chmod -R 755 /var/www/html/repo

3. 同步仓库数据到Web目录

bash

# 同步BaseOS仓库到Web目录
dnf reposync --download-metadata --newest-only --repo=rhel-9-for-x86_64-baseos-rpms -p /var/www/html/repo/# 同步AppStream仓库到Web目录
dnf reposync --download-metadata --newest-only --repo=rhel-9-for-x86_64-appstream-rpms -p /var/www/html/repo/# 创建仓库元数据
createrepo /var/www/html/repo/rhel-9-for-x86_64-baseos-rpms/
createrepo /var/www/html/repo/rhel-9-for-x86_64-appstream-rpms/

输出:

$ dnf reposync --download-metadata --newest-only --repo=rhel-9-for-x86_64-baseos-rpms -p /var/www/html/repo/
...
(11098/11100): python3-libxml2-2.9.13-12.el9_6.x86_64.rpm                                                                                                      53 kB/s | 225 kB     00:04
(11099/11100): libxml2-2.9.13-12.el9_6.x86_64.rpm                                                                                                             138 kB/s | 747 kB     00:05
(11100/11100): libxml2-2.9.13-12.el9_6.i686.rpm                                                                                                               112 kB/s | 785 kB     00:07
[root@localhost ~]#

4. 配置防火墙

bash

# 开放HTTP端口
firewall-cmd --permanent --add-service=http
firewall-cmd --reload# 检查防火墙规则
firewall-cmd --list-all

5. 配置SELinux(如果启用)

bash

# 设置SELinux上下文
setsebool -P httpd_enable_homedirs on
restorecon -R /var/www/html/repo

6. 创建本地仓库配置文件

在本机创建本地HTTP源配置:

bash

cat > /etc/yum.repos.d/local-http.repo << 'EOF'
[local-baseos-http]
name=Local Red Hat Enterprise Linux 9 - BaseOS (HTTP)
baseurl=http://192.168.0.10/repo/rhel-9-for-x86_64-baseos-rpms/
enabled=1
gpgcheck=0
priority=1[local-appstream-http]
name=Local Red Hat Enterprise Linux 9 - AppStream (HTTP)
baseurl=http://192.168.0.10/repo/rhel-9-for-x86_64-appstream-rpms/
enabled=1
gpgcheck=0
priority=1
EOF

7. 创建首页和目录浏览

bash

# 创建仓库首页
cat > /var/www/html/index.html << 'EOF'
<!DOCTYPE html>
<html>
<head><title>Local RHEL 9 Repository Server</title><style>body { font-family: Arial, sans-serif; margin: 40px; }h1 { color: #cc0000; }.repo-link { display: block; margin: 10px 0; padding: 10px; background: #f0f0f0; text-decoration: none; }.repo-link:hover { background: #e0e0e0; }</style>
</head>
<body><h1>Red Hat Enterprise Linux 9 本地仓库服务器</h1><p>服务器地址: 192.168.0.10</p><h2>可用仓库:</h2><a href="/repo/rhel-9-for-x86_64-baseos-rpms/" class="repo-link">BaseOS Repository</a><a href="/repo/rhel-9-for-x86_64-appstream-rpms/" class="repo-link">AppStream Repository</a><h2>客户端配置:</h2><pre>
[local-baseos-http]
name=Local Red Hat Enterprise Linux 9 - BaseOS (HTTP)
baseurl=http://192.168.0.10/repo/rhel-9-for-x86_64-baseos-rpms/
enabled=1
gpgcheck=0[local-appstream-http]
name=Local Red Hat Enterprise Linux 9 - AppStream (HTTP)
baseurl=http://192.168.0.10/repo/rhel-9-for-x86_64-appstream-rpms/
enabled=1
gpgcheck=0</pre>
</body>
</html>
EOF

8. 配置Apache目录浏览

bash

# 在Apache配置中启用目录浏览
cat > /etc/httpd/conf.d/repo.conf << 'EOF'
<Directory "/var/www/html/repo">Options +Indexes +FollowSymLinksAllowOverride NoneRequire all grantedIndexOptions FancyIndexing HTMLTable SuppressDescription
</Directory>
EOF# 重启Apache服务
systemctl restart httpd

9. 测试HTTP仓库服务

bash

# 测试本地访问
curl -I http://192.168.0.10/
curl -I http://192.168.0.10/repo/# 清理并测试yum缓存
yum clean all
yum repolist# 测试安装软件包
yum install -y tree

10. 为其他客户端提供配置文件

其他RHEL 9机器可以使用以下配置:

bash

# 在客户端机器上执行
cat > /etc/yum.repos.d/local-http.repo << 'EOF'
[local-baseos-http]
name=Local Red Hat Enterprise Linux 9 - BaseOS (HTTP)
baseurl=http://192.168.0.10/repo/rhel-9-for-x86_64-baseos-rpms/
enabled=1
gpgcheck=0
priority=1[local-appstream-http]
name=Local Red Hat Enterprise Linux 9 - AppStream (HTTP)
baseurl=http://192.168.0.10/repo/rhel-9-for-x86_64-appstream-rpms/
enabled=1
gpgcheck=0
priority=1
EOF# 禁用原始仓库(可选)
# sed -i 's/enabled=1/enabled=0/g' /etc/yum.repos.d/redhat.repo

11. 创建自动更新脚本

bash

cat > /usr/local/bin/update-http-repo.sh << 'EOF'
#!/bin/bash
echo "$(date): 开始更新本地HTTP仓库"# 同步仓库
dnf reposync --download-metadata --newest-only --delete --repo=rhel-9-for-x86_64-baseos-rpms -p /var/www/html/repo/
dnf reposync --download-metadata --newest-only --delete --repo=rhel-9-for-x86_64-appstream-rpms -p /var/www/html/repo/# 重新创建元数据
createrepo --update /var/www/html/repo/rhel-9-for-x86_64-baseos-rpms/
createrepo --update /var/www/html/repo/rhel-9-for-x86_64-appstream-rpms/# 设置权限
chown -R apache:apache /var/www/html/repo
chmod -R 755 /var/www/html/repoecho "$(date): 仓库更新完成"
EOFchmod +x /usr/local/bin/update-http-repo.sh

现在您可以通过浏览器访问 http://192.168.0.10 来查看仓库状态,其他机器也可以使用这个HTTP源来安装软件包。

12. 禁用官方源

方法 1:用 subscription-manager 禁用(推荐)

# 禁用 BaseOS
subscription-manager repos --disable=rhel-9-for-x86_64-baseos-rpms# 禁用 AppStream
subscription-manager repos --disable=rhel-9-for-x86_64-appstream-rpms

这样会在 /etc/yum.repos.d/redhat.repo 中把对应仓库的 enabled=1 改成 enabled=0,并且保留本地源可用。

方法 2:直接编辑 /etc/yum.repos.d/redhat.repo

vi /etc/yum.repos.d/redhat.repo
找到这两个段落:
[rhel-9-for-x86_64-baseos-rpms]
enabled=1[rhel-9-for-x86_64-appstream-rpms]
enabled=1enabled=1 改成:
enabled=0
保存退出即可。

方法 3:全局禁用 redhat.repo 文件(不建议,太绝对)
如果你根本不想让 RHEL 系统自动生成 redhat.repo:

subscription-manager config --rhsm.manage_repos=0

执行后 subscription-manager 将不再管理或更新 redhat.repo,只会用你手动添加的 .repo 文件。

✅ 建议:
如果你是离线环境用本地 HTTP 仓库,就用 方法 1 禁用官方源,避免 yum/dnf 在访问网络时超时;这样还能保留 subscription-manager 的正常工作。

http://www.lryc.cn/news/615300.html

相关文章:

  • qt文件操作与qss基础
  • 2025彩虹易支付官方正版无删减完整版源码
  • B.10.01.5-电商系统的设计模式应用实战
  • 【Canvas与旗帜】圆角蓝底大黄白星十一红白带旗
  • Node.js特训专栏-实战进阶:22. Docker容器化部署
  • 北京JAVA基础面试30天打卡05
  • STM32的中断系统
  • 05.【数据结构-C语言】栈(先进后出,栈的实现:进栈、出栈、获取栈顶元素,栈实现代码,括号匹配问题)
  • 【排序算法】③直接选择排序
  • 心灵笔记:思考三部曲
  • 使用 Spring Boot 集成七牛云实现图片/文件上传
  • 机器翻译:FastText算法详解与Python的完整实现
  • istio笔记03--快速上手多集群mesh
  • 支持 UMD 自定义组件与版本控制:从 Schema 到动态渲染
  • [FOC电机控制]霍尔传感器于角度问题
  • 贪心----1.买卖股票的最佳时机
  • GoEnhance AI-AI视频风格转换工具
  • 利用whisper api实现若无字幕则自动下载音频并用 whisper 转写,再用 LLM 总结。
  • 飞算JavaAI:人工智能与Java的创新融合与应用前景
  • Klipper-G3圆弧路径算法
  • 四、RuoYi-Cloud-Plus 部署时nacos配置服务启动
  • 驾驶场景玩手机识别准确率↑32%:陌讯动态特征融合算法实战解析
  • 最长回文子串(马拉车/Manacher‘s )算法
  • Android 设置/修改系统NTP服务地址
  • 【Avalonia】无开发者账号使用iOS真机调试跨平台应用
  • 提示条贴合右侧边栏
  • Java 大视界 -- Java 大数据在智能家居场景联动与用户行为模式挖掘中的应用(389)
  • 虚拟机Ubuntu重启发现找不到共享文件夹
  • 2025AI颠覆认知!解锁智能新纪元
  • ubuntu修改密码