View a markdown version of this page

手動選擇執行個體類型以建立混合執行個體群組 - Amazon EC2 Auto Scaling

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

手動選擇執行個體類型以建立混合執行個體群組

本主題示範如何透過手動選擇執行個體類型在單一 Auto Scaling 群組中啟動多個執行個體類型。

若您偏好以執行個體屬性作為選取執行個體類型的條件,請參閱 使用屬性型執行個體類型選取項目建立混合執行個體群組。

先決條件

建立混合執行個體群組 (主控台)

請使用下列程序,透過手動選擇您的群組可以啟動的執行個體類型來建立混合執行個體群組。為了協助您有效率地完成這些步驟,我們會略過某些選用的區段。

若要檢閱混合執行個體群組的最佳實務,請參閱 建立混合執行個體群組的設定概觀。

建立混合執行個體群組
  1. 前往網址 https://console.aws.amazon.com/ec2/ 開啟 Amazon EC2 主控台,然後從導覽窗格中選擇 Auto Scaling 群組。

  2. 在畫面上方的導覽列中,選擇您用來建立啟動範本的相同 AWS 區域 。

  3. 選擇建立 Auto Scaling 群組。

  4. 在選擇啟動範本或組態頁面上,針對Auto Scaling 群組名稱,請輸入 Auto Scaling 群組的名稱。

  5. 若要選擇您的啟動範本,請執行以下操作:

    1. 針對啟動範本,選擇現有的啟動範本。

    2. 針對啟動範本版本,選擇 Auto Scaling 群組擴增時使用啟動範本的預設、最新或特定版本。

    3. 確認您的啟動範本支援您打算使用的所有選項,然後選擇下一步。

  6. 在選擇執行個體啟動選項頁面中,執行以下操作:

    1. 對於 Instance type requirements (執行個體類型需求),選擇 Override launch template (覆寫啟動範本),然後選擇 Manually add instance types (手動新增執行個體類型)。

    2. 選擇您的執行個體類型。您可以使用我們的建議作為起點。依預設選取系列和層代靈活。

      • 若要變更執行個體類型的順序,請使用箭頭。如果您選擇支援優先順序的分配策略,則執行個體類型順序會設定其啟動優先順序。

      • 若要移除執行個體類型,請選擇 X。

      • (選用) 對於權重欄中的方塊,為每個執行個體類型指定相對權重。若要這麼做,請輸入該類型的執行個體計入群組所需容量的單位數。如果執行個體類型提供不同的 vCPU、記憶體、儲存或網路頻寬功能,則這麼做可能會很實用。如需詳細資訊,請參閱設定 Auto Scaling 群組以使用執行個體權重。

        注意,如果您選擇使用大小靈活建議,則屬於本部分的所有執行個體類型都會自動具有權重值。如果您不想指定任何權重,則請清除所有執行個體類型的 Weight (權重) 欄中的方塊。

    3. 在 Instance purchase options (執行個體購買選項) 下,針對Instances distribution (執行個體分佈),分別指定群組要以隨需執行個體和 Spot 執行個體啟動的百分比。如果您的應用程式無狀態、可容錯並且可以處理被中斷的執行個體,則您可以指定較高的 Spot 執行個體百分比。

    4. (選用) 當您指定 Spot 執行個體的百分比時,您可以勾選包含隨需基本容量旁的核取方塊,然後指定 Auto Scaling 群組初始容量中應以隨需執行個體履行的數量下限。超過基本容量的項目會使用執行個體分佈設定來決定啟動多少隨需執行個體和 Spot 執行個體。

    5. 在 Allocation strategies (分配策略) 下,對於 On-Demand allocation strategy (隨需分配策略),請選擇分配策略。手動選擇執行個體類型時,依預設會選取 Prioritized (按優先順序排序)。

    6. 對於 Spot allocation strategy (Spot 分配策略),選擇分配策略。依預設會選取最佳化的價格容量。

      如果您選擇容量最佳化,則可以選擇性地勾選排定執行個體類型優先順序方塊,讓 Amazon EC2 Auto Scaling 根據執行個體類型的列出順序,選擇要先啟動的執行個體類型。

    7. 對於容量重新平衡,請選擇啟用或停用容量重新平衡。當 Spot 執行個體因 Spot 中斷而即將終止時,可使用容量重新平衡來自動回應。如需詳細資訊,請參閱Auto Scaling 中的容量重新平衡,以取代具有風險的 Spot 執行個體。

    8. 在 Network (網路) 下,對於 VPC,選擇 VPC。Auto Scaling 群組必須與您在啟動範本中指定的安全群組建立在同一個 VPC 中。

    9. 對於可用區域和子網路,請選擇指定 VPC 中的一個或多個子網路。在多個可用區域中,請使用子網路,以獲得高可用性。如需詳細資訊,請參閱選擇 VPC 子網路時的注意事項。

    10. 選擇下一步、下一步。

  7. 針對設定群組大小和擴展政策步驟,請執行以下操作:

    1. 對於所需容量,在群組大小下輸入要啟動之執行個體的初始數量。

      依預設,所需容量表示為執行個體數量。如果您為執行個體類型指派權重,則必須將該值轉換為與指派權重相同的測量單位,例如 vCPU 數量。

    2. 在擴展區段的擴展限制下,如果所需容量的新值大於所需容量下限和所需容量上限,則所需容量上限會自動增加到新的所需容量值。您可視需要變更這些限制。如需詳細資訊,請參閱設定 Auto Scaling 群組的擴展限制。

  8. 選擇 Skip to review (跳過以進行檢閱)。

  9. 在 Review (檢閱) 頁面上,選擇 Create Auto Scaling group (建立 Auto Scaling 群組)。

