在建立叢集時設定應用程式 - Amazon EMR

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

在建立叢集時設定應用程式

建立叢集時,您可以使用 Amazon EMR 主控台、 AWS Command Line Interface (AWS CLI) 或 AWS SDK 覆寫應用程式的預設組態。

若要覆寫應用程式的預設組態,請在組態分類中指定自訂值。組態分類會對應至應用程式的組態 XML 檔案,例如 hive-site.xml

組態分類隨 Amazon EMR 發行版本而有所不同。如需特定發行版本中可用的組態分類清單,請參閱版本詳細資訊頁面。例如,Amazon EMR 6.4.0 版

在建立叢集時於主控台中提供組態

若要提供組態,請瀏覽至 [建立叢集] 頁面,然後展開 [軟體設定]。接著,您可以使用 JSON 或陰影文字中示範的速記語法,直接在主控台中輸入組態。否則,您可以使用 JSON Configurations 物件來提供檔案的 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.1.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

在建立叢集時使用 Java SDK 提供組態

下列程式摘錄顯示如何使用 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") );