設定 RES 就緒 AMIs - 研究與工程 Studio

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

設定 RES 就緒 AMIs

使用 RES-ready AMIs,您可以在自訂 AMI 上預先安裝虛擬桌面執行個體 VDIs) 的 RES AMIs 相依性。使用 RES-ready AMIs 可改善使用預先製作映像的 VDI 執行個體開機時間。使用 EC2 Image Builder,您可以將 AMIs 建置並註冊為新的軟體堆疊。如需映像建置器的詳細資訊,請參閱映像建置器使用者指南

開始之前,您必須部署最新版本的 RES

準備 IAM 角色以存取 RES 環境

若要從 EC2 Image Builder 存取 RES 環境服務,您必須建立或修改名為 RES-EC2InstanceProfileForImageBuilder 的 IAM 角色。如需有關設定 IAM 角色以在映像建置器中使用的資訊,請參閱《映像建置器使用者指南》中的 AWS Identity and Access Management (IAM)

您的角色需要:
  • 信任的關係包括 Amazon EC2 服務

  • AmazonSSMManagedInstanceCore 和 EC2InstanceProfileForImageBuilder 政策

  • 具有已部署 RES 環境之有限 DynamoDB 和 Amazon S3 存取權的自訂 RES 政策

    (此政策可以是客戶受管政策或客戶內嵌政策文件。)

信任的關係實體:

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "ec2.amazonaws.com" } "Action": "sts:AssumeRole" } ] }

RES 政策:

{ "Version": "2012-10-17", "Statement": [ { "Sid": "RESDynamoDBAccess", "Effect": "Allow", "Action": "dynamodb:GetItem", "Resource": "arn:aws:dynamodb:{AWS-Region}:{AWS-Account-ID}:table/{RES-EnvironmentName}.cluster-settings", "Condition": { "ForAllValues:StringLike": { "dynamodb:LeadingKeys": [ "global-settings.gpu_settings.*", "global-settings.package_config.*" ] } } }, { "Sid": "RESS3Access", "Effect": "Allow", "Action": "s3:GetObject", "Resource": "arn:aws:s3:::{RES-EnvironmentName}-cluster-{AWS-Region}-{AWS-Account-ID}/idea/vdc/res-ready-install-script-packages/*" } ] }

建立 EC2 Image Builder 元件

遵循《映像建置器使用者指南》中的指示,使用映像建置器主控台建立元件