建立混合執行個體群組 (AWS CLI)

使用命令列建立混合執行個體群組

請使用以下其中一個命令:

範例組態

下列範例組態示範如何使用不同 Spot 分配策略建立混合執行個體群組。

注意

這些範例展示如何使用 JSON 或 YAML 格式組態檔案。如果您使用 AWS CLI 版本 1,則必須指定 JSON 格式的組態檔案。如果您使用 AWS CLI 版本 2,您可以指定 YAML 或 JSON 格式的組態檔案。

範例 1:使用 capacity-optimized 配置策略啟動 Spot 執行個體

下列 create-auto-scaling-group 命令會建立 Auto Scaling 群組,其會指定下列項目:

  • 要啟動多少百分比的群組來做為隨需執行個體 (0),以及隨需執行個體要開始的基本數量 (1)。

  • 按照優先順序啟動的執行個體類型 (c5.large、c5a.large、m5.large、m5a.large、c4.large、m4.large、c3.large、m3.large)。

  • 在其中啟動執行個體的子網路 (subnet-5ea0c127、subnet-6194ea3b、subnet-c934b782)。每個對應於不同的可用區域。

  • 啟動範本 (my-launch-template) 和啟動範本的版本 ($Default)。

Amazon EC2 Auto Scaling 在嘗試滿足您的隨需容量時,會先啟動 c5.large 執行個體類型。Spot 執行個體根據 Spot 執行個體容量,來自於每個可用區域的最佳 Spot 集區。

aws autoscaling create-auto-scaling-group --cli-input-json file://~/config.json

config.json 檔案包含下列內容。

{ "AutoScalingGroupName": "my-asg", "MixedInstancesPolicy": { "LaunchTemplate": { "LaunchTemplateSpecification": { "LaunchTemplateName": "my-launch-template", "Version": "$Default" }, "Overrides": [ { "InstanceType": "c5.large" }, { "InstanceType": "c5a.large" }, { "InstanceType": "m5.large" }, { "InstanceType": "m5a.large" }, { "InstanceType": "c4.large" }, { "InstanceType": "m4.large" }, { "InstanceType": "c3.large" }, { "InstanceType": "m3.large" } ] }, "InstancesDistribution": { "OnDemandBaseCapacity": 1, "OnDemandPercentageAboveBaseCapacity": 0, "SpotAllocationStrategy": "capacity-optimized" } }, "MinSize": 1, "MaxSize": 5, "DesiredCapacity": 3, "VPCZoneIdentifier": "subnet-5ea0c127,subnet-6194ea3b,subnet-c934b782" }

或者,您可使用以下 create-auto-scaling-group 命令建立 Auto Scaling 群組。這將參考 YAML 檔案作為 Auto Scaling 群組的唯一參數。

aws autoscaling create-auto-scaling-group --cli-input-yaml file://~/config.yaml

config.yaml 檔案包含下列內容。

--- AutoScalingGroupName: my-asg MixedInstancesPolicy: LaunchTemplate: LaunchTemplateSpecification: LaunchTemplateName: my-launch-template Version: $Default Overrides: - InstanceType: c5.large - InstanceType: c5a.large - InstanceType: m5.large - InstanceType: m5a.large - InstanceType: c4.large - InstanceType: m4.large - InstanceType: c3.large - InstanceType: m3.large InstancesDistribution: OnDemandBaseCapacity: 1 OnDemandPercentageAboveBaseCapacity: 0 SpotAllocationStrategy: capacity-optimized MinSize: 1 MaxSize: 5 DesiredCapacity: 3 VPCZoneIdentifier: subnet-5ea0c127,subnet-6194ea3b,subnet-c934b782

範例 2:使用 capacity-optimized-prioritized 配置策略啟動 Spot 執行個體

