

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

# 指定 Amazon EMR 托管的安全组和其它安全组
<a name="emr-sg-specify"></a>

您可以使用 AWS 管理控制台 AWS CLI、或 Amazon EMR API 指定安全组。如果您未指定安全组，Amazon EMR 会创建默认安全组。指定其它安全组是可选的。您可以为主实例、核心和任务实例和服务访问（仅私有子网）分配其它安全组。

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

**使用控制台指定安全组**

1. [登录 AWS 管理控制台，然后在 /emr 上打开亚马逊 EMR 控制台。https://console.aws.amazon.com](https://console.aws.amazon.com/emr)

1. 在左侧导航窗格中的 **EMR on EC2** 下，选择 **Clusters**（集群），然后选择 **Create cluster**（创建集群）。

1. 在 **Networking**（联网）下，选择 **EC2 security groups (firewall)** [EC2 安全组（防火墙）] 旁边的箭头以展开此部分。在 **Primary node**（主节点）和 **Core and task nodes**（核心节点和任务节点）下，默认选择 Amazon EMR 默认托管安全组。如果您使用私有子网，则还可以选择安全组进行 **Service access**（服务访问）。

1. 要更改您的 Amazon EMR 托管安全组，请使用 **Choose security groups**（选择安全组）下拉菜单以从 **Amazon EMR-managed security group**（Amazon EMR 托管安全组）选项列表中选择其他选项。您有一个 Amazon EMR 托管安全组，可用于 **Primary node**（主节点）、**Core and task nodes**（核心节点和任务节点）。

1. 要添加自定义安全组，请使用相同的 **Choose security groups**（选择安全组）下拉菜单从 **Custom security group**（自定义安全组）选项列表中选择最多四个自定义安全组。对于 **Primary node**（主节点）和 **Core and task nodes**（核心节点和任务节点），最多可以有四个自定义安全组。

1. 选择适用于集群的任何其他选项。

1. 要启动集群，选择 **Create cluster**（创建集群）。

------

## 使用指定安全组 AWS CLI
<a name="emr-sg-specify-cli"></a>

要使用指定安全组， AWS CLI 请使用带有以下`--ec2-attributes`选项参数的`create-cluster`命令：


| 参数 | 说明 | 
| --- | --- | 
|  `EmrManagedPrimarySecurityGroup`  |  使用此参数为主实例指定自定义托管安全组。如果指定此参数，还必须指定 `EmrManagedCoreSecurityGroup`。对于私有子网中的集群，还必须指定 `ServiceAccessSecurityGroup`。  | 
|  `EmrManagedCoreSecurityGroup`  |  使用此参数为核心和任务实例指定自定义托管安全组。如果指定此参数，还必须指定 `EmrManagedPrimarySecurityGroup`。对于私有子网中的集群，还必须指定 `ServiceAccessSecurityGroup`。  | 
|  `ServiceAccessSecurityGroup`  |  使用此参数为服务访问指定自定义托管安全组，这仅适用于私有子网中的集群。您指定为 `ServiceAccessSecurityGroup` 的安全组不应用于任何其它目的，还应为 Amazon EMR 保留。如果指定此参数，还必须指定 `EmrManagedPrimarySecurityGroup`。  | 
|  `AdditionalPrimarySecurityGroups`  |  使用此参数最多为主实例指定四个其它安全组。  | 
|  `AdditionalCoreSecurityGroups`  |  使用此参数最多为核心和任务实例指定四个其它安全组。  | 

**Example ：指定自定义 Amazon EMR 托管的安全组和其它安全组**  
以下示例为私有子网中的集群、主实例的多个其它安全组以及核心和任务实例的单个其它安全组指定自定义 Amazon EMR 托管式安全组。  
为了便于读取，包含 Linux 行继续符（\$1）。它们可以通过 Linux 命令删除或使用。对于 Windows，请将它们删除或替换为脱字号（^）。

```
 1. aws emr create-cluster --name "ClusterCustomManagedAndAdditionalSGs" \
 2. --release-label emr-emr-7.12.0 --applications Name=Hue Name=Hive \
 3. Name=Pig --use-default-roles --ec2-attributes \
 4. SubnetIds=subnet-xxxxxxxxxxxx,KeyName=myKey,\
 5. ServiceAccessSecurityGroup=sg-xxxxxxxxxxxx,\
 6. EmrManagedPrimarySecurityGroup=sg-xxxxxxxxxxxx,\
 7. EmrManagedCoreSecurityGroup=sg-xxxxxxxxxxx,\
 8. AdditionalPrimarySecurityGroups=['sg-xxxxxxxxxxx',\
 9. 'sg-xxxxxxxxxxx','sg-xxxxxxxxxx'],\
10. AdditionalCoreSecurityGroups=sg-xxxxxxxxxxx \
11. --instance-type m5.xlarge
```

有关更多信息，请参阅《AWS CLI 命令参考》**中的 [create-cluster](https://docs.aws.amazon.com/cli/latest/reference/emr/create-cluster.html)。