在 Red Hat Enterprise Linux 中使用 yum 更新系统时,如何排除内核或其他软件包使它们不被更新?
Environment
- Red Hat Enterprise Linux (RHEL) 5
- Red Hat Enterprise Linux (RHEL) 6
- Red Hat Enterprise Linux (RHEL) 7
- Red Hat Enterprise Linux (RHEL) 8
- Red Hat Enterprise Linux (RHEL) 9
- Red Hat Satellite
- Red Hat Network
Issue
- 在 Red Hat Enterprise Linux 中使用 yum 更新系统时,如何排除内核或其他软件包使它们不被更新?
- 如何在 yum 中使用 exclude 选项?
- 在从 Satellite Server 更新系统时如果防止一个特定的软件包不被更新?
- 如何仅排除 32 位或 64 位的软件包?
Resolution
-
Red Hat Enterprise Linux 4 中的
up2date命令会默认排除内核更新。Red Hat Enterprise Linux 5 中的yum默认会包括内核更新。 -
在 Red Hat Enterprise Linux 5、6、7、8 和 9 中使用
yum更新时,要防止内核或特定软件包不被安装或更新,可以使用以下选项: -
通过命令行临时禁用:
# yum update --exclude=PACKAGENAME
例如,要排除所有与内核相关的软件包:
# yum update --exclude=kernel*
对于 RHEL7、RHEL8 和 RHEL9,也排除以下软件包。
# yum update --exclude=kernel* --exclude=kmod-kvdo
要排除 gcc 和 php 软件包:
# yum update --exclude=gcc,php
要排除 gcc* 和 php* 软件包:
# yum update --exclude=gcc* --exclude=php*
- 要进行永久更改,请编辑
/etc/yum.conf文件并编辑以下条目:
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exclude=kernel* <====
- 对于 RHEL7、RHEL8 和 RHEL9,也排除以下软件包。
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exclude=kernel* kmod-kvdo <====
备注:如果要排除多个软件包,使用一个空格或逗号分隔它们。 另外,不要在配置文件中添加多个 exclude= 行,因为 yum 仅考虑最后的 exclude 条目。
要排除 32 位软件包,编辑 /etc/yum.conf 文件。
exclude=*.i?86 *.i686
Root Cause
Diagnostic Steps
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Comments