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

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.xdnf.cn/news/17486.html

相关文章:

  • Java类和对象课上练习题目设计
  • 计算机网络:CIDR地址块如何划分子网
  • 24SpringCloud黑马商城微服务整合Seata重启服务报错的解决办法
  • Day 36: 复习
  • 【机器学习深度学习】模型选型:如何根据模型的参数算出合适的设备匹配?
  • 05.【数据结构-C语言】栈(先进后出,栈的实现:进栈、出栈、获取栈顶元素,栈实现代码,括号匹配问题)
  • [Oracle] SUBSTR()函数
  • [CUDA] CUTLASS | `CuTe DSL` 创新
  • 化工安防误报率↓82%!陌讯多模态融合算法实战解析
  • ARM CPU 安全更新:Training Solo(关于 Spectre-v2 攻击中域隔离机制的局限性)
  • 在ubuntu服务器下安装cuda和cudnn(笔记)
  • 基于Prometheus、Grafana、Loki与Tempo的统一监控平台故障排查与解决方案
  • 3款强力的Windows系统软件卸载工具
  • STM32的中断系统
  • 大数据与财务管理:未来就业的黄金赛道
  • 第4章 程序段的反复执行4.2while语句P128练习题(题及答案)
  • Mistral Small 3.1 架构深度解析:高效小型模型的巅峰之作
  • 直接插入排序算法:可视化讲解与C语言实现
  • drippingblues靶机教程
  • 飞算JavaAI:人工智能与Java的创新融合与应用前景
  • 逻辑回归详解:原理、应用与实践
  • OceanBase架构设计
  • 後端開發技術教學(四) 數據交互延伸
  • 如何更改win11自带录音机所录制文件的存储路径
  • 新手入门:从零开始使用这份 LaTeX 模板
  • nishang--安装、使用
  • Java Stream 使用 Fork/Join框架的分治任务模型
  • 计算机视觉CS231n学习(6)
  • 基于遗传优化的稀疏线阵最优排布算法matlab仿真
  • day30-HTTP