1 基础知识简介

1.1 yum

1.1.1介绍

  • yum全称“Yellow dog Updater, Modified”,是一个专门为了解决包的依赖关系而存在的软件包管理器。就好像 Windows 系统上可以通过 360 软件管家实现软件的一键安装、升级和卸载,Linux 系统也提供有这样的工具;
  • centos系统除了yum这种可自动安装软件包(自动解决包之间依赖关系)的安装方式,还可以使用 SRPM 源码包和 RPM 二进制包安装软件,但这两种方法都比较繁琐,需要手动解决包之间具有依赖性的问题,尤其是库文件依赖,需要自行去 http://www.rpmfind.net 网站上查找相关的 RPM 包;

1.1.2 使用方式

  • 使用 yum 安装软件包之前,需指定好 yum 下载 RPM 包的位置,此位置称为 yum 源。即yum 源指的就是软件安装包的来源;
  • 使用 yum 安装软件时至少需要指定一个 yum 源。yum 源既可以使用网络 yum 源,也可以将本地光盘作为 yum 源,也可以配置网络yum源。

本文只介绍网络 yum 源配置;
一般情况下,只要主机网络正常,可以直接使用网络 yum 源,不需要对配置文件做任何修改;
网络 yum 源配置文件位于 /etc/yum.repos.d/ 目录下,文件扩展名为".repo"(只要扩展名为 ".repo" 的文件都是 yum 源的配置文件);
通常情况下 CentOS-Base.repo 文件生效。

1.1.3 yum配置方式

cat /etc/yum.repo.d/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.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#released updates 
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
  • [base]:容器名称,一定要放在[]中。
  • name:容器说明,可以自己随便写。
  • mirrorlist:镜像站点,这个可以注释掉。
  • baseurl:我们的 yum 源服务器的地址。默认是 CentOS 官方的 yum 源服务器,是可以使用的。如果你觉得慢,则可以改成你喜欢的 yum 源地址。
  • enabled:此容器是否生效,如果不写或写成 enabled 则表示此容器生效,写成 enable=0 则表示此容器不生效。
  • gpgcheck:如果为 1 则表示 RPM 的数字证书生效;如果为 0 则表示 RPM 的数字证书不生效。
  • gpgkey:数字证书的公钥文件保存位置。不用修改。

1.2 epel

epel的全称叫 Extra Packages for Enterprise Linux 。由 Fedora 社区打造,为 RHEL 及衍生发行版如 CentOS、Scientific Linux 等提供高质量软件包的项目;epel相当于一个第三方源。由于CentOS 官方源包含的大多数的库都是比较旧的。并且很多流行的库也不存在,其目的是为了保证服务器版本安全稳定。

2 阿里云yum源配置

2.1 配置Centos-repo

2.1.1 备份系统repo文件

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

2.1.2 下载阿里yum配置文件

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

2.1.3 重建缓存

yum clean all
yum makecache

2.2 配置epel源

2.2.1 备份系统epel文件

mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.bak

2.2.2 下载阿里epel配置文件

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

2.2.3 重建缓存

yum clean all
yum makecache