Linux下的第三方yum源配置

引言:
CentOS自带的yum源中rpm包数量有限,很多时候找不到我们需的软件包,(例如:要安装网络连接查看软件iftop,默认设置下无法使用yum命令安装),下面教大家在CentOS 6.2中(以32位系统为例,64位系统安装方法一样),使用第三方yum源来安装更多软件包。

使用 yum   repolist 命令可以查看系统已经安装好的yum源

注意:下载第三方的yum源的安装包的时候要注意看自己的系统是多少位的:

查看linux机器是32位还是64位的方法:

file /sbin/init 或者 file /bin/ls
/sbin/init: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped

如果显示 64-bit 则为64位;

file /sbin/init
/sbin/init: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.2.5, dynamically linked (uses shared libs), stripped


如果显示为32 bit 则为32bit;

uname -a:
uname -a
Linux pmx002**.**.**  2.6.32-71.el6.x86_64 #1 SMP Wed Sep 1 01:33:01 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux

x86_64表示64位机器

uname -a
Linux pmx0**.**.**    2.6.9-5.ELsmp #1 SMP Wed Jan 5 19:30:39 EST 2005 i686 i686 i386 GNU/Linux

一、安装CentOS yum源优先级插件yum-priorities
     yum -y install yum-priorities  //该插件的作用主要是设置调用源时的优先级的,一般将官方的优先级设置为最高)

二、设置CentOS默认yum源的优先级为最高:(如果不设置优先级安装多个Yum源的话可能存在冲突的问题。)

cd  /etc/yum.repos.d/   #进入yum源目录
    vi CentOS-Base.repo    #在[base]、[updates]、[extras]组下面添加priority=1,在[centosplus]、[contrib]组下面添加priority=2
################################################################  
[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

[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

[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

[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]
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
###############################################################  
备注:priority的优先级为1到99,设置为1即优先级最高,1-10为系统保留,第三方yum源的优先级从11-99
三、安装epel yum源:

64位的epel源下载地址:

wget http://download.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm

32位的epel源下载地址:

 

Wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm

  rpm-ivh epel-release-6-8.noarch.rpm

导入key认证文件:(如果gpgcheck=0则就不需要这步骤)

参数mirrorlist表示的是映射yum容器的url路径(对应的url路径为多个)此路径需要yum程序自行去查找链接地址,如果不适用可以注释掉。

baseurl表示的是YUM容器的实际地址是一个固定的地址。如果不使用的话也可以注释掉。

   rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
   vi /etc/yum.repos.d/epel.repo   #修改epel yum源优先级,priority=11

###############################################################
   [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=11
#################################################################
四、安装rpmforge yum源
  wget http://apt.sw.be/redhat/el6/en/i386/rpmforge/RPMS/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
  wget http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
  rpm --import RPM-GPG-KEY.dag.txt
  rpm -ivh rpmforge-release-0.5.2-2.el6.rf.i686.rpm
  vi  /etc/yum.repos.d/rpmforge.repo  #修改rpmforge yum源优先级,priority=12

#################################################################
[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=12
#################################################################

五、安装rpmfusion yum源

wget  http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm

wget spacer.gifhttp://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm

yum -y install rpmfusion-free-release-stable.noarch.rpm

  vi /etc/yum.repos.d/rpmfusion-free-updates-testing.repo   #修改rpmfusion yum源优先级,priority=13

#################################################################
[rpmfusion-free-updates-testing]
name=RPM Fusion for EL 6 - Free - Test Updates
#baseurl=http://download1.rpmfusion.org/free/el/updates/testing/6/$basearch/
mirrorlist=http://mirrors.rpmfusion.org/mirrorlist?repo=free-el-updates-testing-6&arch=$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmfusion-free-el-6
priority=13
#################################################################
六、安装atomic yum源
   wget http://www.atomicorp.com/installers/atomic  #下载
   sh ./atomic   #安装
   vi  /etc/yum.repos.d/atomic.repo  #修改atomic yum源优先级,priority=14
##############################################################
[atomic]
name = CentOS / Red Hat Enterprise Linux $releasever - atomicrocketturtle.com
mirrorlist = http://www.atomicorp.com/mirrorlist/atomic/centos-6-$basearch
#mirrorlist = http://www.atomicorp.com/channels/atomic/centos/6/mirrors-atomic
enabled = 1
priority = 1
protect = 0
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY.art.txt
gpgcheck = 1
priority=14
##############################################################
七、更新yum软件包
      yum check-update
八、安装iftop
      yum install iftop
至此,CentOS 第三方yum源配置完成,现在你可以用yum命令安装自己需要的软件了!比如yum install nginx、yum update php等安装或者升级软件包。


本文出自 “Anna--linux之家” 博客,谢绝转载!

你可能感兴趣的:(yum源)