사용자 지정 부트스트랩 작업 - AWS ParallelCluster

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

사용자 지정 부트스트랩 작업

HeadNode/CustomActions/OnNodeStart구성 설정을 정의하면 노드가 시작된 직후 임의의 코드를 AWS ParallelCluster 실행합니다. HeadNode/CustomActions/OnNodeConfigured구성 설정을 정의하는 경우 노드 구성이 올바르게 완료된 후 코드를 AWS ParallelCluster 실행합니다.

AWS ParallelCluster 버전 3.4.0부터 HeadNodeCustomActions/OnNodeUpdated구성 설정을 정의하면 헤드 노드 업데이트 후 코드를 실행할 수 있습니다.

대부분의 경우 이 코드는 Amazon Simple Storage Service(S3)에 저장되며 HTTPS 연결을 통해 액세스됩니다. 이 코드는 root로서 실행되며 클러스터 OS에서 지원되는 어떠한 스크립트 언어로든 작성될 수 있습니다. 코드는 일반적으로 Bash 또는 Python으로 작성됩니다.

참고

AWS ParallelCluster 버전 3.7.0부터 클러스터 Imds/ImdsSupport설정 기본값은 입니다. v2.0

새 클러스터를 생성하여 버전 3.7.0 이상으로 업그레이드할 때는 사용자 지정 부트스트랩 액션 스크립트를 IMDSv2와 호환되도록 업데이트하거나 클러스터 구성 파일에서 Imds/ImdsSupportv1.0에 설정하세요.

주의

공동 책임 모델에 설명된 대로 사용자 정의 스크립트와 인수를 구성하는 것은 사용자의 책임입니다. 사용자 지정 부트스트랩 스크립트와 인수가 클러스터 노드에 대한 전체 액세스 권한이 있다고 신뢰할 수 있는 소스에서 가져온 것인지 확인하세요.

주의

AWS ParallelCluster 파일을 통해 제공되는 내부 변수의 사용을 지원하지 않습니다. /etc/parallelcluster/cfnconfig 이 파일은 향후 릴리스에서 제거될 수 있습니다.

OnNodeStart 작업은 NAT, Amazon Elastic Block Store(Amazon EBS) 또는 스케줄러 구성과 같은 노드 배포 부트스트랩 작업이 시작되기 전에 호출됩니다. OnNodeStart 부트스트랩 작업에는 스토리지 수정, 사용자 추가, 패키지 추가 등이 포함될 수 있습니다.

참고

클러스터용 HeadNode/CustomActions/OnNodeStart스크립트를 구성하는 DirectoryService경우 스크립트를 실행하기 전에 를 AWS ParallelCluster DirectoryService 구성하고 다시 시작합니다. sssd OnNodeStart

노드 부트스트랩 프로세스가 완료된 후 OnNodeConfigured 작업이 호출됩니다. OnNodeConfigured 작업은 인스턴스가 완전히 구성되고 완료된 것으로 간주되기 전에 발생하는 마지막 작업을 수행합니다. 일부 OnNodeConfigured 작업에는 스케줄러 설정 변경, 스토리지 및 패키지 수정이 포함될 수 있습니다. 구성 중에 인수를 지정하여 인수를 스크립트에 전달할 수 있습니다.

헤드 노드 업데이트가 완료되고 스케줄러와 공유 스토리지가 최신 클러스터 구성 변경 사항에 맞게 조정된 후에 OnNodeUpdated 작업이 호출됩니다.

OnNodeStart 또는 OnNodeConfigured 사용자 지정 작업이 성공하면 종료 코드 제로(0)로 성공 여부가 표시됩니다. 다른 종료 코드는 인스턴스 부트스트랩이 실패했음을 나타냅니다.

OnNodeUpdated 사용자 지정 작업이 성공하면 종료 코드 제로(0)와 함께 성공 신호가 표시됩니다. 다른 종료 코드는 업데이트가 실패했음을 나타냅니다.

참고

OnNodeUpdated를 구성한 경우 업데이트 실패 시 수동으로 OnNodeUpdated 작업을 이전 상태로 복원해야 합니다.

OnNodeUpdated 사용자 지정 작업이 실패하면 업데이트가 이전 상태로 롤백됩니다. 하지만 OnNodeUpdated 작업은 업데이트 시에만 실행되며 스택 롤백 시에는 실행되지 않습니다.

HeadNode/CustomActionsScheduling/SlurmQueues/CustomActions 구성 섹션에서 헤드 노드와 각 대기열에 대해 서로 다른 스크립트를 지정할 수 있습니다. OnNodeUpdatedHeadNode 섹션에서만 구성할 수 있습니다.

참고

AWS ParallelCluster 버전 3.0 이전에는 헤드 노드와 컴퓨팅 노드에 다른 스크립트를 지정할 수 없었습니다. AWS ParallelCluster 2.x에서 3.x로 이동 섹션을 참조하세요.

