CentOS / RHEL 下锁定软件包在一个特定的版本

默北 LinuxCentOS / RHEL 下锁定软件包在一个特定的版本已关闭评论10,795字数 1946阅读6分29秒阅读模式

有些时候,我们在对系统进行更新操作时,又不需要对某些软件包进行升级操作,要把该包锁定在某个特定版本下。比如mysql-server,为了避免更新遇到不可预知的错误,禁止对该包进行升级。

那么该如何锁定包在特定版本下呢?文章源自运维生存时间-https://www.ttlsa.com/linux/centos-rhel-lock-package-version-at-a-particular-version/

在上一篇《CentOS / RHEL 防止Kernel升级》,该方法也可以实现。文章源自运维生存时间-https://www.ttlsa.com/linux/centos-rhel-lock-package-version-at-a-particular-version/

下面我来介绍另一种方法。使用yum versionlock 命令来锁定版本。文章源自运维生存时间-https://www.ttlsa.com/linux/centos-rhel-lock-package-version-at-a-particular-version/

1. 安装文章源自运维生存时间-https://www.ttlsa.com/linux/centos-rhel-lock-package-version-at-a-particular-version/

# yum install yum-plugin-versionlock.noarch

2. 添加锁定包文章源自运维生存时间-https://www.ttlsa.com/linux/centos-rhel-lock-package-version-at-a-particular-version/

perl包锁定到当前版本文章源自运维生存时间-https://www.ttlsa.com/linux/centos-rhel-lock-package-version-at-a-particular-version/

# yum versionlock perl
Loaded plugins: fastestmirror, versionlock
Adding versionlock on: 4:perl-5.10.1-127.el6
versionlock added: 1

3. 查看锁定列表文章源自运维生存时间-https://www.ttlsa.com/linux/centos-rhel-lock-package-version-at-a-particular-version/

# yum versionlock list
Loaded plugins: fastestmirror, versionlock
4:perl-5.10.1-127.el6.*
versionlock list done

4. 清除单个包锁定文章源自运维生存时间-https://www.ttlsa.com/linux/centos-rhel-lock-package-version-at-a-particular-version/

# yum versionlock delete '4:perl-5.10.1-127.el6.*'
Loaded plugins: fastestmirror, versionlock
Deleting versionlock for: 4:perl-5.10.1-127.el6.*
versionlock deleted: 1

5. 清除所有锁定文章源自运维生存时间-https://www.ttlsa.com/linux/centos-rhel-lock-package-version-at-a-particular-version/

# yum versionlock clear
Loaded plugins: fastestmirror, versionlock
versionlock cleared

6. 实例文章源自运维生存时间-https://www.ttlsa.com/linux/centos-rhel-lock-package-version-at-a-particular-version/

# yum check-update perl
Loaded plugins: fastestmirror, versionlock
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * epel: mirror01.idc.hinet.net
 * extras: mirrors.163.com
 * updates: mirrors.163.com

perl.x86_64                                                               4:5.10.1-136.el6                                                               base

锁定perl当前版本文章源自运维生存时间-https://www.ttlsa.com/linux/centos-rhel-lock-package-version-at-a-particular-version/

# yum versionlock perl
Loaded plugins: fastestmirror, versionlock
Adding versionlock on: 4:perl-5.10.1-127.el6
versionlock added: 1

更新perl版本文章源自运维生存时间-https://www.ttlsa.com/linux/centos-rhel-lock-package-version-at-a-particular-version/

# yum update perl
Loaded plugins: fastestmirror, versionlock
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * epel: mirror01.idc.hinet.net
 * extras: mirrors.163.com
 * updates: mirrors.163.com
Setting up Update Process
No Packages marked for Update

No Packages marked for Update可见锁定成功了。文章源自运维生存时间-https://www.ttlsa.com/linux/centos-rhel-lock-package-version-at-a-particular-version/

为了更新取消perl锁定文章源自运维生存时间-https://www.ttlsa.com/linux/centos-rhel-lock-package-version-at-a-particular-version/

# yum versionlock delete '4:perl-5.10.1-127.el6.*'
Loaded plugins: fastestmirror, versionlock
Deleting versionlock for: 4:perl-5.10.1-127.el6.*
versionlock deleted: 1
# yum versionlock list
Loaded plugins: fastestmirror, versionlock
0:mysql-server-5.1.73-3.el6_5.*
0:mysql-5.1.73-3.el6_5.*
versionlock list done

更新perl包文章源自运维生存时间-https://www.ttlsa.com/linux/centos-rhel-lock-package-version-at-a-particular-version/

# yum update -y perl
Updated:
  perl.x86_64 4:5.10.1-136.el6                                                                                                                                    
Complete!

更新前后perl版本文章源自运维生存时间-https://www.ttlsa.com/linux/centos-rhel-lock-package-version-at-a-particular-version/

[root@AY14040211382766189cZ ~]# rpm -qa | grep perl
perl-5.10.1-127.el6.x86_64
[root@AY14040211382766189cZ ~]# rpm -qa | grep perl
perl-5.10.1-136.el6.x86_64

Centos文章源自运维生存时间-https://www.ttlsa.com/linux/centos-rhel-lock-package-version-at-a-particular-version/

使用该指令就可以避免误升级软件包到最新版本。特别是在生产环境下的软件包,版本的更新可以有些配置参数不兼容到服务停止,从而影响正常的访问。文章源自运维生存时间-https://www.ttlsa.com/linux/centos-rhel-lock-package-version-at-a-particular-version/ 文章源自运维生存时间-https://www.ttlsa.com/linux/centos-rhel-lock-package-version-at-a-particular-version/

weinxin
我的微信
微信公众号
扫一扫关注运维生存时间公众号,获取最新技术文章~
默北
  • 本文由 发表于 15/04/2014 09:00:20
  • 转载请务必保留本文链接:https://www.ttlsa.com/linux/centos-rhel-lock-package-version-at-a-particular-version/