CentOS 修改yum源为国内源

2.把默认yum源备份(可选)

[root@kangvcar ~]# mkdir /opt/centos-yum.bak
[root@kangvcar ~]# mv /etc/yum.repos.d/* /opt/centos-yum.bak/

起用架构

  • i386
  • x86_64

1.把默认yum源备份(可选)

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

4.革除缓存

[root@kangvcar ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base extras updates
Cleaning up everything
Cleaning up list of fastest mirrors
[root@kangvcar ~]# yum makecache        //把yum源缓存到本地,加快软件的搜索好安装速度
[root@kangvcar ~]# yum list        //总共列出了9954个包

使用验证

率先备份CentOS-Base.repo

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

下载对应版本的CentOS-Base.repo, 放入/etc/yum.repos.d/

这是CentOS 5的:

CentOS-Base.repo

# CentOS-Base.repo## 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 - mirrors.ustc.edu.cnbaseurl=http://mirrors.ustc.edu.cn/centos/$releasever/os/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=osgpgcheck=1gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-5#released updates [updates]name=CentOS-$releasever - Updates - mirrors.ustc.edu.cnbaseurl=http://mirrors.ustc.edu.cn/centos/$releasever/updates/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updatesgpgcheck=1gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-5#additional packages that may be useful[extras]name=CentOS-$releasever - Extras - mirrors.ustc.edu.cnbaseurl=http://mirrors.ustc.edu.cn/centos/$releasever/extras/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extrasgpgcheck=1gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-5#packages used/produced in the build but not released[addons]name=CentOS-$releasever - Addons - mirrors.ustc.edu.cnbaseurl=http://mirrors.ustc.edu.cn/centos/$releasever/addons/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=addonsgpgcheck=1gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5#additional packages that extend functionality of existing packages[centosplus]name=CentOS-$releasever - Plus - mirrors.ustc.edu.cnbaseurl=http://mirrors.ustc.edu.cn/centos/$releasever/centosplus/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplusgpgcheck=1enabled=0gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-5#contrib - packages by Centos Users[contrib]name=CentOS-$releasever - Contrib - mirrors.ustc.edu.cnbaseurl=http://mirrors.ustc.edu.cn/centos/$releasever/contrib/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contribgpgcheck=1enabled=0gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-5

这是CentOS 6的:

CentOS-Base.repo

# CentOS-Base.repo## 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 - mirrors.ustc.edu.cnbaseurl=http://mirrors.ustc.edu.cn/centos/$releasever/os/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=osgpgcheck=1gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6#released updates [updates]name=CentOS-$releasever - Updates - mirrors.ustc.edu.cnbaseurl=http://mirrors.ustc.edu.cn/centos/$releasever/updates/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updatesgpgcheck=1gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6#additional packages that may be useful[extras]name=CentOS-$releasever - Extras - mirrors.ustc.edu.cnbaseurl=http://mirrors.ustc.edu.cn/centos/$releasever/extras/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extrasgpgcheck=1gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6#additional packages that extend functionality of existing packages[centosplus]name=CentOS-$releasever - Plus - mirrors.ustc.edu.cnbaseurl=http://mirrors.ustc.edu.cn/centos/$releasever/centosplus/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplusgpgcheck=1enabled=0gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6#contrib - packages by Centos Users[contrib]name=CentOS-$releasever - Contrib - mirrors.ustc.edu.cnbaseurl=http://mirrors.ustc.edu.cn/centos/$releasever/contrib/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contribgpgcheck=1enabled=0gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6

运维yum makecache生成缓存

修改yum源为国内源 CentOS 修改yum源为国内源
修改yum源的格局有三种,比非常多仇敌喜欢修改yum.repos.d那个文件实行更换,deepvps感到那一个方法…

3.免除缓存

yum clean all

yum makecache

4.更动本地yum源优先利用

[[email protected] ~]# ll /etc/yum.repos.d/
total 8
-rw-r--r--. 1 root root 2573 May 15  2015 CentOS-Base.repo
-rw-r--r--. 1 root root   67 Jun 20 06:04 local.repo
//有两个repo文件
[[email protected] ~]# vi /etc/yum.repos.d/local.repo
[local]
name=local
baseurl=file:///opt/centos
enabled=1
gpgcheck=0
priority=1
//在原基础上加入priority=1 ;数字越小优先级越高
//可以继续修改其他源的priority值,经测试仅配置本地源的优先级为priority=1就会优先使用本地源了

CentOS 修改yum源为国内源

2.下载yum源repo文件

Ali云官方教程:http://mirrors.aliyun.com/help/centos

163合法教程:http://mirrors.163.com/.help/centos.html

CentOS5

阿里云:wget -O /etc/yum.repos.d/CentOS-Base.repo

163:wget -O /etc/yum.repos.d/CentOS5-Base-163.repo

CentOS6

阿里云:wget -O /etc/yum.repos.d/CentOS-Base.repo

163:wget -O /etc/yum.repos.d/CentOS6-Base-163.repo

CentOS7

阿里云:wget -O /etc/yum.repos.d/CentOS-Base.repo

163:wget -O /etc/yum.repos.d/CentOS7-Base-163.repo

4.编写repo文件并指向镜像的挂载目录

[[email protected] ~]# vi /etc/yum.repos.d/local.repo  
[local]
name=local
baseurl=file:///opt/centos
enabled=1
gpgcheck=0

起用版本

  • 5
  • 6

1.查看系统是或不是安装了优先级的插件

[[email protected] ~]# rpm -qa | grep yum-plugin-
yum-plugin-fastestmirror-1.1.31-34.el7.noarch        
//这里看到没有安装yum-plugin-priorities.noarch这个插件
[[email protected] ~]# yum search yum-plugin-priorities        
//用search查看是否有此插件可用
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
====================================================== N/S matched: yum-plugin-priorities =======================================================
yum-plugin-priorities.noarch : plugin to give priorities to packages from different repos

改动centos yum 成人中学国镜像加快yum速度

163的开源镜像地址
区别版本见

sohu的开源镜像地址
今是昨非版本见

中国中国科学技术大学
不等版本见)