구성

다음 구성 설정은 HeadNode/CustomActions/OnNodeStart & OnNodeConfigured & OnNodeUpdatedScheduling/CustomActions/OnNodeStart & OnNodeConfigured 작업 및 인수를 정의하는 데 사용됩니다.

HeadNode: [...] CustomActions: OnNodeStart: # Script URL. This is run before any of the bootstrap scripts are run Script: s3://bucket-name/on-node-start.sh Args: - arg1 OnNodeConfigured: # Script URL. This is run after all the bootstrap scripts are run Script: s3://bucket-name/on-node-configured.sh Args: - arg1 OnNodeUpdated: # Script URL. This is run after the head node update is completed. Script: s3://bucket-name/on-node-updated.sh Args: - arg1 # Bucket permissions Iam: S3Access: - BucketName: bucket_name EnableWriteAccess: false Scheduling: Scheduler: slurm [...] SlurmQueues: - Name: queue1 [...] CustomActions: OnNodeStart: Script: s3://bucket-name/on-node-start.sh Args: - arg1 OnNodeConfigured: Script: s3://bucket-name/on-node-configured.sh Args: - arg1 Iam: S3Access: - BucketName: bucket_name EnableWriteAccess: false

Sequence설정 사용 ( AWS ParallelCluster 버전 3.6.0에 추가됨):

HeadNode: [...] CustomActions: OnNodeStart: # Script URLs. The scripts are run in the same order as listed in the configuration, before any of the bootstrap scripts are run. Sequence: - Script: s3://bucket-name/on-node-start1.sh Args: - arg1 - Script: s3://bucket-name/on-node-start2.sh Args: - arg1 [...] OnNodeConfigured: # Script URLs. The scripts are run in the same order as listed in the configuration, after all the bootstrap scripts are run. Sequence: - Script: s3://bucket-name/on-node-configured1.sh Args: - arg1 - Script: s3://bucket-name/on-node-configured2.sh Args: - arg1 [...] OnNodeUpdated: # Script URLs. The scripts are run in the same order as listed in the configuration, after the head node update is completed. Sequence: - Script: s3://bucket-name/on-node-updated1.sh Args: - arg1 - Script: s3://bucket-name/on-node-updated2.sh Args: - arg1 [...] # Bucket permissions Iam: S3Access: - BucketName: bucket_name EnableWriteAccess: false Scheduling: Scheduler: slurm [...] SlurmQueues: - Name: queue1 [...] CustomActions: OnNodeStart: # Script URLs. The scripts are run in the same order as listed in the configuration, before any of the bootstrap scripts are run Sequence: - Script: s3://bucket-name/on-node-start1.sh Args: - arg1 - Script: s3://bucket-name/on-node-start2.sh Args: - arg1 [...] OnNodeConfigured: # Script URLs. The scripts are run in the same order as listed in the configuration, after all the bootstrap scripts are run Sequence: - Script: s3://bucket-name/on-node-configured1.sh Args: - arg1 - Script: s3://bucket-name/on-node-configured2.sh Args: - arg1 [...] Iam: S3Access: - BucketName: bucket_name EnableWriteAccess: false

Sequence 설정은 AWS ParallelCluster 버전 3.6.0부터 추가되었습니다. 지정할 Sequence 때 사용자 지정 작업에 사용할 여러 스크립트를 나열할 수 있습니다. AWS ParallelCluster 스크립트는 포함하지 않고 단일 스크립트로 사용자 정의 액션을 구성할 수 있도록 계속 지원합니다Sequence.

AWS ParallelCluster 단일 스크립트와 Sequence 동일한 사용자 지정 작업을 모두 포함하는 것은 지원하지 않습니다. 예를 들어, 다음과 같은 구성을 지정하면 AWS ParallelCluster 실패합니다.

[...] CustomActions: OnNodeStart: # Script URL. This is run before any of the bootstrap scripts are run Script: s3://bucket-name/on-node-start.sh Args: - arg1 # Script URLs. The scripts are run in the same order as listed in the configuration, before any of the bootstrap scripts are run. Sequence: - Script: s3://bucket-name/on-node-start1.sh Args: - arg1 - Script: s3://bucket-name/on-node-start2.sh Args: - arg1 [...]

인수

참고

AWS ParallelCluster 2.x에서는 인수가 사용자 지정 스크립트의 URL을 저장하기 위한 예약된 $1 인수였습니다. AWS ParallelCluster 2.x용으로 만든 사용자 지정 부트스트랩 스크립트를 AWS ParallelCluster 3.x에서 다시 사용하려면 인수의 변화를 고려하여 수정해야 합니다. AWS ParallelCluster 2.x에서 3.x로 이동 섹션을 참조하세요.

