Linux下更换为阿里yum源 zero

 更新日期: 2018-08-06

1、yum源的工作原理

  yum是为了解决安装包的依赖关系而生的,如果要源码安装一个软件,需要频繁下载各个包,并解决包的依赖关系。这就好比学门课程,要学会这门课程,就要读课程相关的书,初级——中级——高级,一层一层学上去。现在,如果要学习高级的课本,首先要找到并学习初级的课本,如果初级的课本还要有基础知识,还要一层一层的找下去。那现在有两个图书馆,你所要学习的书都在其中,一个图书馆中的书是一本本放置的,相互之间没有关系,你要什么书取什么书;一个图书馆,书与书之间是有索引连接的,当你要学习一门课程时,它会自动把相关书籍全部提供给你,前者好比官网,后者就是yum源.

2、yum的工作机制

  服务器端:在服务器上面存放了所有的RPM软件包,包与包之间有索引链接;
  客户端:如果需要安装某个软件时,先下载服务器上面记录的依赖性关系文件(可通过WWW或FTP方式),通过对服务器端下载的纪录数据进行分析,然后取得所有相关的软件,一次全部下载下来进行安装。

3、配置阿里yum源

  > [root@zabbix /]# cd /etc/yum.repos.d/

  > [root@zabbix yum.repos.d]# vi 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-6.9 - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/6.9/os/$basearch/
        http://mirrors.aliyuncs.com/centos/6.9/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6.9&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
  
#released updates
[updates]
name=CentOS-6.9 - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/6.9/updates/$basearch/
        http://mirrors.aliyuncs.com/centos/6.9/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6.9&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
  
#additional packages that may be useful
[extras]
name=CentOS-6.9 - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/6.9/extras/$basearch/
        http://mirrors.aliyuncs.com/centos/6.9/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6.9&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
  
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-6.9 - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/6.9/centosplus/$basearch/
        http://mirrors.aliyuncs.com/centos/6.9/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6.9&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
  
#contrib - packages by Centos Users
[contrib]
name=CentOS-6.9 - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/6.9/contrib/$basearch/
        http://mirrors.aliyuncs.com/centos/6.9/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6.9&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6</span>

  >[root@zabbix yum.repos.d]# yum clean all      --清空yum缓存的软件包和header
  >[root@zabbix yum.repos.d]# yum makecache      --把yum源中的包信息进行缓存

4、替换最新yum源

  由于阿里的yum源会定时更新,会导致上面的yum源失效,下面跟大家分享一种实时获取最新yum源的方法。

  首先,进入阿里的镜像地址: https://opsx.alibaba.com/mirror ,点击 “帮助”,如下:

   然后,选择符合对应系统版本(# cat /etc/redhat-release),下载文件

  接下来,替换 .repo 文件中的版本信息,注意将 $releasever 替换成对应的大的版本,不带小版本号。

[root@zero01 yum.repos.d]# sed -i 's/\$releasever/6/g' CentOS-Base.repo 

   最后,刷新缓存

[root@zabbix yum.repos.d]# yum clean all      --清空yum缓存的软件包和header
[root@zabbix yum.repos.d]# yum makecache      --把yum源中的包信息进行缓存

作者:zero_gg
出处:http://www.cnblogs.com/zero-gg/

如果你真心觉得文章写得不错,而且对你有所帮助,那就不妨小小打赏一下吧,如果囊中羞涩,不妨帮忙“推荐"一下,您的“推荐”和”打赏“将是我最大的写作动力!

本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接.

原文地址:https://www.cnblogs.com/zero-gg/p/8477809.html