

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

# 更新 Network Load Balancer 的目標群組運作狀態設定
<a name="modify-target-group-health-settings"></a>

根據預設，Network Load Balancer 會監控目標的運作狀態，並將請求路由至運作狀態良好的目標。不過，如果負載平衡器沒有足夠的運作狀態良好的目標，它會自動將流量傳送至所有已註冊的目標 （失敗開啟）。您可以修改目標群組的目標群組運作狀態設定，以定義 DNS 容錯移轉和路由容錯移轉的閾值。如需詳細資訊，請參閱[目標群組運作狀態](load-balancer-target-groups.md#target-group-health)。

------
#### [ Console ]

**更新目標群組運作狀態設定**

1. 前往 [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/) 開啟 Amazon EC2 主控台。

1. 在導覽窗格的**負載平衡**中，選擇**目標群組**。

1. 選擇目標群組的名稱，以開啟其詳細資訊頁面。

1. 在**屬性**索引標籤中，選擇**編輯**。

1. 展開**目標群組運作狀況需求**。

1. 對於**組態類型**，我們建議您選擇**統一組態**，這會為 DNS 容錯移轉和路由容錯移轉設定相同的閾值。

1. 對於**狀態良好的狀態要求**，請執行下列其中一項：
   + 選擇**最小運作狀況目標計數**，然後輸入從 1 到目標群組目標數目上限的數字。
   + 選擇**最小狀態良好目標百分比**，然後輸入 1 到 100 之間的數字。

1. 資訊文字指出是否為目標群組啟用跨區域負載平衡。如果停用跨區域負載平衡，您可以啟用它，以確保您有足夠的容量。在**目標選取組態**下，更新**跨區域負載平衡**。

   下列文字表示已停用跨區域負載平衡：

   ```
   Healthy state requirements apply to each zone independently.
   ```

   下列文字表示已啟用跨區域負載平衡：

   ```
   Healthy state requirements apply to the total targets across all applicable zones.
   ```

1. 選擇**儲存變更**。

------
#### [ AWS CLI ]

**更新目標群組運作狀態設定**  
使用 [modify-target-group-attributes](https://docs.aws.amazon.com/cli/latest/reference/elbv2/modify-target-group-attributes.html) 指令。下列範例會將兩個運作狀態不佳的動作的運作狀態良好閾值設定為 50%。

```
aws elbv2 modify-target-group-attributes \
    --target-group-arn target-group-arn \
    --attributes \
      "Key=target_group_health.dns_failover.minimum_healthy_targets.percentage,Value=50" \
      "Key=target_group_health.unhealthy_state_routing.minimum_healthy_targets.percentage,Value=50"
```

------
#### [ CloudFormation ]

**修改目標群組運作狀態設定**  
更新 [AWS::ElasticLoadBalancingV2::TargetGroup](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-elasticloadbalancingv2-targetgroup.html) 資源。下列範例會將兩個運作狀態不佳的動作的運作狀態良好閾值設定為 50%。

```
Resources:
  myTargetGroup:
    Type: 'AWS::ElasticLoadBalancingV2::TargetGroup'
    Properties:
      Name: my-target-group
      Protocol: TCP
      Port: 80
      TargetType: ip
      VpcId: !Ref myVPC
      TargetGroupAttributes: 
        - Key: "target_group_health.dns_failover.minimum_healthy_targets.percentage"
          Value: "50"
        - Key: "target_group_health.unhealthy_state_routing.minimum_healthy_targets.percentage"
          Value: "50"
```

------