

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

# 在创建集群时配置应用程序
<a name="emr-configure-apps-create-cluster"></a>

创建集群时，您可以使用 Amazon EMR 控制台、 Amazon Command Line Interface (Amazon CLI) 或软件开发工具包覆盖应用程序的默认配置。 Amazon 

要覆盖应用程序的原定设置配置，您需要指定某个配置分类中的自定义值。配置分类对应于应用程序的配置 XML 文件，例如 `hive-site.xml`。

配置分类因 Amazon EMR 发行版而异。有关特定发行版中可用配置分类的列表，请参阅该发行版的详细信息页面。例如，[Amazon EMR 发行版 6.4.0。](emr-640-release.md#emr-640-class)

## 在创建集群时，在控制台中提供配置
<a name="emr-configure-apps-create-cluster-console"></a>

要提供配置，请导航到**创建集群**页面并展开**软件设置**。然后，您可以在控制台中使用 JSON 或以阴影文本表示的简写语法直接输入配置。否则，您可以为具有 JSON `Configurations` 对象的文件提供一个 Amazon S3 URI。

要为实例组提供配置，请在集群列表中选择一个集群，然后选择**配置**选项卡。在**实例组配置**表中，选择要编辑的实例组，然后选择**重新配置**。

## 创建集群 Amazon CLI 时使用提供配置
<a name="emr-configure-apps-create-cluster-cli"></a>

您可通过提供本地存储或在 Amazon S3 中存储的 JSON 文件的路径来为 **create-cluster** 提供配置。以下示例假定您使用 Amazon EMR 的默认角色，并且已创建这些角色。如果您需要创建角色，请先运行 `aws emr create-default-roles`。

如果您的配置位于本地目录中，您可以使用示例命令。

```
aws emr create-cluster --use-default-roles --release-label emr-7.12.0 --applications Name=Hive \
--instance-type m5.xlarge --instance-count 3 --configurations file://./configurations.json
```

如果您的配置位于 Amazon S3 路径中，则需要设置以下解决方法，然后才能将 Amazon S3 路径传递给 `create-cluster` 命令。

```
#!/bin/sh
# Assume the ConfigurationS3Path is not public, and its present in the same AWS account as the EMR cluster
ConfigurationS3Path="s3://amzn-s3-demo-bucket/config.json"
# Get a presigned HTTP URL for the s3Path
ConfigurationURL=`aws s3 presign $ConfigurationS3Path --expires-in 300`
# Fetch the presigned URL, and minify the JSON so that it spans only a single line
Configurations=`curl $ConfigurationURL | jq -c .`
aws emr create-cluster --use-default-roles --release-label emr-5.34.0 --instance-type m5.xlarge --instance-count 2 --applications Name=Hadoop Name=Spark --configurations $Configurations
```

## 在创建集群时，使用 Java SDK 提供配置
<a name="emr-configure-apps-create-cluster-sdk"></a>

以下程序摘要说明如何使用 适用于 Java 的 Amazon SDK提供配置。

```
Application hive = new Application().withName("Hive");

Map<String,String> hiveProperties = new HashMap<String,String>();
	hiveProperties.put("hive.join.emit.interval","1000");
	hiveProperties.put("hive.merge.mapfiles","true");
	    
Configuration myHiveConfig = new Configuration()
	.withClassification("hive-site")
	.withProperties(hiveProperties);

RunJobFlowRequest request = new RunJobFlowRequest()
	.withName("Create cluster with ReleaseLabel")
	.withReleaseLabel("emr-5.20.0")
	.withApplications(hive)
	.withConfigurations(myHiveConfig)
	.withServiceRole("EMR_DefaultRole")
	.withJobFlowRole("EMR_EC2_DefaultRole")
	.withInstances(new JobFlowInstancesConfig()
		.withEc2KeyName("myEc2Key")
		.withInstanceCount(3)
		.withKeepJobFlowAliveWhenNoSteps(true)
		.withMasterInstanceType("m4.large")
		.withSlaveInstanceType("m4.large")
	);
```