下列 create-auto-scaling-group 命令會建立 Auto Scaling 群組,其會指定下列項目:

  • 要啟動多少百分比的群組來做為隨需執行個體 (0),以及隨需執行個體要開始的基本數量 (1)。

  • 按照優先順序啟動的執行個體類型 (c5.large、c5a.large、m5.large、m5a.large、c4.large、m4.large、c3.large、m3.large)。

  • 在其中啟動執行個體的子網路 (subnet-5ea0c127、subnet-6194ea3b、subnet-c934b782)。每個對應於不同的可用區域。

  • 啟動範本 (my-launch-template) 和啟動範本的版本 ($Latest)。

Amazon EC2 Auto Scaling 在嘗試滿足您的隨需容量時,會先啟動 c5.large 執行個體類型。Amazon EC2 Auto Scaling 在嘗試滿足 Spot 容量時,會竭盡全力遵循執行個體類型優先順序。不過,它會先針對容量進行最佳化。

aws autoscaling create-auto-scaling-group --cli-input-json file://~/config.json

config.json 檔案包含下列內容。

{ "AutoScalingGroupName": "my-asg", "MixedInstancesPolicy": { "LaunchTemplate": { "LaunchTemplateSpecification": { "LaunchTemplateName": "my-launch-template", "Version": "$Latest" }, "Overrides": [ { "InstanceType": "c5.large" }, { "InstanceType": "c5a.large" }, { "InstanceType": "m5.large" }, { "InstanceType": "m5a.large" }, { "InstanceType": "c4.large" }, { "InstanceType": "m4.large" }, { "InstanceType": "c3.large" }, { "InstanceType": "m3.large" } ] }, "InstancesDistribution": { "OnDemandBaseCapacity": 1, "OnDemandPercentageAboveBaseCapacity": 0, "SpotAllocationStrategy": "capacity-optimized-prioritized" } }, "MinSize": 1, "MaxSize": 5, "DesiredCapacity": 3, "VPCZoneIdentifier": "subnet-5ea0c127,subnet-6194ea3b,subnet-c934b782" }

或者,您可使用以下 create-auto-scaling-group 命令建立 Auto Scaling 群組。這將參考 YAML 檔案作為 Auto Scaling 群組的唯一參數。

aws autoscaling create-auto-scaling-group --cli-input-yaml file://~/config.yaml

config.yaml 檔案包含下列內容。

--- AutoScalingGroupName: my-asg MixedInstancesPolicy: LaunchTemplate: LaunchTemplateSpecification: LaunchTemplateName: my-launch-template Version: $Default Overrides: - InstanceType: c5.large - InstanceType: c5a.large - InstanceType: m5.large - InstanceType: m5a.large - InstanceType: c4.large - InstanceType: m4.large - InstanceType: c3.large - InstanceType: m3.large InstancesDistribution: OnDemandBaseCapacity: 1 OnDemandPercentageAboveBaseCapacity: 0 SpotAllocationStrategy: capacity-optimized-prioritized MinSize: 1 MaxSize: 5 DesiredCapacity: 3 VPCZoneIdentifier: subnet-5ea0c127,subnet-6194ea3b,subnet-c934b782

範例 3:使用分散在兩個集區的 lowest-price 配置策略啟動 Spot 執行個體

下列 create-auto-scaling-group 命令會建立 Auto Scaling 群組,其會指定下列項目:

  • 要以隨需執行個體形式啟動的群組百分比 (50)。(這不會指定開始的隨需執行個體的基本數目。)

  • 按照優先順序啟動的執行個體類型 (c5.large、c5a.large、m5.large、m5a.large、c4.large、m4.large、c3.large、m3.large)。

  • 在其中啟動執行個體的子網路 (subnet-5ea0c127、subnet-6194ea3b、subnet-c934b782)。每個對應於不同的可用區域。

  • 啟動範本 (my-launch-template) 和啟動範本的版本 ($Latest)。

Amazon EC2 Auto Scaling 在嘗試滿足您的隨需容量時,會先啟動 c5.large 執行個體類型。就 Spot 容量而言,Amazon EC2 Auto Scaling 嘗試在各可用區域的兩個最低價格的集區中平均啟動 Spot 執行個體。

aws autoscaling create-auto-scaling-group --cli-input-json file://~/config.json

config.json 檔案包含下列內容。

