runsisi's

technical notes

yum versionlock

2019-02-02 runsisi#yum

Ceph 的 ceph-selinux rpm 安装包对 selinux 的依赖不是在 spec 文件里写死的,而是直接依赖当前编译机器的 selinux-policy-devel 版本,在某些时候可能需要支持在低版本的 CentOS 上安装 Ceph,因此编译机器在系统升级时不能升级 selinux 相关的包,在这种情况下可以使用 yum 的 versionlock 插件锁定某些软件包的版本号。

安装

~$ sudo yum install yum-plugin-versionlock

帮助文档

~$ yum help versionlock
Loaded plugins: copr, versionlock
versionlock [add|exclude|list|delete|clear] [PACKAGE-wildcard]

Control package version locks.

锁定版本

~$ sudo yum versionlock add gcc-4.8.5-28.el7_5.1.*
Loaded plugins: copr, versionlock
Adding versionlock on: 0:gcc-4.8.5-28.el7_5.1
versionlock added: 1
~$ sudo yum versionlock add gcc-c++-4.8*
Loaded plugins: copr, versionlock
Adding versionlock on: 0:gcc-c++-4.8.5-28.el7_5.1
versionlock added: 1
~$ sudo yum versionlock add gc*
Loaded plugins: copr, versionlock
Adding versionlock on: 0:gcc-base-debuginfo-4.8.5-28.el7_5.1
Adding versionlock on: 0:gcc-debuginfo-4.8.5-28.el7_5.1
versionlock added: 2
~$ rpm -qa | grep ^gcc-
gcc-4.8.5-28.el7_5.1.x86_64
gcc-c++-4.8.5-28.el7_5.1.x86_64
gcc-debuginfo-4.8.5-28.el7_5.1.x86_64
gcc-base-debuginfo-4.8.5-28.el7_5.1.x86_64

显然,* 就是一个通配符而已,但是需要注意 * 不能包含 arch 及之后的字段。

查看所有已锁定版本

~$ yum versionlock list
Loaded plugins: copr, versionlock
...
0:gcc-base-debuginfo-4.8.5-28.el7_5.1.*
0:gcc-c++-4.8.5-28.el7_5.1.*
0:gcc-4.8.5-28.el7_5.1.*
0:gcc-debuginfo-4.8.5-28.el7_5.1.*
versionlock list done

解除版本锁定

~$ sudo yum versionlock delete gcc-*
Loaded plugins: copr, versionlock
Deleting versionlock for: 0:gcc-base-debuginfo-4.8.5-28.el7_5.1.*
Deleting versionlock for: 0:gcc-c++-4.8.5-28.el7_5.1.*
Deleting versionlock for: 0:gcc-4.8.5-28.el7_5.1.*
Deleting versionlock for: 0:gcc-debuginfo-4.8.5-28.el7_5.1.*
versionlock deleted: 4

* 的规则与前面锁定版本的要求一致。

删除所有版本锁定

~$ sudo yum versionlock clear

配置文件

~$ cat /etc/yum/pluginconf.d/versionlock.conf
[main]
enabled = 1
locklist = /etc/yum/pluginconf.d/versionlock.list
#  Uncomment this to lock out "upgrade via. obsoletes" etc. (slower)
# follow_obsoletes = 1

数据文件

~$ cat /etc/yum/pluginconf.d/versionlock.list
...

# Added locks on Sat Feb  2 09:43:18 2019
0:gcc-4.8.5-28.el7_5.1.*

# Added locks on Sat Feb  2 09:43:32 2019
0:gcc-c++-4.8.5-28.el7_5.1.*

# Added locks on Sat Feb  2 09:43:40 2019
0:gcc-base-debuginfo-4.8.5-28.el7_5.1.*
0:gcc-debuginfo-4.8.5-28.el7_5.1.*

参考资料

How to restrict yum to install or upgrade a package to a fixed specific package version? https://access.redhat.com/solutions/98873