天天看点

Linux调整yum优先级

作者:运维Devops

Linux操作系统安装完毕后一般会有多个源文件,如图:

Linux调整yum优先级

我们就以CentOS-Base.repo为例子,首先查看下此文件内容,如下:

[extras]
gpgcheck=1
gpgkey=http://mirrors.tencentyun.com/centos/RPM-GPG-KEY-CentOS-7
enabled=1
baseurl=http://mirrors.tencentyun.com/centos/$releasever/extras/$basearch/
name=Qcloud centos extras - $basearch
[os]
gpgcheck=1
gpgkey=http://mirrors.tencentyun.com/centos/RPM-GPG-KEY-CentOS-7
enabled=1
baseurl=http://mirrors.tencentyun.com/centos/$releasever/os/$basearch/
name=Qcloud centos os - $basearch
[updates]
gpgcheck=1
gpgkey=http://mirrors.tencentyun.com/centos/RPM-GPG-KEY-CentOS-7
enabled=1
baseurl=http://mirrors.tencentyun.com/centos/$releasever/updates/$basearch/
name=Qcloud centos updates - $basearch           

上面的内容中有多个仓库,比如updates、os、extras,下面我们来设置这几个仓库的优先级

1、首先需要安装一个优先级插件,如下:

yum -y install yum-plugin-priorities.noarch # centos7.9系统           

2、修改yum优先级配置文件,设置为enable,开启优先级插件,1为开启,0为禁止,如下:

Linux调整yum优先级

3、修改yum源文件,在其中添加参数priority=n,其中这个n >=1,数值越大,优先级越小,如图:

Linux调整yum优先级

然后再次通过yum安装软件后将会优先检索extras库,然后是os,最后是updates

注意:如果执行yum命令报错了Options error: invalid boolean value,大概率问题是/etc/yum/pluginconf.d/priorities.conf配置文件中写了注释,并且是#开头的注释