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

CentOS 5.4 新增/移除軟體報錯?製作本地 ISO YUM 源完美解決

編輯:關於 Linux

CentOS 5.4 使用「新增/移除應用程式」時頻繁報錯,無法正常安裝軟體。根因是系統預設尋找光碟源,但光碟機可能無媒體或路徑錯誤。解決之道:將安裝光碟製作成 ISO 檔掛載為本地 YUM 源,並配置 autofs 實現按需自動掛載。

核心思路

  1. 將光碟內容鏡像為 ISO 檔(如 /var/ftp/centos.iso)。
  2. 建立 autofs 自動掛載點(如 /yum/iso),進入目錄時自動掛載 ISO。
  3. 停用網路源(CentOS-Base.repo),啟用本地媒體源(CentOS-Media.repo)。

詳細操作步驟

1. 製作 ISO 鏡像檔

# 放入 CentOS 5.4 安裝光碟
dd if=/dev/cdrom of=/var/ftp/centos.iso
# 或
cat /dev/cdrom > /var/ftp/centos.iso
# 耐心等待完成(視光碟速度約數分鐘)

路徑與檔名可自訂,例如放在桌面:dd if=/dev/cdrom of=~/Desktop/centos.iso。

2. 配置 autofs 自動掛載

# 建立觸發目錄
mkdir -p /yum

# 編輯 /etc/auto.master,新增一行
/yum /etc/auto.img

# 建立 /etc/auto.img,內容如下(注意格式:首欄無斜線)
iso -fstype=iso9660,loop :/var/ftp/centos.iso

關鍵細節:

  • /etc/auto.master 中的 /yum 對應掛載點前綴 /yum/iso。
  • /etc/auto.img 首欄 iso 對應掛載點後綴,前方不可加斜線。
  • -fstype=iso9660,loop 中的減號、逗號、冒號皆不可漏。

3. 啟動 autofs 並驗證

service autofs restart
cd /yum/iso
ls
# 應顯示光碟內容(如 CentOS 目錄、repodata 等)

4. 切換 YUM 來源

cd /etc/yum.repos.d
mv CentOS-Base.repo CentOS-Base.repo.bak
# 確保 CentOS-Media.repo 存在且 baseurl 指向 file:///yum/iso
# 若無該檔,自行建立:
[c5-media]
name=CentOS 5.4 - Media
baseurl=file:///yum/iso
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

5. 測試安裝軟體

yum clean all
yum list
yum install <套件名>
# 應可正常下載安裝,不再報錯

YUM 本地源配置示意圖

優勢總結

  • 一次製作,永久可用,無需每次插光碟。
  • autofs 按需掛載,不佔用資源。
  • 完全離線環境亦可安裝軟體,適合內網伺服器。
Copyright © Windows教程網 All Rights Reserved