网站搜索

如何启用、禁用和安装 Yum 插件


YUM 插件是一些小程序,可以扩展和提高包管理器的整体性能。其中一些是默认安装的,而许多则不是。每当您运行任何 yum 命令时,Yum 都会通知您哪些插件(如果有)已加载并处于活动状态。

在这篇简短的文章中,我们将解释如何在 CentOS/RHEL 发行版中打开或关闭以及配置 YUM 包管理器插件。

要查看所有活动插件,请在终端上运行 yum 命令。从下面的输出中,您可以看到 fastestmirror 插件已加载。

yum search nginx

Loaded plugins: fastestmirror
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
Determining fastest mirrors
...

启用 YUM 插件

要启用 yum 插件,请确保指令 plugins=11 表示打开)存在于 [main] 部分下。/etc/yum.conf文件,如下图。

vi /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1 installonly_limit=5

这是全局启用 yum 插件的通用方法。正如我们稍后将看到的,您可以在其接收配置文件中单独启用它们。

禁用 YUM 插件

要禁用 yum 插件,只需将上面的值更改为 0(意思是关闭),这会全局禁用所有插件。

plugins=0	

在此阶段,值得注意的是:

  • 由于一些插件(例如 product-idsubscription-manager)提供基本的 yum 功能,因此不建议关闭所有插件,尤其是在全局范围内。
  • 其次,全局禁用插件是一种简单的解决方法,这意味着您可以在调查 yum 可能出现的问题时使用此规定。
  • 各种插件的配置位于 /etc/yum/pluginconf.d/ 中。
  • /etc/yum.conf 中全局禁用插件会覆盖各个配置文件中的设置。
  • 并且您还可以在运行 yum 时禁用单个或所有 yum 插件,如下所述。

安装和配置额外的 YUM 插件

您可以使用此命令查看所有 yum 插件及其描述的列表。

yum search yum-plugin

Loaded plugins: fastestmirror
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
Loading mirror speeds from cached hostfile
 * base: mirror.sov.uk.goscomb.net
 * epel: www.mirrorservice.org
 * extras: mirror.sov.uk.goscomb.net
 * updates: mirror.sov.uk.goscomb.net
========================================================================= N/S matched: yum-plugin ==========================================================================
PackageKit-yum-plugin.x86_64 : Tell PackageKit to check for updates when yum exits
fusioninventory-agent-yum-plugin.noarch : Ask FusionInventory agent to send an inventory when yum exits
kabi-yum-plugins.noarch : The CentOS Linux kernel ABI yum plugin
yum-plugin-aliases.noarch : Yum plugin to enable aliases filters
yum-plugin-auto-update-debug-info.noarch : Yum plugin to enable automatic updates to installed debuginfo packages
yum-plugin-changelog.noarch : Yum plugin for viewing package changelogs before/after updating
yum-plugin-fastestmirror.noarch : Yum plugin which chooses fastest repository from a mirrorlist
yum-plugin-filter-data.noarch : Yum plugin to list filter based on package data
yum-plugin-fs-snapshot.noarch : Yum plugin to automatically snapshot your filesystems during updates
yum-plugin-keys.noarch : Yum plugin to deal with signing keys
yum-plugin-list-data.noarch : Yum plugin to list aggregate package data
yum-plugin-local.noarch : Yum plugin to automatically manage a local repo. of downloaded packages
yum-plugin-merge-conf.noarch : Yum plugin to merge configuration changes when installing packages
yum-plugin-ovl.noarch : Yum plugin to work around overlayfs issues
yum-plugin-post-transaction-actions.noarch : Yum plugin to run arbitrary commands when certain pkgs are acted on
yum-plugin-priorities.noarch : plugin to give priorities to packages from different repos
yum-plugin-protectbase.noarch : Yum plugin to protect packages from certain repositories.
yum-plugin-ps.noarch : Yum plugin to look at processes, with respect to packages
yum-plugin-remove-with-leaves.noarch : Yum plugin to remove dependencies which are no longer used because of a removal
yum-plugin-rpm-warm-cache.noarch : Yum plugin to access the rpmdb files early to warm up access to the db
yum-plugin-show-leaves.noarch : Yum plugin which shows newly installed leaf packages
yum-plugin-tmprepo.noarch : Yum plugin to add temporary repositories
yum-plugin-tsflags.noarch : Yum plugin to add tsflags by a commandline option
yum-plugin-upgrade-helper.noarch : Yum plugin to help upgrades to the next distribution version
yum-plugin-verify.noarch : Yum plugin to add verify command, and options
yum-plugin-versionlock.noarch : Yum plugin to lock specified packages from being updated

要安装插件,请使用与安装包相同的方法。例如,我们将安装 changelog 插件,用于显示更新之前/之后的软件包变更日志。

yum install yum-plugin-changelog 

安装后,默认情况下将启用更改日志,请查看其配置文件进行确认。

vi /etc/yum/pluginconf.d/changelog.conf

现在您可以像这样查看软件包(在本例中为httpd)的变更日志

yum changelog httpd

Loaded plugins: changelog, fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.linode.com
 * epel: mirror.freethought-internet.co.uk
 * extras: mirrors.linode.com
 * updates: mirrors.linode.com

Listing all changelogs

==================== Installed Packages ====================
httpd-2.4.6-45.el7.centos.4.x86_64       installed
* Wed Apr 12 17:30:00 2017 CentOS Sources <[email > - 2.4.6-45.el7.centos.4
- Remove index.html, add centos-noindex.tar.gz
- change vstring
- change symlink for poweredby.png
- update welcome.conf with proper aliases
...

在命令行中禁用 YUM 插件

如前所述,我们还可以通过使用这两个重要选项在运行 yum 命令时关闭一个或多个插件。

  • --noplugins – 关闭所有插件
  • --disableplugin=plugin_name – 禁用单个插件

您可以像此 yum 命令一样禁用所有插件。

yum search --noplugins yum-plugin

下一个命令在安装 httpd 软件包时禁用插件 fastestmirror

yum install --disableplugin=fastestmirror httpd

Loaded plugins: changelog
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-45.el7.centos.4 will be updated
--> Processing Dependency: httpd = 2.4.6-45.el7.centos.4 for package: 1:mod_ssl-2.4.6-45.el7.centos.4.x86_64
---> Package httpd.x86_64 0:2.4.6-67.el7.centos.6 will be an update
...

现在就是这样!您可能还想阅读以下与 YUM 相关的文章。

  1. 如何使用“Yum History”查找已安装或已删除的软件包信息
  2. 如何修复 Yum 错误:数据库磁盘映像格式错误

在本指南中,我们展示了如何在 CentOS/RHEL 7 中激活、配置或停用 YUM 包管理器插件。使用下面的评论表提出任何问题或分享您对本文的看法。