輸入您的元件詳細資訊:
  1. 針對類型,選擇建置

  2. 針對映像作業系統 (OS),選擇 Linux 或 Windows。

  3. 針對元件名稱,輸入有意義的名稱,例如 research-and-engineering-studio-vdi-<operating-system>

  4. 輸入元件的版本編號,並選擇性地新增描述。

  5. 定義文件中,輸入下列定義檔案。如果您遇到任何錯誤,YAML 檔案會區分空間,而且最可能的原因。

    Linux
    # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # with the License. A copy of the License is located at # # http://www.apache.org/licenses/LICENSE-2.0 # # or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES # OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions # and limitations under the License. name: research-and-engineering-studio-vdi-linux description: An RES EC2 Image Builder component to install required RES software dependencies for Linux VDI. schemaVersion: 1.0 parameters: - AWSAccountID: type: string description: RES Environment AWS Account ID - RESEnvName: type: string description: RES Environment Name - RESEnvRegion: type: string description: RES Environment Region - RESEnvReleaseVersion: type: string description: RES Release Version phases: - name: build steps: - name: PrepareRESBootstrap action: ExecuteBash onFailure: Abort maxAttempts: 3 inputs: commands: - 'mkdir -p /root/bootstrap/logs' - 'mkdir -p /root/bootstrap/latest' - name: DownloadRESLinuxInstallPackage action: S3Download onFailure: Abort maxAttempts: 3 inputs: - source: 's3://{{ RESEnvName }}-cluster-{{ RESEnvRegion }}-{{ AWSAccountID }}/idea/vdc/res-ready-install-script-packages/linux/res_linux_install_{{ RESEnvReleaseVersion }}.tar.gz' destination: '/root/bootstrap/res_linux_install_{{ RESEnvReleaseVersion }}.tar.gz' expectedBucketOwner: '{{ AWSAccountID }}' - name: RunInstallScript action: ExecuteBash onFailure: Abort maxAttempts: 3 inputs: commands: - 'tar -xvf {{ build.DownloadRESLinuxInstallPackage.inputs[0].destination }} -C /root/bootstrap/latest' - '/bin/bash /root/bootstrap/latest/virtual-desktop-host-linux/install.sh -r {{ RESEnvRegion }} -n {{ RESEnvName }} -g NONE' - name: FirstReboot action: Reboot onFailure: Abort maxAttempts: 3 inputs: delaySeconds: 0 - name: RunInstallPostRebootScript action: ExecuteBash onFailure: Abort maxAttempts: 3 inputs: commands: - '/bin/bash /root/bootstrap/latest/virtual-desktop-host-linux/install_post_reboot.sh' - name: SecondReboot action: Reboot onFailure: Abort maxAttempts: 3 inputs: delaySeconds: 0
    Windows
    # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # with the License. A copy of the License is located at # # http://www.apache.org/licenses/LICENSE-2.0 # # or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES # OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions # and limitations under the License. name: research-and-engineering-studio-vdi-windows description: An RES EC2 Image Builder component to install required RES software dependencies for Windows VDI. schemaVersion: 1.0 parameters: - AWSAccountID: type: string description: RES Environment AWS Account ID - RESEnvName: type: string description: RES Environment Name - RESEnvRegion: type: string description: RES Environment Region - RESEnvReleaseVersion: type: string description: RES Release Version phases: - name: build steps: - name: CreateRESBootstrapFolder action: CreateFolder onFailure: Abort maxAttempts: 3 inputs: - path: 'C:\Users\Administrator\RES\Bootstrap' overwrite: true - name: DownloadRESWindowsInstallPackage action: S3Download onFailure: Abort maxAttempts: 3 inputs: - source: 's3://{{ RESEnvName }}-cluster-{{ RESEnvRegion }}-{{ AWSAccountID }}/idea/vdc/res-ready-install-script-packages/windows/res_windows_install_{{ RESEnvReleaseVersion }}.tar.gz' destination: '{{ build.CreateRESBootstrapFolder.inputs[0].path }}\res_windows_install_{{ RESEnvReleaseVersion }}.tar.gz' expectedBucketOwner: '{{ AWSAccountID }}' - name: RunInstallScript action: ExecutePowerShell onFailure: Abort maxAttempts: 3 inputs: commands: - 'cd {{ build.CreateRESBootstrapFolder.inputs[0].path }}' - 'Tar -xf res_windows_install_{{ RESEnvReleaseVersion }}.tar.gz' - 'Import-Module .\virtual-desktop-host-windows\Install.ps1' - 'Install-WindowsEC2Instance' - name: Reboot action: Reboot onFailure: Abort maxAttempts: 3 inputs: delaySeconds: 0
  6. 建立任何選用標籤,然後選擇建立元件

準備您的 EC2 Image Builder 配方

EC2 Image Builder 配方會定義基本映像,以做為建立新映像的起點,以及您新增的一組元件來自訂映像,並確認一切如預期般運作。您必須建立或修改配方,以使用必要的 RES 軟體相依性來建構目標 AMI。如需配方的詳細資訊,請參閱管理配方

RES 支援下列映像作業系統:

  • Amazon Linux 2 (x86 和 ARM64)

  • Ubuntu 22.04.3 (x86)

  • Windows 2019、2022 (x86)

Create a new recipe
  1. 在 開啟 EC2 Image Builder 主控台https://console.aws.amazon.com/imagebuilder

  2. 已儲存的資源下,選擇映像配方

  3. 選擇建立映像配方

  4. 輸入唯一的名稱和版本編號。

  5. 選擇 RES 支援的基礎映像。

  6. 執行個體組態下,如果未預先安裝 SSM 代理程式,請安裝 SSM 代理程式。在使用者資料和任何其他所需的使用者資料中輸入資訊。

  7. 對於 Linux 型配方,將 Amazon 受管aws-cli-version-2-linux建置元件新增至配方。RES 安裝指令碼使用 AWS CLI 提供 DynamoDB 叢集設定組態值的 VDI 存取權。Windows 不需要此元件。

  8. 新增為 Linux 或 Windows 環境建立的 EC2 Image Builder 元件,然後輸入任何必要的參數值。下列參數是必要的輸入:AWSAccountID、RESEnvName、RESEnvRegion 和 RESEnvReleaseVersion。

    重要

    對於 Linux 環境,您必須依先新增aws-cli-version-2-linux建置元件的順序新增這些元件。

  9. (建議) 新增 Amazon 受管simple-boot-test-<linux-or-windows>測試元件,以確認可以啟動 AMI。這是最低建議。您可以選取其他符合您需求的測試元件。

  10. 視需要完成任何選用區段,新增任何其他所需的元件,然後選擇建立配方

