說明:此測試環境用Red Hat Enterprise Linux 5.4 作為測試機,同理,本文理論上可以解決關于RHEL和CentOS 5版本甚至6版本的yum更新源的問題(其他版本未測試)
推薦使用鏡像源服務器網站:http://vault.centos.org/
問題描述:
1、RHEL的YUM源需要注冊用戶才能更新使用,由于CentOS和RHEL基本沒有區別,并且CentOS已經被REHL收購。所以將RHEL的YUM源替換為CentOS即可
2、CentOS 5 在2017-03-31日已經結束支持,不再提供維護更新,所以包括阿里云鏡像站的文件可能都是過時或已經有部分文件缺失
環境:Red Hat Enterprise Linux 5.4
解決方法:
1.清除原有RHEL的YUM及相關軟件包。
~]#? rpm -qa | grep yum | xargs rpm -e --nodeps
~]#? rpm -qa |grep python-urlgrabber|xargs rpm -e --nodeps
檢查yum是否刪除干凈
~]#rpm -qa |grep yum?
2.備份或只保留/etc/yum.repos.d/rhel-debuginfo.repo,其他.repo文件都刪掉,這里我選擇備份
~]# cp /etc/yum.repos.d/rhel-debuginfo.repo /etc/yum.repos.d/rhel-debuginfo.repo.bak
3.將RHEL的yum源更換同版本的CentOS的yum源,修改baseurl和gpgkey為目標鏡像服務器
baseurl=http://vault.centos.org/5.4/os/i386/
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-5
原RHEL的yum源:
修改為CentOS的yum源:
4.在安裝yum前,先下載相應的rpm包
~]# wget http://vault.centos.org/5.4/os/i386/CentOS/python-iniparse-0.2.3-4.el5.noarch.rpm
~]# wget http://vault.centos.org/5.4/os/i386/CentOS/yum-metadata-parser-1.1.2-3.el5.centos.i386.rpm
~]# wget http://vault.centos.org/5.4/os/i386/CentOS/yum-3.2.22-20.el5.centos.noarch.rpm
~]# wget http://vault.centos.org/5.4/os/i386/CentOS/yum-fastestmirror-1.1.16-13.el5.centos.noarch.rpm
5.安裝yum軟件包
~]# rpm -ivh python-iniparse-0.2.3-4.el5.noarch.rpm
~]# rpm -ivh yum-metadata-parser-1.1.2-3.el5.centos.i386.rpm
~]# rpm -ivh yum-3.2.22-20.el5.centos.noarch.rpm yum-fastestmirror-1.1.16-13.el5.centos.noarch.rpm
第三條命令一次安裝兩個rpm文件,因為他們存在依賴關系,不在一起的話會安裝失敗。
6.更換yum源,使用http://vault.centos.org/作為更新源
將其中的baseurl中的$releasever之前部分替換成相應歷史源站地址和版本號
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.? You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base - 163.com
baseurl=http://vault.centos.org/5.4/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
#released updates
[updates]
name=CentOS-$releasever - Updates - 163.com
baseurl=http://vault.centos.org/5.4/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
#packages used/produced in the build but not released
[addons]
name=CentOS-$releasever - Addons - 163.com
baseurl=http://vault.centos.org/5.4/addons/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=addons
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - 163.com
baseurl=http://vault.centos.org/5.4/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - 163.com
baseurl=http://vault.centos.org/5.4/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - 163.com
baseurl=http://vault.centos.org/5.4/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
7.確認在 /etc/yum.repos.d/目錄沒有除了CentOS-Base.repo之外其他以repo結尾的文件,有的話刪除或做備份處理
8.yum更新和啟用更新源
~]# yum clean all
~]# yum makecache
過程出現time out 超時尋找其他mirror鏡像源,報錯,基本是下載資源和網速問題,可以退出安裝重新yum makecache
出現yum.pid報錯,刪掉重新makecache
~]# rm -r /var/run/yum.pid
~]# yun makecache
9.安裝完成,測試驗證
~]# yum install telnet-server
"""
以上僅憑回憶操作所記,有問題后續測試更新
"""