分分钟搞定让RHEL 5使用CentOS 5的yum源进行更新


相信大部分使用Red Hat Enterprise Linux 5的人都是没有在RHN上注册的,这样导致我们无法直接使用Red Hat提供的yum源来安装与更新软件。
注册RHN服务的费用算下来一年至少也得1000多元每台,价格不菲。由于CentOS是RHEL的社区编译版本,绝大多数软件包完全相同,且提供了免费的yum源,所以我们可以使用CentOS 5的yum源来对RHEL的软件进行在线安装与更新。

配置的思路其实很简单,就是将CentOS的yum源配置文件/etc/yum.repos.d/CentOS-Base.repo中的配置信息复制过来,创建一个新的repo仓库文件,进行相应的修改即可。

下面开始配置过程:
1. 创建新的.repo仓库文件
输入以下内容(RHEL自带的.repo文件是不需要删除的,因为在检测到未注册RHN服务以后,它们根本不会被启用。)

# vim /etc/yum.repos.d/rhel-rpms-from-centos-source.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

2.导入RPM-KEY
32位系统下执行:
#rpm --import http://mirror.centos.org/centos/5/os/i386/RPM-GPG-KEY-CentOS-5

64位系统下执行:
#rpm --import http://mirror.centos.org/centos/5/os/x86_64/RPM-GPG-KEY-CentOS-5

3.清理缓存
# yum clean all

4.完成配置,可开始使用yum
# yum install zip

================================
在国内使用CentOS的官方源会比较慢,建议采用一些国内的yum源,将mirror.centos.org更换为对应的站点域名即可。
下面是上海交大的yum源配置文件,供大家使用。

[base]
name=Red Hat Enterprise Linux $releasever - Base
baseurl=http://ftp.sjtu.edu.cn/centos/5/os/$basearch/
gpgcheck=1
gpgkey=http://ftp.sjtu.edu.cn/centos/RPM-GPG-KEY-CentOS-5

#released updates 
[updates]
name=Red Hat Enterprise Linux $releasever - Updates
baseurl=http://ftp.sjtu.edu.cn/centos/5/updates/$basearch/
gpgcheck=1
gpgkey=http://ftp.sjtu.edu.cn/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://ftp.sjtu.edu.cn/centos/5/addons/$basearch/
pgcheck=1
gpgkey=http://ftp.sjtu.edu.cn/centos/RPM-GPG-KEY-CentOS-5

#additional packages that may be useful
[extras]
name=Red Hat Enterprise Linux $releasever - Extras
baseurl=http://ftp.sjtu.edu.cn/centos/5/extras/$basearch/
gpgcheck=1
gpgkey=http://ftp.sjtu.edu.cn/centos/RPM-GPG-KEY-CentOS-5

#additional packages that extend functionality of existing packages
[centosplus]
name=Red Hat Enterprise Linux $releasever - Plus
baseurl=http://ftp.sjtu.edu.cn/centos/5/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://ftp.sjtu.edu.cn/centos/RPM-GPG-KEY-CentOS-5

#contrib - packages by Centos Users
[contrib]
name=Red Hat Enterprise Linux $releasever - Contrib
baseurl=http://ftp.sjtu.edu.cn/centos/5/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://ftp.sjtu.edu.cn/centos/RPM-GPG-KEY-CentOS-5

另外,在局域网环境内,推荐大家参考一下我的这一篇文章:
《利用DVD安装光盘构建属于自己的RHEL yum安装源》:http://heylinux.com/archives/954.html

  1. #1 by 遛狗网 on 2011/06/23 - 11:33

    这个方法不错。

(will not be published)
*