Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

RedHat 5/6 配置 YUM 使用 CentOS 鏡像源與本地光碟源離線更新完整指南

編輯:Linux 教學

背景痛點

RHEL 官方 YUM 源需付費訂閱 (RHN/CDN),未授權系統無法直接 yum update。CentOS 作為 RHEL 重建版,二進制相容且免費,是完美替代源。

方案一:配置 CentOS 網路鏡像源 (聯網環境)

1. 匯入 CentOS GPG 金鑰

rpm --import https://ftp.twaren.net/Linux/CentOS/RPM-GPG-KEY-CentOS-5
# 或對應版本:CentOS-6、CentOS-7、CentOS-8、CentOS-9-Stream

2. 編輯 /etc/yum.repos.d/rhel-debuginfo.repo (或新建 .repo 檔)

[base]
name=CentOS-$releasever - Base
baseurl=https://ftp.twaren.net/Linux/CentOS/5/os/$basearch/
gpgcheck=1

[updates]
name=CentOS-$releasever - Updates
baseurl=https://ftp.twaren.net/Linux/CentOS/5/updates/$basearch/
gpgcheck=1

[extras]
name=CentOS-$releasever - Extras
baseurl=https://ftp.twaren.net/Linux/CentOS/5/extras/$basearch/
gpgcheck=1

[addons]
name=CentOS-$releasever - Addons
baseurl=https://ftp.twaren.net/Linux/CentOS/5/addons/$basearch/
gpgcheck=1
  • $releasever 自動展開為 5/6/7/8/9
  • $basearch 自動展開為 i386/x86_64
  • 鏡像站建議選擇地理最近:ftp.twaren.net (台灣)、mirrors.aliyun.com (大陸)、mirror.centos.org (官方)

3. 清除快取並測試

yum clean all
yum makecache
yum install httpd  # 驗證安裝

方案二:配置本地光碟/ISO 離線源 (隔離網環境)

1. 掛載安裝光碟或 ISO

mkdir -p /mnt/cdrom
mount /dev/cdrom /mnt/cdrom
# 或掛載 ISO 檔
mount -o loop rhel-server-5.4-x86_64-dvd.iso /mnt/cdrom

2. 備份原 repo 檔並建立離線源

cd /etc/yum.repos.d
cp rhel-debuginfo.repo rhel-debuginfo.repo.bak

cat > rhel-debuginfo.repo <<'EOF'
[rhel-dvd]
name=Red Hat Enterprise Linux $releasever - DVD
baseurl=file:///mnt/cdrom/Server
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
EOF

3. 測試安裝

yum clean all
yum install ntp

進階:建立本地 YUM 儲存庫服務 (HTTP/FTP)

# 1. 同步鏡像 (需聯網機器)
reposync -r base -r updates -r extras --download_path=/data/repo/centos/7

# 2. 建立索引
createrepo /data/repo/centos/7/base
createrepo /data/repo/centos/7/updates

# 3. 架設 HTTP 服務
yum install -y httpd
ln -s /data/repo /var/www/html/repo
systemctl start httpd

# 4. 客戶端配置
baseurl=https://repo-server/repo/centos/7/base/$basearch/

常見問題排查

現象原因解決
GPG check failed金鑰不匹配/未匯入rpm --import 正確版本金鑰
404 Not Foundbaseurl 路徑錯誤瀏覽器驗證 URL、注意 $releasever/$basearch 展開
依賴關係缺失源不完整 (僅掛載 DVD 缺 updates)啟用 updates 源或手動下載 RPM
yum 掛起快取損毀yum clean dbcache
Copyright © Windows教程網 All Rights Reserved