说明:此测试环境用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
"""
以上仅凭回忆操作所记,有问题后续测试更新
"""