本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
的节点生命周期操作示例 AWS 个
以下示例使用 AWS CLI 来配置节点生命周期操作。当您使用创建计算节点组时,您可以定义生命周期操作create-compute-node-group,或者使用在现有计算节点组上添加或更改这些操作update-compute-node-group。这两个命令的--node-lifecycle-actions值相同。
跨阶段的多个脚本
此示例将两个生命周期阶段的脚本与不同的执行策略和错误行为结合在一起。
aws pcs create-compute-node-group --regionregion\ --cluster-identifiermy-cluster\ --compute-node-group-identifiermy-cng\ --subnet-idssubnet-ExampleID1\ --custom-launch-template id=lt-ExampleID1,version='1' \ --iam-instance-profile-arn=arn:InstanceProfile\ --scaling-config minInstanceCount=0,maxInstanceCount=10\ --instance-configs instanceType=t3.large\ --node-lifecycle-actions '{ "stages": { "nodeBootstrapped": [ { "name": "Mount FSx Lustre", "scriptSource": { "scriptLocation": "s3://my-bucket/mount-fsx.sh" }, "arguments": ["fs-0abc123", "/scratch"], "executionPolicy": "EVERY_BOOT" }, { "name": "Join Active Directory", "scriptSource": { "scriptLocation": "s3://my-bucket/configure-ad.sh" }, "arguments": ["ad.example.com", "EXAMPLE"], "executionPolicy": "FIRST_BOOT_ONLY" } ], "nodeReady": [ { "name": "Configure CloudWatch logging", "scriptSource": { "scriptLocation": "s3://my-bucket/setup-cloudwatch.sh" }, "arguments": ["/aws/pcs/my-cluster"], "onError": "CONTINUE" } ] } }'
混合错误行为
此示例在同一阶段使用关键脚本和可选脚本。第一个在出现故障时终止节点;第二个继续。
aws pcs create-compute-node-group --regionregion\ --cluster-identifiermy-cluster\ --compute-node-group-identifiermy-cng\ --subnet-idssubnet-ExampleID1\ --custom-launch-template id=lt-ExampleID1,version='1' \ --iam-instance-profile-arn=arn:InstanceProfile\ --scaling-config minInstanceCount=0,maxInstanceCount=10\ --instance-configs instanceType=t3.large\ --node-lifecycle-actions '{ "stages": { "nodeBootstrapped": [ { "name": "Install required packages", "scriptSource": { "scriptLocation": "s3://my-bucket/install-packages.sh" }, "onError": "TERMINATE" }, { "name": "Install optional tools", "scriptSource": { "scriptLocation": "s3://my-bucket/install-optional.sh" }, "onError": "CONTINUE" } ] } }'
使用校验和进行完整性验证
添加 SHA-256 校验和,这样,如果脚本的内容不匹配,代理就会拒绝该脚本。
aws pcs update-compute-node-group \ --cluster-identifiermy-cluster\ --compute-node-group-identifiermy-cng\ --node-lifecycle-actions '{ "stages": { "nodeBootstrapped": [ { "name": "Mount EFS", "scriptSource": { "scriptLocation": "s3://my-bucket/mount-efs.sh", "checksum": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" }, "arguments": ["fs-12345678", "/shared"] } ] } }'
重启时启用脚本刷新
设置scriptCachingPolicy为REFRESH_ON_REBOOT。此UpdateComputeNodeGroup调用是配置更改,因此它会耗尽并替换现有实例。替换完成后,实例在每次重启时都会重新下载脚本。然后,您可以更新 Amazon S3 中的脚本内容,实例在下次重启时无需再调用 API 即可获得更改。
aws pcs update-compute-node-group \ --cluster-identifiermy-cluster\ --compute-node-group-identifiermy-cng\ --node-lifecycle-actions '{ "stages": { "nodeBootstrapped": [ { "name": "Mount EFS", "scriptSource": { "scriptLocation": "s3://my-bucket/mount-efs.sh" }, "arguments": ["fs-12345678", "/shared"], "executionPolicy": "EVERY_BOOT" } ] }, "scriptCachingPolicy": "REFRESH_ON_REBOOT" }'
从 AWS ParallelCluster 引导操作迁移
许多现有的 AWS ParallelCluster 引导脚本在 AWS PCS 生命周期操作中按原样运行。 AWS PCS 提供每脚本错误处理(TERMINATESTOP_SEQUENCE、或CONTINUE)和重启控制(FIRST_BOOT_ONLY或EVERY_BOOT)。 AWS PCS 的默认值为FIRST_BOOT_ONLY。要匹配 ParallelCluster 行为(每次启动时运行),executionPolicy请将设置为EVERY_BOOT。
AWS ParallelCluster |
AWS 个人电脑 |
|---|---|
|
|
|
|
|
没有 AWS PCS 等效物 |