RHEL/CentOS Yum命令:黑名单软件包[禁用某些软件包]

时间:2020-01-09 10:43:24  来源:igfitidea点击:

如何强制yum命令禁止使用某些存储库(例如RHEL或者CentOS Linux 6.x服务器下的EPEL)安装某些软件包?
可以在任何.repo配置文件中设置exclude选项。
语法如下:

exclude=package1 package2  
exclude=package1* package?

Package1 Package2是要从更新或者安装中排除的软件包列表。
这应该是一个用空格分隔的列表。
允许使用通配符(例如*和?)的Shell glob。
在此示例中,来自epel repo的blakclist nginx软件包。
编辑/etc/yum.repos.d/epel.repo,执行:

# vi /etc/yum.repos.d/epel.repo

使用exclude关键字如下更新文件:

[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
### Blacklist nginx package ###
exclude=nginx*
 
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 6 - $basearch - Debug
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch/debug
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-6&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
gpgcheck=1
 
[epel-source]
name=Extra Packages for Enterprise Linux 6 - $basearch - Source
#baseurl=http://download.fedoraproject.org/pub/epel/6/SRPMS
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-6&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
gpgcheck=1

保存并关闭文件。
您可以搜索仓库:

# yum search nginx

输出示例:

Loaded plugins: product-id, rhnplugin, subscription-manager
Updating certificate-based repositories.
============================== N/S Matched: nginx ==============================
collectd-nginx.x86_64 : Nginx plugin for collectd
nginx.x86_64 : Robust, small and high performance HTTP and reverse proxy server

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

但是,您不能安装相同的文件:

# yum install nginx

输出示例:

Loaded plugins: product-id, rhnplugin, subscription-manager
Updating certificate-based repositories.
Setting up Install Process
Nothing to do

您还可以按以下方式使用yum命令行选项,而无需编辑Repo文件:

# yum --exclude=nginx* update

您可以如下列出软件包:

# yum --exclude=nginx\* --exclude=lighttpd\* update

或者

# yum -x nginx -x lighttpd update

或者

# yum -x 'nginx*' -x 'lighttpd*' update