

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 为集群的操作系统打补丁
<a name="patching-cluster-v3"></a>

本教程介绍如何通过构建打补丁的 AMI 并更新 Amazon ParallelCluster 集群以使用它，将操作系统更新应用到正在运行的集群的节点，而无需从头开始重新创建集群。

该程序分为三个步骤：

1. 构建包含操作系统更新的已修补的 AMI。

1. 更新计算和登录队列以使用已修补的 AMI。

   这将从打补丁的 AMI 启动新实例以替换现有节点。

1. 对头节点应用相同的补丁策略。

   无法替换头节点 AMI，因此必须在适当位置修补头节点，然后重新启动。

步骤 1 和 3 都使用相同的命令（在中定义）将操作系统更新应用到节点[修补节点](#patch-a-node-v3)。

**集群停机时间**  
此过程意味着由于更换计算和登录节点以及头节点重启而导致集群停机。

## 第 1 步：构建打补丁的 AMI
<a name="patching-cluster-build-ami-v3"></a>

构建包含操作系统更新的自定义 AMI：

1. 从您的集群当前使用的 AMI 启动实例。

1. 通过运行中的命令来修补实例[修补节点](#patch-a-node-v3)。

1. 从打补丁的实例创建新的 AMI。

例如，记下已修补的 AMI 的 ID`ami-123456789`，因为您将在下一步中使用它。

## 第 2 步：将计算和登录节点更新到已修补的 AMI
<a name="patching-cluster-update-fleet-v3"></a>

**注意**  
必须停止登录节点才能使其图像更改生效。将登录池设置[`Count`](LoginNodes-v3.md#yaml-LoginNodes-Pools-Count)为`0`，应用更新，然后恢复`Count`到其原始值并再次应用更新。

1. 要在不停止计算队列的情况下替换计算和登录节点，请在集群配置`DRAIN`中[`QueueUpdateStrategy`](Scheduling-v3.md#yaml-Scheduling-SlurmSettings-QueueUpdateStrategy)将 [`SlurmSettings`](Scheduling-v3.md#Scheduling-v3-SlurmSettings) /设置为。

1. 在集群配置中，将打补丁的 AMI 设置为计算队列和登录节点池的自定义 AMI：
   + [`SlurmQueues`](Scheduling-v3.md#Scheduling-v3-SlurmQueues) / [`Image`](Scheduling-v3.md#Scheduling-v3-SlurmQueues-Image) / [`CustomAmi`](Scheduling-v3.md#yaml-Scheduling-SlurmQueues-Image-CustomAmi)
   + [`Pools`](LoginNodes-v3.md#LoginNodes-v3-Pools) / [`Image`](LoginNodes-v3.md#yaml-LoginNodes-Pools-Image) / [`CustomAmi`](LoginNodes-v3.md#yaml-LoginNodes-Pools-Image-CustomAmi)

1. 使用[`pcluster 更新集群`](pcluster.update-cluster-v3.md)命令应用更改。

1. 此更新将计算节点替换为运行已修补的 AMI 的实例，并从打补丁的 AMI 重新创建登录节点。

## 第 3 步：修补头节点
<a name="patching-cluster-head-node-v3"></a>

头节点是一个静态实例，因此您可以将其修补到位，然后重启它。

1. 连接到头节点。

1. 通过运行中的命令来修补头节点[修补节点](#patch-a-node-v3)。

1. 等待头节点再次通过 SSH 访问。

## 修补节点
<a name="patch-a-node-v3"></a>

使用节点操作系统的命令，使用节点的包管理器应用所有可用的操作系统更新。这些命令既可以在构建已修补的 AMI ([第 1 步：构建打补丁的 AMI](#patching-cluster-build-ami-v3)) 时使用，也可以在修补头节点 ([第 3 步：修补头节点](#patching-cluster-head-node-v3)) 时使用。

**与 Lustre 客户端的内核兼容性**  
将内核升级到 FSx for Lustre 客户端支持的最新版本之后，重启后会中断 FSx 的挂载。  
为防止这种情况，请将内核限制在 Lustre 客户端支持的最新版本。以下命令假定该版本；设置`kernel_cap`为 Lustre 客户端支持的最新内核。亚马逊 Linux 2023 将 Lustre 模块与内核一起提供，因此不需要上限。  
有关更多信息，请参阅《* FSx for Lustre 用户[指南》中的](https://docs.amazonaws.cn/fsx/latest/LustreGuide/install-lustre-client.html)安装 Lustre 客户端。*

**Amazon Linux 2023**

```
# Refresh the package manager cache.
sudo dnf clean all
sudo dnf makecache --refresh -y

# No kernel cap needed: the Lustre module ships in-tree with the kernel.

# Apply all available updates.
sudo dnf upgrade -y
```

**RHEL 8、RHEL 9、Rocky Linux 8 和 Rocky Linux 9 **

```
# Refresh the package manager cache.
sudo dnf clean all
sudo dnf makecache --refresh -y

# Determine the kernel cap: the newest kernel version supported by the FSx for Lustre client.
# We assume 5.14.0-503.11.1.el9_5.x86_64; set kernel_cap to the newest kernel your Lustre client supports.
kernel_cap=5.14.0-503.11.1.el9_5.x86_64

# Cap the kernel at that version and version-lock it.
sudo dnf install -y python3-dnf-plugin-versionlock
sudo dnf versionlock add "kernel-${kernel_cap}" "kernel-core-${kernel_cap}" "kernel-modules-${kernel_cap}" "kernel-modules-core-${kernel_cap}" "kernel-tools-${kernel_cap}"

# Apply all available updates.
sudo dnf upgrade -y

# Refresh the Lustre client for the kernel about to boot.
new_kernel=$(rpm -q kernel --qf '%{VERSION}-%{RELEASE}.%{ARCH}\n' | sort -V | tail -n1)
if ! modinfo -k "$new_kernel" lustre >/dev/null 2>&1; then
  sudo sed -i -E "s#(/el/)[0-9]+(\.[0-9]+)?#\1$(. /etc/os-release && echo "$VERSION_ID")#" /etc/yum.repos.d/aws-fsx.repo
  sudo dnf clean metadata
  sudo dnf upgrade -y kmod-lustre-client lustre-client
fi
```

**ubuntu 22.04 和 24.04 **

```
# Refresh the package manager cache.
sudo DEBIAN_FRONTEND=noninteractive apt-get update -y

# Determine the kernel cap: the newest kernel version supported by the FSx for Lustre client.
# We assume 6.8.0-1021-aws; set kernel_cap to the newest kernel your Lustre client supports.
kernel_cap=6.8.0-1021-aws

# Cap the kernel at that version and version-lock it.
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y "linux-image-${kernel_cap}" "linux-headers-${kernel_cap}" "linux-modules-${kernel_cap}" "linux-modules-extra-${kernel_cap}"
sudo apt-mark hold linux-aws linux-image-aws linux-headers-aws

# Apply all available updates. The dpkg options keep locally-modified config files
# (e.g. efs-utils.conf); without them dpkg prompts and aborts on EOF, and
# DEBIAN_FRONTEND=noninteractive does not cover this.
sudo DEBIAN_FRONTEND=noninteractive apt-get upgrade -y -o Dpkg::Options::="--force-confold" -o Dpkg::Options::="--force-confdef"

# Refresh the Lustre client for the kernel about to boot.
new_kernel=$(dpkg-query -W -f='${Package}\n' 'linux-image-*-aws' | sed 's/^linux-image-//' | grep -E '^[0-9]' | sort -V | tail -n1)
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y "lustre-client-modules-${new_kernel}" lustre-client-modules-aws
```

应用更新后，在任何操作系统上重新启动节点以将其激活。更新安装新内核时需要重启：

```
$ sudo reboot
```