Get Hands-on with Amazon EKS - Workshop Event Series
Whether you're taking your first steps with Kubernetes or you're an experienced practitioner looking to sharpen your skills, our Amazon EKS workshop series delivers practical, real-world experience that moves you forward. Learn directly from AWS solutions architects and EKS specialists through hands-on sessions designed to build your confidence with Kubernetes. Register now and start building with Amazon EKS!
如何在受管運算環境中將現有的 Amazon FSx for Lustre 檔案系統掛接到 AWS Batch?
我想要在受管運算環境中將現有的 Amazon FSx for Lustre 檔案系統掛接到 AWS Batch。
簡短描述
將 Amazon Elastic Compute Cloud (Amazon EC2) 啟動範本與 AWS Batch 搭配使用。此組態將現有的 Amazon FSx for Lustre 檔案系統掛接到您的容器上,而無需建立自訂 Amazon Machine Image (AMI)。
**重要:**建立檔案系統時,請使用指派給運算環境的相同 Amazon Virtual Private Cloud (Amazon VPC) 和子網路。
解決方法
**注意:**如果您在執行 AWS Command Line Interface (AWS CLI) 命令時收到錯誤,請參閱AWS CLI 錯誤疑難排解。此外,請確定您使用的是最新的 AWS CLI 版本。
要在受管運算環境中將現有的 Amazon FSx for Lustre 檔案系統掛接到 AWS Batch,請完成下列步驟:
-
建立一個 Amazon FSx for Lustre 檔案系統。然後,選擇持久性或暫存檔案系統部署類型。
**注意:**對於長期儲存和工作負載,請使用持久性檔案系統。對於暫時儲存和短期資料處理,請使用暫存檔案系統。 -
複製您的檔案系統 ID (例如,fs-0123456789abcdef0)。您必須具有檔案系統 ID 才能執行啟動範本。
-
建立啟動範本,其中包含使用者資料區段,並使用 MIME 分段檔案格式。如需詳細資訊,請參閱 Cloud-init 網站上的 Mime 分段封存。
請參閱下列 Amazon Linux 2 MIME 多段檔案範例。使用您的檔案系統 ID 取代 fs-0123456789abcdef0,使用您的 AWS 區域取代 us-east-1,並使用八個字元的 Amazon FSx 掛接名稱 xxxxxxxx:Content-Type: multipart/mixed; boundary="==MYBOUNDARY==" MIME-Version: 1.0 --==MYBOUNDARY== Content-Type: text/cloud-boothook; charset="us-ascii" file_system_id=fs-0123456789abcdef0 region=us-east-1 fsx_directory=/scratch fsx_mount_name=xxxxxxxx amazon-linux-extras install -y lustre2.10 mkdir -p ${fsx_directory} mount -t lustre -o noatime,flock ${file_system_id}.fsx.${region}.amazonaws.com@tcp:/${fsx_mount_name} ${fsx_directory} --==MYBOUNDARY==--**注意:**此範例 MIME 分段檔案將運算資源設定為安裝 Extras 程式庫中的 Lustre 2.10 套件。此檔案還會在 /scratch 掛接現有 Amazon FSx for Lustre 檔案系統。如需其他 Linux 發行版的安裝說明,請參閱安裝 Lustre 用戶端。
-
啟動範本以調用使用者資料,如下列 Amazon Linux 2 範例所示:
{ "LaunchTemplateName": "user-data", "LaunchTemplateData": { "UserData": "TUlNRS1W...<base64 encoded userdata>..." } }**注意:**如果您將使用者資料新增至 Amazon EC2 主控台中的啟動範本,請確定執行下列其中一項作業:將使用者資料以純文字貼上,或從檔案上傳使用者資料。如果您使用 AWS CLI 或 AWS SDK,則必須先對使用者資料進行 base64 編碼。如需詳細資訊,請參閱在 base64encode 網站上進行 base64 格式編碼。然後,在呼叫 CreateLaunchTemplate 時,將該字串提交為 UserData 參數的值。
-
建立名為 mount-fsx-lustre.json 的檔案。
**注意:**根據您的使用情況調整磁碟區大小。 -
執行 create-launch-template AWS CLI 命令,以根據您在步驟 5 中建立的 mount-fsx-lustre.json 檔案建立啟動範本:將 us-east-1 取代為您的區域:
aws ec2 --region us-east-1 create-launch-template --cli-input-json file://mount-fsx-lustre.json範例輸出:
{ "LaunchTemplate": { "LaunchTemplateId": "lt-08cb09d54bcf551f3", "LaunchTemplateName": "fsx-test", "CreateTime": "2020-06-30T17:13:22.000Z", "CreatedBy": "arn:aws:iam::12345678999:user/test", "DefaultVersionNumber": 1, "LatestVersionNumber": 1 } } -
建立新的運算環境,並將該環境與您的啟動範本建立關聯。當 AWS Batch 啟動執行個體時,Amazon FSx for Lustre 檔案系統現在將掛接到容器執行個體上。
**重要:**預設情況下,AWS Batch 受管運算環境會使用適用於運算資源的已核准 Amazon Elastic Container Service (Amazon ECS) 最佳化 AMI 版本。您必須明確為 Amazon ECS 最佳化的 Amazon Linux 2 AMI 及其他 Linux 發行版設定 AMI ID。 -
使用 SSH 連接至由 AWS Batch 啟動的執行個體,檢查檔案系統是否隨著容器執行個體一起掛接。然後,執行下列 df 命令:
$ df -h範例輸出:
Filesystem Size Used Avail Used% Mounted ondevtmpfs 3.9G 0 3.9G 0% /dev tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs 3.9G 448K 3.9G 1% /run tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/xvda1 30G 4.2G 25G 15% / 172.31.79.79@tcp:/xxxxxxxx 1.1T 4.5M 1.1T 1% /scratch tmpfs 798M 0 798M 0% /run/user/1000注意:****/scratch 會自動掛接。
-
在 AWS Batch 中建立任務定義,其中包含磁碟區和掛接點。
{ "jobDefinitionName": "Fsx-sample", "jobDefinitionArn": "arn:aws:batch:us-east-1:12345678999:job-definition/userdata:1", "revision": 1, "status": "ACTIVE", "type": "container", "parameters": {}, "containerProperties": { "image": "busybox", "vcpus": 1, "memory": 1024, "command": [], "volumes": [ { "host": { "sourcePath": "/scratch" }, "name": "Scratch" } ], "environment": [], "mountPoints": [ { "containerPath": "/scratch", "sourceVolume": "Scratch" } ], "ulimits": [], "resourceRequirements": [] } } -
使用在步驟 9 中建立的任務定義以提交 AWS Batch 任務。
