

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# `AWSSupport-TroubleshootOpenSearchRedYellowCluster`
<a name="automation-troubleshoot-opensearch-red-yellow-cluster"></a>

 **描述** 

 `AWSSupport-TroubleshootOpenSearchRedYellowCluster`automation runbook 用于识别[红色](https://docs.aws.amazon.com//opensearch-service/latest/developerguide/handling-errors.html#handling-errors-red-cluster-status)或[黄色](https://docs.aws.amazon.com//opensearch-service/latest/developerguide/handling-errors.html#handling-errors-yellow-cluster-status)集群运行状况的原因，并指导您将集群更改回绿色。

 **如何工作？** 

 该运行手册`AWSSupport-TroubleshootOpenSearchRedYellowCluster`可帮助您排除红色或黄色群集的原因，并通过分析群集配置和资源利用率提供了解决此问题的后续步骤。

 运行手册执行以下步骤：
+  对目标域调用 [DescribeDomain](https://docs.aws.amazon.com//opensearch-service/latest/APIReference/API_DescribeDomain.html)API 以获取集群配置。
+  检查 OpenSearch 服务域是基于互联网（公共）还是基于[亚马逊虚拟私有云 (VPC) 的](https://docs.aws.amazon.com//opensearch-service/latest/developerguide/vpc.html)。
+  根据集群配置创建公共 AWS Lambda 函数或[基于 Amazon VPC](https://docs.aws.amazon.com//lambda/latest/dg/foundation-networking.html) 的函数。注意：Lambda 函数包含 APIs 对集群运行 OpenSearch 服务以确定集群为何处于红色或黄色状态的疑难解答代码。
+  删除 Lambda 函数。
+  显示已执行的检查以及解决红色或黄色群集问题的后续建议步骤。

**文档类型**

自动化

**所有者**

Amazon

**平台**

Linux、macOS、Windows

**参数**

**所需的 IAM 权限**

`AutomationAssumeRole` 参数需要执行以下操作才能成功使用运行手册。
+ `cloudformation:CreateStack`
+ `cloudformation:DescribeStacks`
+ `cloudformation:DescribeStackEvents`
+ `cloudformation:DeleteStack`
+ `lambda:CreateFunction`
+ `lambda:DeleteFunction`
+ `lambda:InvokeFunction`
+ `lambda:GetFunction`
+ `es:DescribeDomain`
+ `es:DescribeDomainConfig`
+ `ec2:DescribeSecurityGroups`
+ `ec2:DescribeSubnets`
+ `ec2:DescribeVpcs`
+ `ec2:DescribeNetworkInterfaces`
+ `ec2:CreateNetworkInterface`
+ `ec2:DeleteNetworkInterface`
+ `ec2:DescribeInstances`
+ `ec2:AttachNetworkInterface`
+ `cloudwatch:GetMetricData`
+ `iam:PassRole`

该`LambdaExecutionRole`参数需要以下操作才能成功使用运行手册：
+ `es:ESHttpGet`
+ `ec2:CreateNetworkInterface`
+ `ec2:DescribeNetworkInterfaces`
+ `ec2:DeleteNetworkInterface`

`LambdaExecutionRole`政策概述：

 以下是 Lambda 函数的执行角色（AWS Identity and Access Management (IAM) 角色）的示例，该角色向该函数授予访问本运行手册所需的 AWS 服务和资源的权限。有关更多信息，请参阅 [Lambda 执行角色](https://docs.aws.amazon.com//lambda/latest/dg/lambda-intro-execution-role.html)。

**注意**  
 只有当`ec2:DescribeNetworkInterfaces`您的 OpenSearch 服务集群[基于 Amazon VPC](https://docs.aws.amazon.com//opensearch-service/latest/developerguide/vpc.html) 时，才需要`ec2:CreateNetworkInterface`、和`ec2:DeleteNetworkInterface`，以允许 Lambda 函数创建和管理 Amazon VPC 网络接口。有关更多信息，请参阅[将出站联网连接到 Amazon VPC 和 [Lambda 执行](https://docs.aws.amazon.com//lambda/latest/dg/lambda-intro-execution-role.html)角色中的资源](https://docs.aws.amazon.com//lambda/latest/dg/configuration-vpc.html#vpc-permissions)。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "es:ESHttpGet",
            "Resource": [
                "arn:aws:es:us-east-1:111122223333:domain/domain-name/",
                "arn:aws:es:us-east-1:111122223333:domain/domain-name/_cluster/health",
                "arn:aws:es:us-east-1:111122223333:domain/domain-name/_cat/indices",
                "arn:aws:es:us-east-1:111122223333:domain/domain-name/_cat/allocation",
                "arn:aws:es:us-east-1:111122223333:domain/domain-name/_cluster/allocation/explain"
            ]
        },
        {
            "Condition": {
                "ArnLikeIfExists": {
                    "ec2:Vpc": "arn:aws:ec2:us-east-1:111122223333:vpc/vpc_id"
                }
            },
            "Action": [
                "ec2:DeleteNetworkInterface",
                "ec2:CreateNetworkInterface",
                "ec2:DescribeNetworkInterfaces",
                "ec2:UnassignPrivateIpAddresses",
                "ec2:AssignPrivateIpAddresses"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}
```

------

 **说明** 

按照这些步骤对自动化进行配置：

1. 在 AWS Systems Manager 控制台[AWSSupport-TroubleshootOpenSearchRedYellowCluster](https://console.aws.amazon.com/systems-manager/documents/AWSSupport-TroubleshootOpenSearchRedYellowCluster/description)中导航到。

1. 选择 Execute automation（执行自动化）。

1. 要输入参数，请输入以下内容：
   + **AutomationAssumeRole （可选）：**

     允许 Systems Manager Automation 代表您执行操作的 AWS Identity and Access Management (IAM) 角色的亚马逊资源名称 (ARN)。如果未指定角色，Systems Manager Automation 将使用启动此运行手册的用户的权限。
   + **LambdaExecutionRole （必填）：**

     Lambda 将用于签署对您的亚马逊服务集群的请求的 IAM 角色的 ARN。 OpenSearch 
   + **DomainName （必填）：**

     群集运行状况为红色或黄色的 OpenSearch 服务域的名称。
   + **UtilizationThreshold （可选）：**

     用于比较 CPUUtilization和 JVMMemory压力指标的利用率阈值百分比。默认值为 80。  
![\[Input parameters form for AWS Systems Manager Automation with IAM roles and domain settings.\]](http://docs.aws.amazon.com/zh_cn/systems-manager-automation-runbooks/latest/userguide/images/awssupport-troubleshoot-opensearch-red-yellow-cluster_input_paramters.png)

1. 如果您已在 S OpenSearch ervice 集群上启用了[精细访问控制](https://docs.aws.amazon.com//opensearch-service/latest/developerguide/fgac.html)，请确保将`LambdaExecutionRole`角色 arn 映射到至少具有权限的角色。`cluster_monitor`  
![\[集群 permissions section showing cluster_monitor permission granted.\]](http://docs.aws.amazon.com/zh_cn/systems-manager-automation-runbooks/latest/userguide/images/awssupport-troubleshoot-opensearch-red-yellow-cluster_permissions.png)  
![\[Backend roles interface showing an AWSIAM role for Lambda execution and options to remove or add roles.\]](http://docs.aws.amazon.com/zh_cn/systems-manager-automation-runbooks/latest/userguide/images/awssupport-troubleshoot-opensearch-red-yellow-cluster_backend_roles.png)

1. 选择执行。

1. 自动化启动。

1. 自动化运行手册执行以下步骤：
   + **GetClusterConfiguration:**

     获取 OpenSearch 服务集群配置。
   + **创建 AWSLambdaFunctionStack：**

     使用在您的账户中创建一个临时 Lambda 函数。 CloudFormation Lambda 函数用于运行服务。 OpenSearch APIs
   + **WaitForAWSLambdaFunctionStack:**

     等待 CloudFormation 堆栈完成。
   + **GetClusterMetricsFromCloudWatch:**

     获取与 Amazon CloudWatch ClusterStatus CPUUtilization、和 Pr JVMMemory ess OpenSearch ure Service 集群相关的指标及其创建日期。
   + **RunOpenSearchAPIs:**

     使用 Lambda 函数调用 OpenSearch 服务 APIs 并分析集群指标数据，以诊断红色或黄色集群状态的原因。
   + **删除 AWSLambdaFunctionStack：**

     删除您的账户中由此自动化创建的 Lambda 函数。

1. 完成后，查看“输出”部分以了解执行的详细结果。
   + **RootCause:**

     概述已确定的集群运行状况处于红色或黄色状态的原因。
   + **IssueDescription:**

     提供有关集群为何处于红色或黄色状态以及使集群恢复到绿色状态的可能步骤的详细信息。

 **参考** 

Systems Manager Automation
+ [运行此自动化（控制台）](https://console.aws.amazon.com/systems-manager/automation/execute/AWSSupport-TroubleshootOpenSearchRedYellowCluster)
+ [运行自动化](https://docs.aws.amazon.com//systems-manager/latest/userguide/automation-working-executing.html)
+ [设置自动化](https://docs.aws.amazon.com//systems-manager/latest/userguide/automation-setup.html)
+ [支持自动化工作流登录页面](https://aws.amazon.com/premiumsupport/technology/saw/)

AWS 服务文档
+ 有关更多信息，请参阅 [Amazon OpenSearch 服务疑难解答](https://docs.aws.amazon.com//opensearch-service/latest/developerguide/handling-errors.html)