最新消息:

CentOS / RHEL:yum升级时锁定特定软件版本

Linux运维 大步 2767浏览 0评论

在centos/RHEL中,用yum 升级时,会把所有有更新版的旧版本软件全都升级,这样可能带来不稳定的因素,所以,我们要做的就是在yum升级时锁定特定软件版本,不让某些软件升级到新版本。

yum相关文章:

yum 命令跳过特定(指定)软件包升级方法

用exclude参数(禁止)排除指定软件包被yum升级

yum升级中锁定指定软件版本禁止其升级(手动)

yum使用yum-plugin-security插件安全性升级

yum安装指定(特定)版本(旧版本)软件包的方法

yum –showduplicates 介绍和使用方法

CentOS / RHEL:yum升级时锁定特定软件版本的方法如下:

有两个参数如下:

1. --exculede 参数表示排除某些软件在在升级名单内,就是不让它升级。

2. yum versionlock 安装yum的锁定版本的插件 versionlock

 

方法一: yum versionlock 命令

注意:用yum安装yum-plugin-versionlock 时,可能因为你的源中的版本不是最新的 ,使得下面的教程不能使用,所以,你只能用老版本versionlock,老版本的versionlock没有下面所写的那些参数,从而只能用手动编辑 cat /etc/yum/pluginconf.d/versionlock.list来锁定版本了。参考文章《yum升级中锁定指定软件版本禁止其升级(手动)》。yum官方FAQ

 

首先,要安装 yum-plugin-versionlock 插件。它能在yum升级时候,将指定软件包名或版本保护起来(即使软件包是旧的版本),防止被yum升级的到新的版本。

安装 yum- versionlock 到centos/rhel 服务器

输入以下命令安装yum- versionlock

# yum -y install yum-plugin-versionlock

输出如下:

[root@ksharpdabu ~]# yum install yum-versionlock

Loaded plugins: fastestmirror

Loading mirror speeds from cached hostfile

* base: centos.mirror.freedomvoice.com

* extras: mirror.pac-12.org

* updates: mirrors.usc.edu

Setting up Install Process

Resolving Dependencies

--> Running transaction check

---> Package yum-versionlock.noarch 0:1.1.16-21.el5.centos set to be updated

--> Finished Dependency Resolution

 

Dependencies Resolved

 

======================================================================

Package Arch Version Repository

Size

======================================================================

Installing:

yum-versionlock noarch 1.1.16-21.el5.centos base 17 k

 

Transaction Summary

======================================================================

Install 1 Package(s)

Upgrade 0 Package(s)

 

Total download size: 17 k

Is this ok [y/N]: y

Downloading Packages:

yum-versionlock-1.1.16-21.el5.centos.noarch.rp | 17 kB 00:00

Running rpm_check_debug

Running Transaction Test

Finished Transaction Test

Transaction Test Succeeded

Running Transaction

Installing : yum-versionlock 1/1

 

Installed:

yum-versionlock.noarch 0:1.1.16-21.el5.centos

 

Complete!

 

语法

基本语法如下:

yum versionlock package-name-here

yum versionlock package1 package2

yum versionlock add package-wildcard

yum versionlock add package1\*

yum versionlock [command] package1\*

注意:可以使用通配符,如:

yum versionlock add php*

显示如下:

Loaded plugins: security, versionlock

Adding versionlock on: 0:php-common-5.3.3-22.el6

Adding versionlock on: 0:php-5.3.3-22.el6

Adding versionlock on: 0:php-cli-5.3.3-22.el6

versionlock added:

 

锁定nginx 保持当前版本,输入:

# yum versionlock nginx

或者

# yum versionlock add nginx

 

 

列出被versionlock锁定的所有软件包项目,输入:

# yum versionlock list

移除/删除 被versionlock锁定的软件包,如 nginx,输入:

# yum versionlock delete nginx

 

移除所有被被versionlock锁定的软件包,输入

# 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

 

实例演示:假设要锁定ethtool的版本,不让它被yum升级。

1.检查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

 

2.锁定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

3. 显示被锁定的软件包项目

# 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.

2:ethtool-3.5-1.el6.*

versionlock list done

 

4.尝试升级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

 

 

解除versionlock对ethtool的锁定,yum升级ethtool

# 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 --exclude 锁定软件包版本

编辑 /etc/yum.conf

# vi /etc/yum.conf

在[main]段添加要锁定的php和nginx,输入:

exclude=php* nginx*

保存关闭该文件。再参见《用exclude参数(禁止)排除指定软件包被yum升级

 

技巧(tip)

查看软件版本的方法,假设查看ppp的版本,输入:

#rpm -qa | grep ppp

输出如下:

ppp-2.4.4-2.el5

英文原文见:CentOS / RHEL: Yum Lock Package Version At a Particular Version

转载请注明:大步's Blog » CentOS / RHEL:yum升级时锁定特定软件版本

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (4)

SiteMap