一、注册 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 |
查看可用源 |