Personalizar clusters HDInsight usando o Bootstrap
Os scripts de bootstrap permitem instalar e configurar componentes no Azure HDInsight programaticamente.
Há três abordagens para definir as definições do arquivo de configuração à medida que o cluster HDInsight é criado:
- Utilizar o Azure PowerShell
- Utilizar o .NET SDK
- Utilizar o modelo do Azure Resource Manager
Por exemplo, usando esses métodos programáticos, você pode configurar opções nestes arquivos:
- clusterIdentity.xml
- core-site.xml
- gateway.xml
- hbase-env.xml
- hbase-site.xml
- hdfs-site.xml
- hive-env.xml
- hive-site.xml
- site-mapeado
- oozie-site.xml
- oozie-env.xml
- tez-site.xml
- webhcat-site.xml
- yarn-site.xml
- server.properties (configuração kafka-broker)
Para obter informações sobre como instalar mais componentes no cluster HDInsight durante o tempo de criação, consulte Personalizar clusters HDInsight usando Ação de Script (Linux).
Pré-requisitos
- Se estiver usando o PowerShell, você precisará do Módulo Az.
Utilizar o Azure PowerShell
O seguinte código do PowerShell personaliza uma configuração do Apache Hive :
Importante
O parâmetro Spark2Defaults
pode precisar ser usado com Add-AzHDInsightConfigValue. Você pode passar valores vazios para o parâmetro, conforme mostrado no exemplo de código a seguir.
# 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
Um script PowerShell de trabalho completo pode ser encontrado no Apêndice.
Para verificar a alteração:
- Navegue até
https://CLUSTERNAME.azurehdinsight.net/
ondeCLUSTERNAME
está o nome do cluster. - No menu à esquerda, navegue até Hive>Configs>Advanced.
- Expanda Site de colmeia avançado.
- Localize hive.metastore.client.socket.timeout e confirme se o valor é 90s.
Mais alguns exemplos sobre como personalizar outros arquivos de configuração:
# 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
Utilizar o .NET SDK
Consulte SDK do Azure HDInsight para .NET.
Utilizar modelo do Resource Manager
Você pode usar o bootstrap no modelo do Gerenciador de Recursos:
"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"
}
}
Exemplo de trecho de modelo do Gerenciador de Recursos para alternar a configuração em spark2-defaults para limpar periodicamente os logs de eventos do armazenamento.
"configurations": {
"spark2-defaults": {
"spark.history.fs.cleaner.enabled": "true",
"spark.history.fs.cleaner.interval": "7d",
"spark.history.fs.cleaner.maxAge": "90d"
}
}
Consulte também
- Criar clusters Apache Hadoop no HDInsight fornece instruções sobre como criar um cluster HDInsight usando outras opções personalizadas.
- Desenvolver scripts de ação de script para o HDInsight
- Instalar e usar o Apache Spark em clusters HDInsight
- Instale e use o Apache Giraph em clusters HDInsight.
Apêndice: Exemplo do PowerShell
Esse script do PowerShell cria um cluster HDInsight e personaliza uma configuração do Hive. Certifique-se de inserir valores para $nameToken
, $httpPassword
e $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