redhat默认不支持第三方的yum源,要求有rhn账号,下面就rhel5和rhel6改为centos源

一、rhel5.5 X86_64更改为centos的yum源

查看系统自带的yum相关的rpm包

 rpm -qa|grep yum

删掉系统自带的yum相关的包

rpm -e --nodeps yum-updatesd-0
rpm -e --nodeps yum-security  
rpm -e --nodeps yum-metadata-p
rpm -e --nodeps yum-rhn-plugin

安装163yum包,三个yum包有依赖关系,需要一起安装

wget  http://mirrors.163.com/centos/5/os/x86_64/CentOS/python-iniparse-0.2.3-6.el5.noarch.rpm    
wget http://mirrors.163.com/centos/5/os/x86_64/CentOS/yum-fastestmirror-1.1.16-21.el5.centos.noarch.rpm
wget          
wget 
rpm -ivh python-iniparse-0.2.3-6.el5.noarch.rpm  
rpm -ivh  yum-fastestmirror-1.1.16-21.el5.centos.noarch.rpm yum-3.2.22-40.el5.centos.noarch.rpm yum-metadata-parser-1.1.2-4.el5.x86_64.rpm

在/etc/yum.repos.d下将原有的repo文件重命名,新建一个Base.repo

[base]
name=Red Hat Enterprise Linux $releasever - Base
baseurl=http://mirror.centos.org/centos/5/os/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
 
#released updates
[updates]
name=Red Hat Enterprise Linux $releasever - Updates
baseurl=http://mirror.centos.org/centos/5/updates/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
 
#packages used/produced in the build but not released
[addons]
name=Red Hat Enterprise Linux $releasever - Addons
baseurl=http://mirror.centos.org/centos/5/addons/$basearch/
pgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
 
#additional packages that may be useful
[extras]
name=Red Hat Enterprise Linux $releasever - Extras
baseurl=http://mirror.centos.org/centos/5/extras/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
 
#additional packages that extend functionality of existing packages
[centosplus]
name=Red Hat Enterprise Linux $releasever - Plus
baseurl=http://mirror.centos.org/centos/5/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
 
#contrib - packages by Centos Users
[contrib]
name=Red Hat Enterprise Linux $releasever - Contrib
baseurl=http://mirror.centos.org/centos/5/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

这里也可以使用mirrors.163.com或者mirrors.aliyun.com的yum源, rhel6则以163yum源为例,导入key

rpm --import http://mirror.centos.org/centos/5/os/x86_64/RPM-GPG-KEY-CentOS-5

生成缓存

yum clean all
yum makecache

如果配置成功则会提示加载成功


二、redhat6.4 X86_64更改为centos的yum源

删除原有的yum相关的rpm包

 rpm -qa|grep yum
 rpm -e --nodeps yum-rhn-plugin
 rpm -e --nodeps yum-metadata-parser
 rpm -e --nodeps yum-utils
 rpm -e --nodeps yum-plugin-security
 rpm -e --nodeps rhn-check

下载安装包并安装

mkdir -p /server/tools
 cd /server/tools/
 wget http://mirrors.163.com/centos/6/os/x86_64/Packages/python-iniparse-0.3.1-2.1.el6.noarch.rpm
 wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-3.2.29-69.el6.centos.noarch.rpm
 wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-metadata-parser-1.1.2-16.el6.x86_64.rpm
 wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.30-30.el6.noarch.rpm
  rpm -ivh python-iniparse-0.3.1-2.1.el6.noarch.rpm 
 rpm -ivh yum-3.2.29-69.el6.centos.noarch.rpm yum-metadata-parser-1.1.2-16.el6.x86_64.rpm yum-plugin-fastestmirror-1.1.30-30.el6.noarch.rpm

重命名原有自带的repo文件,并下载163的repo文件

 cd /etc/yum.repos.d/
 mv rhel-source.repo rhel-source.repo.bak
 wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
 rpm --import http://mirrors.163.com/centos/6/os/x86_64/RPM-GPG-KEY-CentOS-6
 sed -i 's#$releasever#6#g' CentOS6-Base-163.repo

清空缓存,并重新生成

 yum clean all
 yum makecache

如果配置阿里的yum源,则可以加入如下命令

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

至此rhel6配置centos源配置完成