一经使用下边YUM源的话,最佳把里面包车型大巴mirrorlist注释掉,不然系统会运行fastesmirror插件自动物检疫查的,并不一定会动用那一个yum源的.

本人用的是中国防外贸大学的进程不错。

法一:直接下载源文件

CentOS USTC mirror 这么些镜像不错,大家更新可用那一个

#yum -y install wget
#cd /etc/yum.repos.d
#mv CentOS-Base.repo CentOS-Base.repo.save
#wget

专注:假设为率先次安装的新系统来讲,则必要先安装wget那么些下载软件,不然没法下载CentOS-Base.repo这一个文件的。

法二:手动创造源文件

更动yum镜像站点为中华站点地址,推荐)

#cd /etc/yum.repos.d/

#mv CentOS-Base.repo CentOS-Base.repo.bak

#vi CentOS-Base.repo

修改/etc/yum.repos.d/CentOS-Base.repo如下:

3.下载aliyun yum源repo文件(对应自身的系统版本下载就能够)

#各系统版本repo文件对应的下载操作
CentOS 5
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
CentOS 6
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
CentOS 7
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

[[email protected] ~]# cat /etc/redhat-release        //查看系统的版本
CentOS Linux release 7.2.1511 (Core)
[[email protected] ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
--2017-06-20 06:43:08--  http://mirrors.aliyun.com/repo/Centos-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 112.124.140.210, 115.28.122.210
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|112.124.140.210|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2573 (2.5K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo’
100%[=======================================================================================================>] 2,573       --.-K/s   in 0s      
2017-06-20 06:43:08 (118 MB/s) - ‘/etc/yum.repos.d/CentOS-Base.repo’ saved [2573/2573]

CentOS 修改yum源为国内源

修改yum源的法子有三种,非常多相爱的人喜欢修改yum.repos.d那么些文件进行改换,deepvps认为那几个情势不是太好,以下这几个方法就便于多了。

在CentOS系统中,能够直接通过yum来设置组件,但系统私下认可的yum源速度往往大失所望,都总是国外的,为了在境内高达快捷安装的目标,将要要求修改yum源,能够使用

那2个国内源。

进行以下命令就足以了

cd /etc/yum.repos.d
mv CentOS-Base.repo CentOS-Base.repo.bak
wget


wget

运维yum makecache生成缓存

搞定。

CentOS配置本地yum源/Ali云yum源/163yuan源,并配置yum源的优先级,centos163yuan

Centos镜像使用扶助

5.测试

配置优先级前:(使用阿里云yum源)
[[email protected] ~]# yum -y install vim
Dependencies Resolved
=================================================================================================================================================
Package                            Arch                         Version                                     Repository                     Size
=================================================================================================================================================
Installing:
vim-enhanced                       x86_64                       2:7.4.160-1.el7_3.1                         updates                       1.0 M
Updating for dependencies:
vim-common                         x86_64                       2:7.4.160-1.el7_3.1                         updates                       5.9 M
省略···

配置优先级后:(使用本地yum源)
[[email protected] ~]# yum -y install vim
Dependencies Resolved
=================================================================================================================================================
Package                                     Arch                        Version                                Repository                  Size
=================================================================================================================================================
Installing:
vim-enhanced                                x86_64                      2:7.4.160-1.el7                        local                      1.0 M
Installing for dependencies:
gpm-libs                                    x86_64                      1.20.7-5.el7                           local                       32 k
perl                                        x86_64                      4:5.16.3-286.el7                       local                      8.0 M
perl-Carp                                   noarch                      1.26-244.el7                           local                       19 k
perl-Encode                                 x86_64                      2.51-7.el7                             local                      1.5 M
perl-Exporter                               noarch                      5.68-3.el7                             local                       28 k
perl-File-Path                              noarch                      2.09-2.el7                             local                       26 k
perl-File-Temp                              noarch                      0.23.01-3.el7                          local                       56 k
省略···