CentOS、Redhat中锁定、解锁软件包版本的方法(y
那么该如何锁定包在特定版本下呢?下面我来介绍一种方法。使用yum versionlock 命令来锁定版本。
1. 安装
复制代码
代码如下:
# yum install yum-plugin-versionlock.noarch
2. 添加锁定包
例子:将perl包锁定到当前版本
复制代码
# yum versionlock perl
Loaded plugins: fastestmirror, versionlock
Adding versionlock on: 4:perl-5.10.1-127.el6
versionlock added: 1
代码如下:
# yum versionlock perl
Loaded plugins: fastestmirror, versionlock
Adding versionlock on: 4:perl-5.10.1-127.el6
versionlock added: 1
3. 查看锁定列表
复制代码
代码如下:
# yum versionlock list
Loaded plugins: fastestmirror, versionlock
4:perl-5.10.1-127.el6.*
versionlock list done
Loaded plugins: fastestmirror, versionlock
4:perl-5.10.1-127.el6.*
versionlock list done
4. 清除单个包锁定
复制代码
代码如下:
# 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
Loaded plugins: fastestmirror, versionlock
Deleting versionlock for: 4:perl-5.10.1-127.el6.*
versionlock deleted: 1
5. 清除所有锁定
复制代码
代码如下:
# yum versionlock clear
Loaded plugins: fastestmirror, versionlock
versionlock cleared
Loaded plugins: fastestmirror, versionlock
versionlock cleared
6. 实例
复制代码
代码如下:
# 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
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当前版本
复制代码
代码如下:
# yum versionlock perl
Loaded plugins: fastestmirror, versionlock
Adding versionlock on: 4:perl-5.10.1-127.el6
versionlock added: 1
Loaded plugins: fastestmirror, versionlock
Adding versionlock on: 4:perl-5.10.1-127.el6
versionlock added: 1
更新perl版本
复制代码
# 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
代码如下:
# 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可见锁定成功了。
为了更新取消perl锁定
复制代码
# 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
代码如下:
# 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包
复制代码
# yum update -y perl
Updated:
perl.x86_64 4:5.10.1-136.el6
Complete!
代码如下:
# yum update -y perl
Updated:
perl.x86_64 4:5.10.1-136.el6
Complete!
更新前后perl版本
复制代码
[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
代码如下:
[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
使用该指令就可以避免误升级软件包到最新版本。特别是在生产环境下的软件包,版本的更新可以有些配置参数不兼容到服务停止,从而影响正常的访问。