사용자 지정 부트스트랩 작업이 포함된 예제 클러스터

다음 단계는 노드를 구성한 후 실행할 간단한 스크립트를 생성하여 클러스터의 노드에 R, curlwget 패키지를 설치합니다.

  1. 스크립트를 생성합니다.

    #!/bin/bash echo "The script has $# arguments" for arg in "$@" do echo "arg: ${arg}" done yum -y install "${@:1}"
  2. 올바른 권한을 사용하여 스크립트를 Amazon S3에 업로드합니다. 공개 읽기 권한이 적절하지 않은 경우 HeadNode/Iam/S3AccessScheduling/SlurmQueues 구성 섹션을 사용하세요. 자세한 정보는 Amazon S3 작업을 참조하세요.

    $ aws s3 cp --acl public-read /path/to/myscript.sh s3://<bucket-name>/myscript.sh
    중요

    Windows에서 스크립트를 편집한 경우 스크립트를 Amazon S3에 업로드하기 전에 줄 끝을 CRLF에서 LF로 변경해야 합니다.

  3. 새 작업을 포함하도록 AWS ParallelCluster 구성을 업데이트하십시오. OnNodeConfigured

    CustomActions: OnNodeConfigured: Script: https://<bucket-name>.s3.<region>.amazonaws.com/myscript.sh Args: - "R" - "curl" - "wget"

    버킷에 public-read 권한이 없는 경우 s3을 URL 프로토콜로 사용합니다.

    CustomActions: OnNodeConfigured: Script: s3://<bucket-name>/myscript.sh Args: - "R" - "curl" - "wget"
  4. 클러스터를 시작합니다.

    $ pcluster create-cluster --cluster-name mycluster \ --region <region> --cluster-configuration config-file.yaml
  5. 출력을 확인합니다.

    • HeadNode 구성에 사용자 지정 작업을 추가한 경우 헤드 노드에 로그인하고 다음 명령을 실행하여 /var/log/cfn-init.log에 있는 cfn-init.log 파일을 확인합니다.

      $ less /var/log/cfn-init.log 2021-09-03 10:43:54,588 [DEBUG] Command run postinstall output: The script has 3 arguments arg: R arg: curl arg: wget Loaded plugins: dkms-build-requires, priorities, update-motd, upgrade-helper Package R-3.4.1-1.52.amzn1.x86_64 already installed and latest version Package curl-7.61.1-7.91.amzn1.x86_64 already installed and latest version Package wget-1.18-4.29.amzn1.x86_64 already installed and latest version Nothing to do
    • SlurmQueues 설정에 사용자 지정 작업을 추가한 경우 컴퓨팅 노드의 /var/log/cloud-init.log에 있는 cloud-init.log를 확인하세요. 이러한 로그를 보는 CloudWatch 데 사용합니다.

    Amazon CloudWatch 콘솔에서 이 두 로그를 모두 볼 수 있습니다. 자세한 정보는 Amazon CloudWatch Logs와 통합을 참조하세요.

IMDSv2의 사용자 지정 부트스트랩 스크립트 업데이트 예제

다음 예제에서는 IMDSv1에서 사용하던 사용자 지정 부트스트랩 액션 스크립트를 IMDSv2와 함께 사용할 수 있도록 업데이트합니다. IMDSv1 스크립트는 아마존 EC2 인스턴스 AMI ID 메타데이터를 검색합니다.

#!/bin/bash AMI_ID=$(curl http://169.254.169.254/latest/meta-data/ami-id) echo $AMI_ID >> /home/ami_id.txt

다음은 IMDSv2와 호환되도록 수정된 사용자 지정 부트스트랩 작업 스크립트를 보여줍니다.

#!/bin/bash AMI_ID=$(TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` \ && curl -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/ami-id) echo $AMI_ID >> /home/ami_id.txt

자세한 설명은 Linux 인스턴스를 위한 Amazon EC2 사용자 가이드인스턴스 메타데이터 검색을 참조하세요.

IMDSv1의 구성 업데이트 예제

다음은 버전 3.7.0 이상을 사용할 때 IMDSv1을 지원하는 클러스터 구성의 예입니다. AWS ParallelCluster

Region: us-east-1 Imds: ImdsSupport: v1.0 Image: Os: alinux2 HeadNode: InstanceType: t2.micro Networking: SubnetId: subnet-abcdef01234567890 Ssh KeyName: key-name CustomActions: OnNodeConfigured: Script: Script-path Scheduling: Scheduler: slurm SlurmQueues: - Name: queue1 CustomActions: OnNodeConfigured: Script: Script-path ComputeResources: - Name: t2micro Instances: - InstanceType: t2.micro MinCount: 11 Networking: SubnetIds: - subnet-abcdef01234567890