CentOS配置本地yum源/阿里云yum源/163yuan源并配置yum源的优先级
一、用centos镜像搭建本地yum源
由于安装centos后的默认yum源为centos的官方地址,所以在国内使用很慢甚至无法访问,所以一般的做法都是把默认的yum源替换成aliyun的yum源或者163等国内的yum源(下文介绍如何配置)。
但是以上的方法都是需要网络的,当没有网络的时候就无法使用了,所以还有一个常用的方法就是用centos的iso镜像搭建本地yum源,这样安装软件的速度就会飞快,缺点是可能有些包没有。
1.安装centos后默认的yum源如下
[root@kangvcar ~]# ll /etc/yum.repos.d/ total 32 -rw-r--r--. 1 root root 1664 dec 9 2015 centos-base.repo -rw-r--r--. 1 root root 1309 dec 9 2015 centos-cr.repo -rw-r--r--. 1 root root 649 dec 9 2015 centos-debuginfo.repo -rw-r--r--. 1 root root 290 dec 9 2015 centos-fasttrack.repo -rw-r--r--. 1 root root 630 dec 9 2015 centos-media.repo -rw-r--r--. 1 root root 1331 dec 9 2015 centos-sources.repo -rw-r--r--. 1 root root 1952 dec 9 2015 centos-vault.repo
2.把默认yum源备份(可选)
[root@kangvcar ~]# mkdir /opt/centos-yum.bak [root@kangvcar ~]# mv /etc/yum.repos.d/* /opt/centos-yum.bak/
3.在虚拟机上挂载centos镜像文件
[root@kangvcar ~]# mount -t iso9660 /dev/sr0 /opt/centos mount: /dev/sr0 is write-protected, mounting read-only
4.编写repo文件并指向镜像的挂载目录
[root@kangvcar ~]# vi /etc/yum.repos.d/local.repo [local] name=local baseurl=file:///opt/centos enabled=1 gpgcheck=0
5.清除缓存
[root@kangvcar ~]# yum clean all loaded plugins: fastestmirror cleaning repos: local cleaning up everything cleaning up list of fastest mirrors [root@kangvcar ~]# yum makecache //把yum源缓存到本地,加快软件的搜索好安装速度 [root@kangvcar ~]# yum list //列出了3780个包
二、把默认的centos yum源修改成国内的aliyun yum源
阿里云官方教程:
1.安装centos后默认的yum源如下
[root@kangvcar ~]# ll /etc/yum.repos.d/ total 32 -rw-r--r--. 1 root root 1664 dec 9 2015 centos-base.repo -rw-r--r--. 1 root root 1309 dec 9 2015 centos-cr.repo -rw-r--r--. 1 root root 649 dec 9 2015 centos-debuginfo.repo -rw-r--r--. 1 root root 290 dec 9 2015 centos-fasttrack.repo -rw-r--r--. 1 root root 630 dec 9 2015 centos-media.repo -rw-r--r--. 1 root root 1331 dec 9 2015 centos-sources.repo -rw-r--r--. 1 root root 1952 dec 9 2015 centos-vault.repo
2.把默认yum源备份(可选)
[root@kangvcar ~]# mkdir /opt/centos-yum.bak [root@kangvcar ~]# mv /etc/yum.repos.d/* /opt/centos-yum.bak/
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
[root@kangvcar ~]# cat /etc/redhat-release //查看系统的版本 centos linux release 7.2.1511 (core) [root@kangvcar ~]# 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]
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 yum源修改成国内的163源
163官方教程:
1.安装centos后默认的yum源如下
[root@kangvcar ~]# ll /etc/yum.repos.d/ total 32 -rw-r--r--. 1 root root 1664 dec 9 2015 centos-base.repo -rw-r--r--. 1 root root 1309 dec 9 2015 centos-cr.repo -rw-r--r--. 1 root root 649 dec 9 2015 centos-debuginfo.repo -rw-r--r--. 1 root root 290 dec 9 2015 centos-fasttrack.repo -rw-r--r--. 1 root root 630 dec 9 2015 centos-media.repo -rw-r--r--. 1 root root 1331 dec 9 2015 centos-sources.repo -rw-r--r--. 1 root root 1952 dec 9 2015 centos-vault.repo
2.把默认yum源备份(可选)
[root@kangvcar ~]# mkdir /opt/centos-yum.bak [root@kangvcar ~]# mv /etc/yum.repos.d/* /opt/centos-yum.bak/
3.下载163 yum源repo文件
#各系统版本repo文件对应的下载操作 centos 5 wget -o /etc/yum.repos.d/centos5-base-163.repo http://mirrors.163.com/.help/centos5-base-163.repo centos 6 wget -o /etc/yum.repos.d/centos6-base-163.repo http://mirrors.163.com/.help/centos6-base-163.repo centos 7 wget -o /etc/yum.repos.d/centos7-base-163.repo http://mirrors.163.com/.help/centos7-base-163.repo
[root@kangvcar ~]# cat /etc/redhat-release //查看系统的版本 centos linux release 7.2.1511 (core) [root@kangvcar ~]# wget -o /etc/yum.repos.d/centos7-base-163.repo http://mirrors.163.com/.help/centos7-base-163.repo --2017-06-20 06:29:47-- http://mirrors.163.com/.help/centos7-base-163.repo resolving mirrors.163.com (mirrors.163.com)... 123.58.173.185, 123.58.173.186 connecting to mirrors.163.com (mirrors.163.com)|123.58.173.185|:80... connected. http request sent, awaiting response... 200 ok length: 1572 (1.5k) [application/octet-stream] saving to: ‘/etc/yum.repos.d/centos7-base-163.repo' 100%[=======================================================================================================>] 1,572 --.-k/s in 0s 2017-06-20 06:29:47 (293 mb/s) - ‘/etc/yum.repos.d/centos7-base-163.repo' saved [1572/1572]
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 //总共列出了9951个包
四、修改yum源的优先级
ps:当既有本地yum源又有163源的时候,我们在装软件包的时候当然希望先用本地的yum源去安装,本地找不到可用的包时再使用163源去安装软件,这里就涉及到了优先级的问题,yum提供的插件yum-plugin-priorities.noarch可以解决这个问题
1.查看系统是否安装了优先级的插件
[root@kangvcar ~]# rpm -qa | grep yum-plugin- yum-plugin-fastestmirror-1.1.31-34.el7.noarch //这里看到没有安装yum-plugin-priorities.noarch这个插件 [root@kangvcar ~]# 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
2.安装yum-plugin-priorities.noarch插件
[root@kangvcar ~]# yum -y install yum-plugin-priorities.noarch
3.查看插件是否启用
[root@kangvcar ~]# cat /etc/yum/pluginconf.d/priorities.conf [main] enabled = 1 //1为启用;0为禁用
4.修改本地yum源优先使用
[root@kangvcar ~]# 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文件 [root@kangvcar ~]# 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就会优先使用本地源了
5.测试
配置优先级前:(使用阿里云yum源) [root@kangvcar ~]# 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源) [root@kangvcar ~]# 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 省略···
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
上一篇: Oracle作业4-函数
下一篇: 武媚娘去了一趟尼姑庵