使用 Bootstrap 自訂 HDInsight 叢集

Bootstrap 腳本可讓您以程式設計方式在 Azure HDInsight 中安裝和設定元件。

建立 HDInsight 叢集時,有三種方法可設定組態檔設定:

  • 使用 Azure PowerShell
  • 使用 .NET SDK
  • 使用 Azure Resource Manager 範本

例如,使用這些程序設計方法,您可以在這些檔案中設定選項:

  • clusterIdentity.xml
  • core-site.xml
  • gateway.xml
  • hbase-env.xml
  • hbase-site.xml
  • hdfs-site.xml
  • hive-env.xml
  • hive-site.xml
  • mapred-site
  • oozie-site.xml
  • oozie-env.xml
  • tez-site.xml
  • webhcat-site.xml
  • yarn-site.xml
  • server.properties (kafka-broker 組態)

如需在建立期間在 HDInsight 叢集上安裝更多元件的資訊,請參閱使用腳本動作自定義 HDInsight 叢集(Linux)。

必要條件

  • 如果使用 PowerShell,您需要 Az Module

使用 Azure PowerShell

下列 PowerShell 程式代碼會 自訂 Apache Hive 組態:

重要

參數Spark2Defaults可能需要與 Add-AzHDInsightConfigValue 搭配使用。 您可以將空白值傳遞至 參數,如下列程式代碼範例所示。

# hive-site.xml configuration
$hiveConfigValues = @{ "hive.metastore.client.socket.timeout"="90s" }

$config = New-AzHDInsightClusterConfig `
         -ClusterType "Spark"  `
    | Set-AzHDInsightDefaultStorage `
        -StorageAccountResourceId "$storageAccountResourceId" `
        -StorageAccountKey $defaultStorageAccountKey `
    | Add-AzHDInsightConfigValue `
        -HiveSite $hiveConfigValues `
        -Spark2Defaults @{}

New-AzHDInsightCluster `
    -ResourceGroupName $resourceGroupName `
    -ClusterName $hdinsightClusterName `
    -Location $location `
    -ClusterSizeInNodes 2 `
    -Version "4.0" `
    -HttpCredential $httpCredential `
    -SshCredential $sshCredential `
    -Config $config

您可以在附錄中找到完整的 PowerShell 腳稿。

若要確認變更:

  1. 流覽至 https://CLUSTERNAME.azurehdinsight.net/ 其中 CLUSTERNAME 是叢集的名稱。
  2. 從左側功能表中,流覽至 [Hive>設定>進階]。
  3. 展開 [ 進階 Hive-site]。
  4. 找出 hive.metastore.client.socket.timeout ,並確認值為 90秒

自訂其他組態檔的一些更多範例:

# hdfs-site.xml configuration
$HdfsConfigValues = @{ "dfs.blocksize"="64m" } #default is 128MB in HDI 3.0 and 256MB in HDI 2.1

# core-site.xml configuration
$CoreConfigValues = @{ "ipc.client.connect.max.retries"="60" } #default 50

# mapred-site.xml configuration
$MapRedConfigValues = @{ "mapreduce.task.timeout"="1200000" } #default 600000

# oozie-site.xml configuration
$OozieConfigValues = @{ "oozie.service.coord.normal.default.timeout"="150" }  # default 120

使用 .NET SDK

請參閱 適用於 .NET 的 Azure HDInsight SDK。

使用 Resource Manager 範本

您可以在 Resource Manager 樣本中使用啟動程式:

"configurations": {
    "hive-site": {
        "hive.metastore.client.connect.retry.delay": "5",
        "hive.execution.engine": "mr",
        "hive.security.authorization.manager": "org.apache.hadoop.hive.ql.security.authorization.DefaultHiveAuthorizationProvider"
    }
}

Hadoop customizes cluster bootstrap Azure Resource Manager template.

範例 Resource Manager 範本代碼段,以切換 spark2 預設值中的組態,以定期清除記憶體中的事件記錄檔。

"configurations": {
    "spark2-defaults": {
        "spark.history.fs.cleaner.enabled": "true",
        "spark.history.fs.cleaner.interval": "7d",
        "spark.history.fs.cleaner.maxAge": "90d"
    }
}

另請參閱

附錄:PowerShell 範例

此 PowerShell 腳本會建立 HDInsight 叢集並自定義 Hive 設定。 請務必輸入、 $httpPassword$sshPassword的值$nameToken

####################################
# Service names and variables
####################################

$nameToken = "<ENTER AN ALIAS>"
$namePrefix = $nameToken.ToLower() + (Get-Date -Format "MMdd")
$resourceGroupName = $namePrefix + "rg"
$hdinsightClusterName = $namePrefix + "hdi"
$defaultStorageAccountName = $namePrefix + "store"
$defaultBlobContainerName = $hdinsightClusterName
$location = "East US"

####################################
# Connect to Azure
####################################

Write-Host "Connecting to your Azure subscription ..." -ForegroundColor Green
$sub = Get-AzSubscription -ErrorAction SilentlyContinue
if(-not($sub))
{
    Connect-AzAccount
}

# If you have multiple subscriptions, set the one to use
#$context = Get-AzSubscription -SubscriptionId "<subscriptionID>"
#Set-AzContext $context

####################################
# Create a resource group
####################################

Write-Host "Creating a resource group ..." -ForegroundColor Green
New-AzResourceGroup `
    -Name  $resourceGroupName `
    -Location $location

####################################
# Create a storage account and container
####################################
	
Write-Host "Creating the default storage account and default blob container ..."  -ForegroundColor Green
New-AzStorageAccount `
    -ResourceGroupName $resourceGroupName `
    -Name $defaultStorageAccountName `
    -Location $location `
    -SkuName Standard_LRS `
    -Kind StorageV2 `
    -EnableHttpsTrafficOnly 1
	
$defaultStorageAccountKey = (Get-AzStorageAccountKey `
                                -ResourceGroupName $resourceGroupName `
                                -Name $defaultStorageAccountName)[0].Value

$defaultStorageContext = New-AzStorageContext `
                                -StorageAccountName $defaultStorageAccountName `
                                -StorageAccountKey $defaultStorageAccountKey
								
New-AzStorageContainer `
    -Name $defaultBlobContainerName `
    -Context $defaultStorageContext #use the cluster name as the container name

####################################
# Create a configuration object
####################################

$hiveConfigValues = @{"hive.metastore.client.socket.timeout"="90s"}
$storageAccountResourceId = (Get-AzStorageAccount -ResourceGroupName $resourceGroupName ` -Name $defaultStorageAccountName).Id

