CentOS/RHEL:特定版本的Yum Lock软件包版本

时间:2020-01-09 10:34:14  来源:igfitidea点击:

我是新的CentOS/RHEL 6.x服务器用户和DevOP。
我需要在通过yum命令更新的服务器上锁定名为nginx的软件包。
如何在CentOS/Red Hat Enterprise Linux(RHEL)6.x或Fedora Linux上的特定版本上锁定软件包版本?
您有以下两种选择:

  • 将--exclude指令传递给yum命令,以定义要从更新或安装中排除的软件包列表。
  • yum versionlock命令版本锁定rpm软件包命令。

方法1:yum versionlock命令

您需要安装yum-plugin-versionlock插件。
它为软件包采用了一组名称/版本,并排除了这些软件包的所有其他版本(包括可选的以下已过时的版本)。
这使您可以防止软件包被较新版本更新。

在CentOS/RHEL服务器上安装yum-plugin-versionlock

要安装yum-plugin-versionlock软件包,请输入:

# yum -y install yum-versionlock

或者

# yum -y install yum-plugin-versionlock

输出示例:

Resolving Dependencies
--> Running transaction check
---> Package yum-plugin-versionlock.noarch 0:1.1.30-14.el6 will be installed
--> Finished Dependency Resolution
 
Dependencies Resolved
 
================================================================================
Package                  Arch     Version         Repository              Size
================================================================================
Installing:
yum-plugin-versionlock   noarch   1.1.30-14.el6   rhel-x86_64-server-6    27 k
 
Transaction Summary
================================================================================
Install       1 Package(s)
 
Total download size: 27 k
Installed size: 0  
Downloading Packages:
yum-plugin-versionlock-1.1.30-14.el6.noarch.rpm          |  27 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : yum-plugin-versionlock-1.1.30-14.el6.noarch                  1/1 
  Verifying  : yum-plugin-versionlock-1.1.30-14.el6.noarch                  1/1 
 
Installed:
  yum-plugin-versionlock.noarch 0:1.1.30-14.el6                                 
 
Complete!

语法

基本语法如下:

yum versionlock package-name-here
yum versionlock package1 package2
yum versionlock add package-wildcard
yum versionlock add package1\*
yum versionlock [command] package1\*

要将nginx软件包锁定为当前版本,请输入:

# yum versionlock nginx

或者

# yum versionlock add nginx

要列出所有当前的版本锁条目,请运行:

# yum versionlock list

要删除/删除nginx软件包的版本锁条目,请输入:

# yum versionlock delete nginx

要删除所有版本锁条目:

# yum versionlock clear

输出示例:

Loaded plugins: product-id, rhnplugin, security, subscription-manager,
              : versionlock
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
This system is receiving updates from RHN Classic or RHN Satellite.
versionlock cleared

在可用存储库中为软件包的最新版本添加排除项(在版本锁中)

# yum versionlock exclude pakage1 package2
# yum versionlock exclude pakage-wildcard-here

演示:使用yum lock版本命令锁定ethtool软件包

首先,检查ethtool软件包在服务器上是否有更新:

# yum check-update
# yum check-update ethtool

输出示例:

Loaded plugins: product-id, rhnplugin, security, subscription-manager,
              : versionlock
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
This system is receiving updates from RHN Classic or RHN Satellite.

ethtool.x86_64               2:3.5-1.2.el6_5                rhel-x86_64-server-6

锁定ethtool,输入:

# yum versionlock add ethtool

输出示例:

Loaded plugins: product-id, rhnplugin, security, subscription-manager,
              : versionlock
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
This system is receiving updates from RHN Classic or RHN Satellite.
Adding versionlock on: 2:ethtool-3.5-1.el6
versionlock added: 1

列出版本锁中的条目,输入:

# yum versionlock list

输出示例:

Loaded plugins: product-id, rhnplugin, security, subscription-manager,
              : versionlock
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
This system is receiving updates from RHN Classic or RHN Satellite.
2:ethtool-3.5-1.el6.*
versionlock list done

尝试更新ethtool软件包,输入:

# yum update ethtool

输出示例:

Loaded plugins: product-id, rhnplugin, security, subscription-manager,
              : versionlock
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
This system is receiving updates from RHN Classic or RHN Satellite.
Setting up Update Process
No Packages marked for Update

删除ethtool版本锁,以便yum可以应用更新:

# yum versionlock delete '2:ethtool-3.5-1.el6.*'

输出示例:

Loaded plugins: product-id, rhnplugin, security, subscription-manager,
              : versionlock
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
This system is receiving updates from RHN Classic or RHN Satellite.
Deleting versionlock for: 2:ethtool-3.5-1.el6.*
versionlock deleted: 1

小技巧:列出/查看软件包的历史记录?

使用以下命令:

# yum --showduplicates list packageNameHere
# yum --showduplicates list ethtool

yum命令具有历史记录选项。
它允许管理员访问有关已在系统上运行的yum事务的历史记录的详细信息。
您可以查看过去的交易中发生了什么。
您可以使用各种命令行选项来查看发生的情况,使用undo/redo/rollback对该信息进行操作并启动新的历史文件。

方法#2:yum exclude命令从yum更新锁定程序包版本

编辑/etc/yum.conf

# vi /etc/yum.conf

在[main]部分下添加以下行以锁定php和nginx,输入:

exclude=php* nginx*

保存并关闭文件。