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 模块。
使用 Azure PowerShell
以下 PowerShell 代码将自定义 Apache Hive 配置:
重要
参数 Spark2Defaults 可能需要与 Add-AzHDInsightConfigValues 一起使用。 你可以向参数传递空值,如以下代码示例中所示。
# 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 脚本。
若要验证更改,请执行以下操作:
- 导航至 https://CLUSTERNAME.azurehdinsight.cn/,其中CLUSTERNAME是群集的名称。
- 从左侧菜单中,导航到“Hive”>“配置”>“高级”。
- 展开“高级 hive-site”。
- 找到 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
请参阅用于 .NET 的 Azure HDInsight SDK。
使用 Resource Manager 模板
可以在 Resource Manager 模板中使用 bootstrap:
"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"
    }
}
 
spark2-defaults 中用于切换配置的示例 Azure 资源管理器模板代码片段会定期清除存储中的事件日志。
"configurations": {
    "spark2-defaults": {
        "spark.history.fs.cleaner.enabled": "true",
        "spark.history.fs.cleaner.interval": "7d",
        "spark.history.fs.cleaner.maxAge": "90d"
    }
}
另请参阅
- 在 HDInsight 中创建 Apache Hadoop 群集提供了有关如何使用其他自定义选项创建 HDInsight 群集的说明。
- 为 HDInsight 开发脚本操作脚本
- 在 HDInsight 群集上安装并使用 Apache Spark
- 在 HDInsight 群集上安装并使用 Apache Giraph。
附录: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 = "China East"
####################################
# Connect to Azure
####################################
Write-Host "Connecting to your Azure subscription ..." -ForegroundColor Green
$sub = Get-AzSubscription -ErrorAction SilentlyContinue
if(-not($sub))
{
    Connect-AzAccount -Environment AzureChinaCloud
}
# 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