Modify a recipe

如果您有現有的 EC2 Image Builder 配方,您可以新增下列元件來使用它:

  1. 對於 Linux 型配方,將 Amazon 受管aws-cli-version-2-linux建置元件新增至配方。RES 安裝指令碼使用 AWS CLI 提供 DynamoDB 叢集設定組態值的 VDI 存取權。Windows 不需要此元件。

  2. 新增為 Linux 或 Windows 環境建立的 EC2 Image Builder 元件,然後輸入任何必要的參數值。下列參數是必要的輸入:AWSAccountID、RESEnvName、RESEnvRegion 和 RESEnvReleaseVersion。

    重要

    對於 Linux 環境,您必須依先新增aws-cli-version-2-linux建置元件的順序新增這些元件。

  3. 視需要完成任何選用區段,新增任何其他所需的元件,然後選擇建立配方

設定 EC2 Image Builder 基礎設施

您可以使用基礎設施組態來指定映像建置器用來建置和測試映像建置器映像的 Amazon EC2 基礎設施。若要搭配 RES 使用,您可以選擇建立新的基礎設施組態,或使用現有的基礎設施組態。

若要設定映像建置器基礎設施:
  1. 針對 IAM 角色,輸入您先前在 中設定的角色準備 IAM 角色以存取 RES 環境

  2. 針對執行個體類型,選擇至少具有 4 GB 記憶體的類型,並支援您選擇的基本 AMI 架構。請參閱 Amazon EC2 執行個體類型

  3. 對於 VPC、子網路和安全群組,您必須允許網際網路存取以下載軟體套件。還必須允許存取 RES 環境的 cluster-settings DynamoDB 資料表和 Amazon S3 叢集儲存貯體。

設定映像建置器映像管道

映像建置器映像管道會組合基礎映像、用於建置和測試的元件、基礎設施組態和分發設定。若要為 RES 就緒 AMIs 設定映像管道,您可以選擇建立新的管道,或使用現有的管道。如需詳細資訊,請參閱《映像建置器使用者指南》中的建立和更新 AMI 映像管道

Create a new Image Builder pipeline
  1. 在 開啟映像建置器主控台https://console.aws.amazon.com/imagebuilder

  2. 從導覽中,選擇映像管道

  3. 選擇建立映像管道

  4. 輸入唯一名稱、選用描述、排程和頻率來指定管道詳細資訊。

  5. 針對選擇配方,選擇使用現有配方,然後選取在 中建立的配方準備您的 EC2 Image Builder 配方。確認您的配方詳細資訊正確無誤。

  6. 針對定義映像建立程序,根據使用案例選擇預設或自訂工作流程。在大多數情況下,預設工作流程已足夠。如需詳細資訊,請參閱為 EC2 Image Builder 管道設定映像工作流程

  7. 針對定義基礎設施組態,選擇選擇現有的基礎設施組態,然後選取在 中建立的基礎設施組態設定 EC2 Image Builder 基礎設施。確認您的基礎設施詳細資訊正確無誤。

  8. 針對定義分佈設定,選擇使用服務預設值建立分佈設定。輸出映像必須位於與您的 RES 環境 AWS 區域 相同的 中。使用服務預設值時,映像會在使用映像建置器的區域中建立。

  9. 檢閱管道詳細資訊,然後選擇建立管道

Modify an existing Image Builder pipeline
  1. 若要使用現有的管道,請修改詳細資訊以使用在 中建立的配方準備您的 EC2 Image Builder 配方

  2. 選擇儲存變更

執行映像建置器映像管道

若要產生設定的輸出映像,您必須啟動映像管道。建置程序可能需要長達一小時的時間,具體取決於映像配方中的元件數量。

若要執行映像管道:
  1. 映像管道中,選取在 中建立的管道設定映像建置器映像管道

  2. 動作中,選擇執行管道

在 RES 中註冊新的軟體堆疊

  1. 遵循 中的指示軟體堆疊 (AMIs)來註冊軟體堆疊。

  2. 針對 AMI ID,輸入內建於 之輸出映像的 AMI ID執行映像建置器映像管道