搭建本地 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 查看可用源
相关推荐
A小辣椒8 小时前
TShark:基础知识
linux
AlfredZhao10 小时前
OCI 明明分配了 200G 系统盘,为什么 df 只看到 30G?
linux·oci
AlfredZhao1 天前
vi 删除指定范围的行,不用再反复按 dd
linux·vi
用户9718356334661 天前
银河麒麟 KY10 申威(SW64) 安装 nginx-1.16.1-2.p01.ky10.sw_64.rpm 详细步骤
linux
猪脚踏浪1 天前
linux 拷贝文件或目录到指定的位置
linux
摇滚侠2 天前
Linux CentOS7 rpm 安装 MySQL 5.7
linux·运维·mysql
bush42 天前
嵌入式linux学习记录十四、术语
linux·嵌入式
载数而行5202 天前
Linux 11 动态监控指令top
linux
不会C语言的男孩2 天前
Linux 系统编程 · 第 8 章:进程基础
linux·c语言
古城小栈2 天前
Unix 与 Linux 异同小叙
linux·服务器·unix