搭建本地 RHEL 源

一、注册 Red Hat 开发者订阅

1.1 注册账号

访问 https://developers.redhat.com/register 注册账号。

1.2 获取激活密钥

登录 Red Hat Hybrid Cloud Console:

  • 路径:Red Hat Enterprise Linux → System Configuration → Activation Keys
  • 创建或查看现有激活密钥
  • 记录 Organization ID 和 Activation Key

1.3 在联网服务器上注册

bash 复制代码
sudo subscription-manager register --org your-org-id --activationkey your-activation-key

# 验证
sudo subscription-manager list
sudo yum repolist enabled

成功标志 :yum repolist 显示 rhel-8-for-x86_64-baseos-rpms 和 rhel-8-for-x86_64-appstream-rpms


二、同步 RHEL 仓库到本地

2.1 安装工具

bash 复制代码
sudo yum install -y reposync createrepo

2.2 创建同步目录

bash 复制代码
sudo mkdir -p /repo/rhel/8.10

2.3 同步仓库

bash 复制代码
sudo reposync -p /repo/rhel/8.10     --repoid=rhel-8-for-x86_64-baseos-rpms     --repoid=rhel-8-for-x86_64-appstream-rpms     --newest-only --download-metadata
参数 含义
-p /repo/rhel/8.10 同步目标目录
--repoid 指定仓库 ID
--newest-only 只同步最新版本
--download-metadata 同时下载 repodata 元数据

预计大小:10-15 GB

2.4 验证

bash 复制代码
ls /repo/rhel/8.10/
du -sh /repo/rhel/8.10/

三、配置 nginx 作为内网源服务器

3.1 确认目录结构

bash 复制代码
ls /repo/rhel/8.10/rhel-8-for-x86_64-baseos-rpms/
ls /repo/rhel/8.10/rhel-8-for-x86_64-appstream-rpms/

3.2 创建 nginx 配置

bash 复制代码
cat > /docker/nginx-ic/conf.d/repo.conf << 'EOF'
server {
    listen 9000;
    server_name repo.********.com;

    location /rhel/8.10/baseos/ {
        alias /repo/rhel/8.10/rhel-8-for-x86_64-baseos-rpms/;
        autoindex on;
        autoindex_exact_size off;
        autoindex_localtime on;
    }

    location /rhel/8.10/appstream/ {
        alias /repo/rhel/8.10/rhel-8-for-x86_64-appstream-rpms/;
        autoindex on;
        autoindex_exact_size off;
        autoindex_localtime on;
    }
}
EOF
配置项 作用
listen 9000 监听端口
server_name 服务器域名
location /rhel/8.10/baseos/ URL 路径匹配
alias /repo/rhel/8.10/... 映射到实际磁盘路径
autoindex on 启用目录浏览

3.3 修改 docker-compose.yml

bash 复制代码
cat > /docker/nginx-ic/docker-compose.yml << 'EOF'
version: '3.9'
services:
  test-nginx:
    container_name: nginx-ic
    image: nginx:alpine
    ports:
      - "9000:9000"
    volumes:
      - /docker/nginx-ic/conf.d:/etc/nginx/conf.d
      - /docker/nginx-ic/nginx.conf:/etc/nginx/nginx.conf
      - /docker/nginx-ic/logs:/var/log/nginx
      - /repo/rhel/8.10:/repo/rhel/8.10:ro
    restart: unless-stopped
EOF

3.4 重启 nginx

bash 复制代码
cd /docker/nginx-ic
docker-compose down
docker-compose up -d

3.5 验证

bash 复制代码
curl http://localhost:9000/rhel/8.10/baseos/
curl http://localhost:9000/rhel/8.10/appstream/
curl http://localhost:9000/rhel/8.10/baseos/repodata/repomd.xml

四、内网机器配置

4.1 配置 hosts(如使用域名)

bash 复制代码
echo "192.168.1.1 repo.********.com" | sudo tee -a /etc/hosts

4.2 禁用 subscription-manager

bash 复制代码
sudo sed -i 's/^enabled=1/enabled=0/' /etc/yum/pluginconf.d/subscription-manager.conf

4.3 创建本地源配置

bash 复制代码
sudo tee /etc/yum.repos.d/internal-rhel.repo << 'EOF'
[internal-baseos]
name=Internal RHEL 8.10 BaseOS
baseurl=http://repo.********.com:9000/rhel/8.10/baseos/
enabled=1
gpgcheck=0

[internal-appstream]
name=Internal RHEL 8.10 AppStream
baseurl=http://repo.********.com:9000/rhel/8.10/appstream/
enabled=1
gpgcheck=0
EOF

4.4 验证

bash 复制代码
sudo yum clean all
sudo yum makecache

五、使用本地源

bash 复制代码
# 查看可用包
sudo yum list available

# 安装软件
sudo yum install package-name

# 更新系统
sudo yum update

六、常用命令

命令 作用
reposync -p /repo/rhel/8.10 --newest-only 同步最新版本
createrepo /path/to/repo 生成元数据
yum clean all 清除缓存
yum makecache 重建缓存
yum repolist 查看可用源
相关推荐
郝亚军24 分钟前
ec_private.pem的生成方法
linux·运维·服务器
NendoZen1 小时前
Arch Linux解决Grub无法SAVEDEFAULT问题(uki启动问题)
linux·运维·服务器
忆挽篱笙歌2 小时前
进程控制管理
linux·运维·服务器
Escalating_xu2 小时前
【Linux 网络编程】connect 的断线重连:用状态机写一个能恢复连接的 TCP 客户端
linux·网络·tcp/ip
Zucker n3 小时前
英语“论文”语法检查工具
linux·windows
苏宸啊4 小时前
Reactor反应堆模式
linux
骇客野人5 小时前
Linux 全套实操方案(含目录详解、文件传输、日志、文件规范、环境变量、Java 应用部署运维)
java·linux·运维
_菜鸟果果5 小时前
高德地图 JS API 2.0 在国产 Linux/ARM 电脑上渲染失败 的排查与解决
linux·开发语言·javascript
GeW5 小时前
飞行汽车交付阿联酋,真正先“起飞”的是低空数据基座——红帽Linux与数据库高可用为什么成了低空运营的隐形跑道
linux
0+1115 小时前
Linux --DNS与ICMP
linux·运维·服务器