在创建集群时配置应用程序 - Amazon EMR
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

在创建集群时配置应用程序

在创建集群时,您可以使用 Amazon EMR 控制台、Amazon Command Line Interface(Amazon CLI)或 Amazon SDK 覆盖应用程序的原定设置配置。

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

配置分类因 Amazon EMR 发行版而异。有关特定发行版中可用配置分类的列表,请参阅该发行版的详细信息页面。例如,Amazon EMR 发行版 6.4.0。

在创建集群时,在控制台中提供配置

要提供配置,请导航到 Create cluster (创建集群) 页面,然后选择 Edit software settings (编辑软件设置)。然后,您可以在控制台中使用 JSON 或以阴影文本表示的简写语法直接输入配置。否则,您可以为具有 JSON Configurations 对象的文件提供一个 Amazon S3 URI。

要为实例组提供配置,请导航到 Hardware Configuration (硬件配置) 页面。在 Node type (节点类型) 表中的 Instance type (实例类型) 列,为每个实例组选择编辑应用程序 Configurations (配置)

在创建集群时使用 Amazon CLI 提供配置

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

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

aws emr create-cluster --use-default-roles --release-label emr-5.36.1 --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://my-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 提供配置

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

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") );