CentOS7-yum源配置

1.查看yum源

yum repolist 

显示如下

Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.neusoft.edu.cn
 * updates: mirrors.neusoft.edu.cn
repo id                             repo name                             status
base/7/x86_64                       CentOS-7 - Base                       9,911
extras/7/x86_64                     CentOS-7 - Extras                       314
updates/7/x86_64                    CentOS-7 - Updates                      946
repolist: 11,171

可以看到yum的源使用的是清华大学的镜像源,扩展和更新使用的是则是另一个镜像源。

2.使用阿里云的yum源

查看wget是否安装

rpm -qa | grep wget

如果安装则会出现wget相关信息,如果没有则使用如下命令进行安装

sudo yum -y install wget

1.备份原有的yum源

sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.back

2.设置阿里云的yum源

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

如果想使用其它yum源,将阿里云的yum源地址更改为相应的yum源地址即可

使用网易yum源
sudo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo

对于任意的yum源只需找到yum源地址,都可以使用相同的方法进行配置

3.添加EPEL源

EPEL(https://fedoraproject.org/wiki/EPEL)是一组企业级的高质量额外软件包。
EPEL源的安装有两种方法:
命令行直接安装

yum -y install epel-release 

手动安装

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

4.更新yum源

sudo yum clean all 
sudo yum makecache 

再次使用yum repolist命令查看yum源信息

Loaded plugins: fastestmirror, langpacks
Repository epel is listed more than once in the configuration
Repository epel-debuginfo is listed more than once in the configuration
Repository epel-source is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
repo id               repo name                                           status
base/7/x86_64         CentOS-7 - Base - mirrors.aliyun.com                 9,911
epel/x86_64           Extra Packages for Enterprise Linux 7 - x86_64      12,604
extras/7/x86_64       CentOS-7 - Extras - mirrors.aliyun.com                 314
updates/7/x86_64      CentOS-7 - Updates - mirrors.aliyun.com                946
repolist: 23,775

可以看到yum源已经修改为阿里云的yum源了

3设置多级yum源

我们可以配置多个yum源,并使用优先级的高低决定优先使用哪一种yum源。例如可以配置一个阿里云的yum源和一个私人的yum源,给予阿里云的yum源高优先级,当在阿里云的yum源中无法找到相应的软件包时则从低优先级的yum源中搜索是否有相应的软件包。
对于优先级的设置,可以使用yum提供的yum-plugin-priorities.noarch插件解决。

1查看是否安装优先级插件

[peko@localhost ~]$ rpm -qa | grep yum-plugin-
yum-plugin-fastestmirror-1.1.31-45.el7.noarch

可以看到并没用安装yum-plugin-priorities.noarch插件

查看阿里云的yum源上是否有yum-plugin-priorities.noarch插件

[peko@localhost ~]$ yum search yum-plugin-priorities
Loaded plugins: fastestmirror, langpacks
Repository epel is listed more than once in the configuration
Repository epel-debuginfo is listed more than once in the configuration
Repository epel-source is listed more than once in the configuration
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

Name and summary matches only, use "search all" for everything.

可以看到,有一个匹配的结果出现,说明yum源中有此插件

2 安装插件

sudo yum -y install yum-plugin-priorities.noarch 

查看插件是否生效

[peko@localhost ~]$  cat /etc/yum/pluginconf.d/priorities.conf
[main]
enabled = 1

enabled = 1为启用,enabled = 0为禁用

3 编辑优先级

编辑/etc/yum.repos.d/下的*.repo文件来设置优先级

[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
priority=1

通过添加priority=N来设置优先级高低,N越小优先级越高。安装包优先从优先级高的yum源开始安装。

你可能感兴趣的:(CentOS7-yum源配置)