添加多个yum源并自动选择最快的源

2013/5/26 系统centos6.4final

有时候如果我们的网络是在大陆,而yum使用的源的镜像服务器在台湾的话,这样会拖慢yum下载和更新软件的速度,这时候可以通过添加国内的yum server镜像来提高yum下载和更新软件的速度。下面介绍几个常用的大陆开源镜像,速度都很不错。
网易  mirrors.163.com
搜狐  mirrors.sohu.com
中科大 mirrors.ustc.edu.cn

添加多个yum源的方法
方法一:快速导入

首先备份/etc/yum.repos.d/CentOS-Base.repo

    mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

下载对应版本repo文件, 放入/etc/yum.repos.d/(操作前请做好相应备份)

运行yum makecache生成缓存



方法二: 手动修改文件 
1、进入源目录:

cd /etc/yum.repos.d

2、添加多个源文件,如:shlug.repo,ustc.repo,两个源的内容如下:
(可以创建独立的repo文件,也可以把以下的内容加到 /etc/yum.repos.d/CentOS-Base.repo 后面

[shlug.repo]

#mirrors-shlug-org.repo 
# rpm --import http://mirrors.shlug.org/centos/RPM-GPG-KEY-CentOS-6
# This file uses a new mirrorlist system developed by Lance Davis for CentOS. 
# 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=mirrors-shlug-org--CentOS-$releasever - Base 
baseurl=http://mirrors.shlug.org/centos/$releasever/os/$basearch/ 
gpgcheck=1 
gpgkey=http://mirrors.shlug.org/centos/RPM-GPG-KEY-CentOS-6 
#released updates 
[update] 
name=mirrors-shlug-org--CentOS-$releasever - Updates 
baseurl=http://mirrors.shlug.org/centos/$releasever/updates/$basearch/ 
gpgcheck=1 
gpgkey=http://mirrors.shlug.org/centos/RPM-GPG-KEY-CentOS-6
#packages used/produced in the build but not released 
#[addons] 网站上的源目录没有addon,故注释掉
#baseurl=http://mirrors.shlug.org/centos/$releasever/addons/$basearch/ 
#gpgcheck=1 
#gpgkey=http://mirrors.shlug.org/centos/RPM-GPG-KEY-CentOS-6 
#additional packages that may be useful 
[extras] 
name=mirrors-shlug-org--CentOS-$releasever - Extras 
baseurl=http://mirrors.shlug.org/centos/$releasever/extras/$basearch/ 
gpgcheck=1 
gpgkey=http://mirrors.shlug.org/centos/RPM-GPG-KEY-CentOS-6 
#additional packages that extend functionality of existing packages 
[centosplus] 
name=mirrors-shlug-org--CentOS-$releasever - Plus 
baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/ 
gpgcheck=1 
gpgkey=http://mirrors.shlug.org/centos/RPM-GPG-KEY-CentOS-6 
#contrib - packages by Centos Users 
[contrib] 
name=mirrors-shlug-org--CentOS-$releasever - Contrib 
baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/ 
gpgcheck=1 
enabled=0 
gpgkey=http://mirrors.shlug.org/centos/RPM-GPG-KEY-CentOS-6

[ustc.repo]

# CentOS-Base.repo
#
# This file uses a new mirrorlist system developed by Lance Davis for CentOS.
# 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
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://centos.ustc.edu.cn/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://centos.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6

#released updates
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://centos.ustc.edu.cn/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://centos.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6

#packages used/produced in the build but not released
#[addons] 网站上的源目录没有addon,故注释掉
#name=CentOS-$releasever - Addons
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=addons
#baseurl=http://centos.ustc.edu.cn/centos/$releasever/addons/$basearch/
#gpgcheck=1
#gpgkey=http://centos.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://centos.ustc.edu.cn/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://centos.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6

#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://centos.ustc.edu.cn/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://centos.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6

3、导入KEY

rpm --import http://mirrors.shlug.org/centos/RPM-GPG-KEY-CentOS-6
rpm --import http://centos.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6

4、安装自动源选择插件--自动选择最快的源

yum install yum-fastestmirror -y

5、如何确认正在使用的是哪个源?

cd /var/cache/yum
cat timedhosts.txt
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值