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

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

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

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

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

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

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

要提供配置,请导航到创建集群页面并展开软件设置。然后,您可以使用控制台中以阴影文本JSON形式演示的速记语法直接输入配置。否则,您可以为带有JSONConfigurations对象的文件提供 Amazon S3 URI。

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

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

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

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

aws emr create-cluster --use-default-roles --release-label emr-7.2.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://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

创建集群SDK时使用 Java 提供配置

以下程序摘要说明如何使用 AWS 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") );