CentOS 添加第三方源扩展yum软件包

安装CentOS yum源优先级插件yum-priorities

确认系统是否安装了priority这个yum的插件,这个插件用来保证安装软件时候软件仓库先后次序,一般是默认先从官方base或者镜像安装,然后从社区用户contribute的软件中安装,再从第三方软件仓库中安装。当然这个次序可以自己更改,为了安全和稳定还是依照这个次序吧。

# yum install yum-priorities

安装完以后查看 /etc/yum/pluginconf.d/priorities.conf 文件,确认文件中有这一行

[main]
enabled=1

设置CentOS默认yum源的优先级为最高

现在就可以手动编辑 /etc/yum.repos.d/ 目录中后缀为.repo的文件来设置软件仓库的先后次序,priority=N(N是整数,范围从1-99) 官方推荐配置是 [base], [addons], [updates], [extras] … priority=1 [centosplus],[contrib] … priority=2 Third Party Repos such as rpmforge … priority=N (where N is > 10 and based on your preference),也就是说priority的优先级为1到99,设置为1即优先级最高,1-10为系统保留,第三方yum源的优先级从11-99。
进入yum源目

# cd /etc/yum.repos.d/

在[base]、[updates]、[extras]组下面添加priority=1,在[centosplus]、[contrib]组下面添加priority=2

#vim CentOS-Base.repo

修改后如下所示:

# 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
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
priority=1

#released updates
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
priority=1

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
priority=1

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
priority=2

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
#baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
priority=2

添加配置第三方源

1、RPMForge(http://rpmforge.net)

RPMForge是CentOS系统下的软件仓库,拥有4000多种的软件包,被CentOS社区认为是最安全也是最稳定的一个软件仓库。

添加方法:终端执行:

32位系统:

# rpm -ivh http://apt.sw.be/redhat/el6/en/i386/rpmforge/RPMS/rpmforge-release-0.5.2-2.el6.rf.i686.rpm

64位系统:

# rpm -ivh http://apt.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm

然后导入它的公钥

# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag

修改rpmforge yum源优先级,priority=11

# vim /etc/yum.repos.d/rpmforge.repo

修改完如下所示:

### Name: RPMforge RPM Repository for RHEL 6 - dag
### URL: http://rpmforge.net/
[rpmforge]
name = RHEL $releasever - RPMforge.net - dag
baseurl = http://apt.sw.be/redhat/el6/en/$basearch/rpmforge
mirrorlist = http://apt.sw.be/redhat/el6/en/mirrors-rpmforge
#mirrorlist = file:///etc/yum.repos.d/mirrors-rpmforge
enabled = 1
protect = 0
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
gpgcheck = 1
priority=11
......

2、EPEL(Extra Packages for Enterprise Linux) EPEL(http://fedoraproject.org/wiki/EPEL)是由Fedora社区打造,为RHEL及衍生发行版如CentOS、Scientific Linux等提供高质量软件包的项目。有了EPEL,就像在Fedora上一样,可以通过yum随意安装软件。很多源添加前也都要求添加这个算是“官方”的源。

添加方法: 打开终端,输入

32位系统:

# rpm -ivh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm

64位系统:

# rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-5.noarch.rpm

然后导入公钥(可选)

# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

修改epel yum源优先级,priority=12

# vim /etc/yum.repos.d/epel.repo

修改完如下所示:

[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
priority=12
......

3、CentALT(http://centos.alt.ru)(此第三方源可选)

CentALT是俄罗斯的一个源,推荐它的主要目的是主要是能够下载最新版的apache、nginx和postfix,而且这个源只有不到100个RPM包,很少与别的源存在依赖冲突。

添加方法: 终端执行:

32位系统:

# rpm -ivh http://centos.alt.ru/repository/centos/6/i386/centalt-release-6-1.noarch.rpm

64位系统:

# rpm -ivh http://centos.alt.ru/repository/centos/6/x86_64/centalt-release-6-1.noarch.rpm

修改epel yum源优先级,priority=13

# vim /etc/yum.repos.d/centalt.repo

修改完如下所示:

[CentALT]
name=CentALT Packages for Enterprise Linux 6 - $basearch
baseurl=http://centos.alt.ru/repository/centos/6/$basearch/
enabled=1
gpgcheck=0
priority=13
......