当前位置: 首页 > 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.dtcms.com/a/322808.html

相关文章:

  • 【数据结构入门】栈和队列
  • 网盘短剧资源转存项目源码 支持垮克 带后台 附教程
  • Kafka服务端NIO操作原理解析(二)
  • MX 播放器:安卓设备上的全能视频播放器
  • 【解决方法】华为电脑的亮度调节失灵
  • 本地部署接入 whisper + ollama qwen3:14b 总结字幕
  • 服务机器人选择屏幕的逻辑
  • 微软推出革命性AI安全工具Project IRE,重塑网络安全防御新范式
  • Orange的运维学习日记--37.iSCSI详解与服务部署
  • FreeRTOS学习笔记:任务通知和软件定时器
  • jQuery 零基础学习第一天
  • 数据结构—二叉树及gdb的应用
  • 【贪心】P4873 [USACO14DEC] Cow Jog G|省选-
  • MBR分区nvme固态硬盘安装win7--非UEFI启动和GPT分区
  • llm本地部署+web访问+交互
  • Oracle字段操作
  • [TryHackMe]Challenges---Game Zone游戏区
  • 力扣热题100-----118.杨辉三角
  • Kettle ETL 工具存在的问题以及替代方案的探索
  • Arm Development Studio 安全通告:CVE-2025-7427
  • 什么情况下需要JVM调优?
  • Java-file类
  • 力扣 30 天 JavaScript 挑战 第二题笔记
  • 每日算法刷题Day59:8.9:leetcode 队列8道题,用时2h30min
  • 【攻防实战】从外到内全链路攻防实战纪实
  • python---类型别名
  • 1073. 沙漏
  • sqli-labs通关笔记-第40关 GET字符型堆叠注入(单引号括号闭合 手工注入+脚本注入两种方法)
  • J2000平赤道系、瞬时平赤道系与瞬时真赤道系
  • (论文速读)重新思考CNN生成网络中的上采样操作