$config = New-AzHDInsightClusterConfig `
          -ClusterType "Spark"  `
    | Set-AzHDInsightDefaultStorage `
        -StorageAccountResourceId "$storageAccountResourceId" `
        -StorageAccountKey $defaultStorageAccountKey `
    | Add-AzHDInsightConfigValue `
        -HiveSite $hiveConfigValues `
		-Spark2Defaults @{}
		
####################################
# Set Ambari admin username/password
####################################

$httpUserName = "admin"  #HDInsight cluster username
$httpPassword = '<ENTER A PASSWORD>'

$httpPW = ConvertTo-SecureString -String $httpPassword -AsPlainText -Force
$httpCredential = New-Object System.Management.Automation.PSCredential($httpUserName,$httpPW)

####################################
# Set ssh username/password
####################################

$sshUserName = "sshuser" #HDInsight ssh user name
$sshPassword = '<ENTER A PASSWORD>'

$sshPW = ConvertTo-SecureString -String $sshPassword -AsPlainText -Force
$sshCredential = New-Object System.Management.Automation.PSCredential($sshUserName,$sshPW)

####################################
# Create an HDInsight cluster
####################################

New-AzHDInsightCluster `
    -ResourceGroupName $resourceGroupName `
    -ClusterName $hdinsightClusterName `
    -Location $location `
    -ClusterSizeInNodes 2 `
    -Version "4.0" `
    -HttpCredential $httpCredential `
    -SshCredential $sshCredential `
    -Config $config
	
####################################
# Verify the cluster
####################################

Get-AzHDInsightCluster `
    -ClusterName $hdinsightClusterName