ブートストラップを使って HDInsight クラスターをカスタマイズする

ブートストラップ スクリプトを使用すると、Azure HDInsight のコンポーネントをプログラムでインストールおよび構成できます。

HDInsight クラスターの作成時に構成ファイル設定を指定する方法は、次の 3 つです。

  • 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)」を参照してください。

前提条件

Azure PowerShell の使用

次の PowerShell コードでは、Apache Hive 構成をカスタマイズします。

重要

Add-Add-AzHDInsightConfigValue と共にパラメーター Spark2Defaults を使うことが必要な場合があります。 次のコード例に示すように、パラメーターに空の値を渡すことができます。

# 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]>[Configs](構成)>[Advanced](詳細) に移動します。
  3. [Advanced hive-site](詳細な Hive サイト) を展開します。
  4. hive.metastore.client.socket.timeout を探し、値が 90s であることを確認します。

他の構成ファイルのカスタマイズのサンプルを次に示します。

# 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 の使用

Azure HDInsight SDK for .NET」を参照してください。

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.

定期的にイベント ログをストレージからクリーンアップするために spark2-defaults の構成を切り替える Resource Manager テンプレート スニペットのサンプル。

"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 の設定をカスタマイズします。 必ず $nameToken$httpPassword、および $sshPassword の値を入力してください。

####################################
# 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