搭建本地 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 IDActivation 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-rpmsrhel-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 查看可用源
相关推荐
2301_809051142 小时前
Linux 网络编程 学习笔记
linux·网络·学习
坤昱2 小时前
cfs调度类深入解刨——最新内核细节分析2
linux·服务器·cfs·cfs调度·eevdf调度·eevdf·kernel 7.1
艾莉丝努力练剑3 小时前
【Linux:文件】Ext系列文件系统进阶
linux·运维·服务器·c++·文件系统·文件io·ext
海市公约3 小时前
Linux核心基础命令与权限管理实战指南
linux·运维·服务器·vim·权限管理·系统监控·命令行
eggcode3 小时前
【Qt学习】Linux(ARM架构)在线安装Qt6.x
linux·qt·学习·arm
wkd_0073 小时前
Ubuntu 22.04 Samba 连接故障排查记:从“用户名或密码错误”到 NTLM 版本不兼容
linux·运维·ubuntu
mixboot4 小时前
Linux 进程工作目录查看利器:pwdx 命令详解
linux·运维·服务器
旺仔来了5 小时前
不联网的Linux下部署python环境
linux·开发语言·python
Irene19916 小时前
WSL 切换磁盘后验证完整性(MobaXterm、Powershell、WSL 的区别)
linux·wsl·mobaxterm
扛枪的书生7 小时前
Keepalived 学习总结
linux