{ "AutoScalingGroupName": "my-asg", "MixedInstancesPolicy": { "LaunchTemplate": { "LaunchTemplateSpecification": { "LaunchTemplateName": "my-launch-template", "Version": "$Latest" }, "Overrides": [ { "InstanceType": "c5.large" }, { "InstanceType": "c5a.large" }, { "InstanceType": "m5.large" }, { "InstanceType": "m5a.large" }, { "InstanceType": "c4.large" }, { "InstanceType": "m4.large" }, { "InstanceType": "c3.large" }, { "InstanceType": "m3.large" } ] }, "InstancesDistribution": { "OnDemandPercentageAboveBaseCapacity": 50, "SpotAllocationStrategy": "lowest-price", "SpotInstancePools": 2 } }, "MinSize": 1, "MaxSize": 5, "DesiredCapacity": 3, "VPCZoneIdentifier": "subnet-5ea0c127,subnet-6194ea3b,subnet-c934b782" }

或者,您可使用以下 create-auto-scaling-group 命令建立 Auto Scaling 群組。這將參考 YAML 檔案作為 Auto Scaling 群組的唯一參數。

aws autoscaling create-auto-scaling-group --cli-input-yaml file://~/config.yaml

config.yaml 檔案包含下列內容。

--- AutoScalingGroupName: my-asg MixedInstancesPolicy: LaunchTemplate: LaunchTemplateSpecification: LaunchTemplateName: my-launch-template Version: $Default Overrides: - InstanceType: c5.large - InstanceType: c5a.large - InstanceType: m5.large - InstanceType: m5a.large - InstanceType: c4.large - InstanceType: m4.large - InstanceType: c3.large - InstanceType: m3.large InstancesDistribution: OnDemandPercentageAboveBaseCapacity: 50 SpotAllocationStrategy: lowest-price SpotInstancePools: 2 MinSize: 1 MaxSize: 5 DesiredCapacity: 3 VPCZoneIdentifier: subnet-5ea0c127,subnet-6194ea3b,subnet-c934b782

範例 4:使用 price-capacity-optimized 分配策略啟動 競價型執行個體

下列 create-auto-scaling-group 命令會建立 Auto Scaling 群組,其會指定下列項目:

  • 要以隨需執行個體形式啟動的群組百分比 (30)。(這不會指定開始的隨需執行個體的基本數目。)

  • 按照優先順序啟動的執行個體類型 (c5.large、c5a.large、m5.large、m5a.large、c4.large、m4.large、c3.large、m3.large)。

  • 在其中啟動執行個體的子網路 (subnet-5ea0c127、subnet-6194ea3b、subnet-c934b782)。每個對應於不同的可用區域。

  • 啟動範本 (my-launch-template) 和啟動範本的版本 ($Latest)。

Amazon EC2 Auto Scaling 在嘗試滿足您的隨需容量時,會先啟動 c5.large 執行個體類型。對於 Spot 容量,Amazon EC2 Auto Scaling 嘗試從 Spot 執行個體集區以可能的最低價格啟動 Spot 執行個體,但同時也具有正啟動的執行個體數量的最佳容量。

aws autoscaling create-auto-scaling-group --cli-input-json file://~/config.json

config.json 檔案包含下列內容。

{ "AutoScalingGroupName": "my-asg", "MixedInstancesPolicy": { "LaunchTemplate": { "LaunchTemplateSpecification": { "LaunchTemplateName": "my-launch-template", "Version": "$Latest" }, "Overrides": [ { "InstanceType": "c5.large" }, { "InstanceType": "c5a.large" }, { "InstanceType": "m5.large" }, { "InstanceType": "m5a.large" }, { "InstanceType": "c4.large" }, { "InstanceType": "m4.large" }, { "InstanceType": "c3.large" }, { "InstanceType": "m3.large" } ] }, "InstancesDistribution": { "OnDemandPercentageAboveBaseCapacity": 30, "SpotAllocationStrategy": "price-capacity-optimized" } }, "MinSize": 1, "MaxSize": 5, "DesiredCapacity": 3, "VPCZoneIdentifier": "subnet-5ea0c127,subnet-6194ea3b,subnet-c934b782" }

或者,您可使用以下 create-auto-scaling-group 命令建立 Auto Scaling 群組。這將參考 YAML 檔案作為 Auto Scaling 群組的唯一參數。

aws autoscaling create-auto-scaling-group --cli-input-yaml file://~/config.yaml

config.yaml 檔案包含下列內容。

--- AutoScalingGroupName: my-asg MixedInstancesPolicy: LaunchTemplate: LaunchTemplateSpecification: LaunchTemplateName: my-launch-template Version: $Default Overrides: - InstanceType: c5.large - InstanceType: c5a.large - InstanceType: m5.large - InstanceType: m5a.large - InstanceType: c4.large - InstanceType: m4.large - InstanceType: c3.large - InstanceType: m3.large InstancesDistribution: OnDemandPercentageAboveBaseCapacity: 30 SpotAllocationStrategy: price-capacity-optimized MinSize: 1 MaxSize: 5 DesiredCapacity: 3 VPCZoneIdentifier: subnet-5ea0c127,subnet-6194ea3b,subnet-c934b782