搭建本地 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 查看可用源
相关推荐
李可以量化1 小时前
QMT 量化交易:北交所数据获取与实时涨跌统计完整教程
linux·服务器·windows
lolo大魔王3 小时前
Linux列出文件和目录
linux·运维·服务器
zadyd3 小时前
vLLM Linux 双卡部署大模型服务器指南
linux·人工智能·python·机器学习·vllm
j_xxx404_3 小时前
Linux命名管道:跨进程通信实战指南|附源码
linux·运维·服务器·人工智能·ai
楼田莉子4 小时前
仿Muduo的高并发服务器:Http协议模块
linux·服务器·c++·后端·学习
milo.qu10 小时前
RockyLinux9.7 docker部署Jisti Meet
linux·docker·容器
GanGanGanGan_10 小时前
CentOS 7.9 glibc 2.17 源码编译升级到 glibc 2.31
linux·运维·centos·glibc
charlie11451419110 小时前
嵌入式Linux驱动开发——class 和 device 模型 - 自动创建设备节点的幕后机制
linux·运维·驱动开发
枳实-叶12 小时前
【Linux驱动开发】第四天:dmesg日志全解+驱动加载失败极速排查
linux·运维·驱动开发