Skapa Linux-baserade kluster i HDInsight med Azure PowerShell

Azure PowerShell är en kraftfull skriptmiljö som du kan använda för att styra och automatisera distributionen och hanteringen av dina arbetsbelastningar i Microsoft Azure. Det här dokumentet innehåller information om hur du skapar ett Linux-baserat HDInsight-kluster med hjälp av Azure PowerShell. Den innehåller också ett exempelskript.

Om du inte har någon Azure-prenumeration kan du skapa ett kostnadsfritt konto innan du börjar.

Förutsättningar

Anteckning

Vi rekommenderar att du använder Azure Az PowerShell-modulen för att interagera med Azure. Se Installera Azure PowerShell för att komma igång. Information om hur du migrerar till Az PowerShell-modulen finns i artikeln om att migrera Azure PowerShell från AzureRM till Az.

Azure PowerShell Az-modulen.

Skapa kluster

Varning

Faktureringen för HDInsight-kluster beräknas proportionellt per minut, oavsett om du använder dem eller inte. Se till att ta bort klustret när du har använt det. Se hur du tar bort ett HDInsight-kluster.

Om du vill skapa ett HDInsight-kluster med hjälp av Azure PowerShell måste du utföra följande procedurer:

  • Skapa en Azure-resursgrupp
  • Skapa ett Azure Storage-konto
  • Skapa en Azure Blob-container
  • Skapa ett HDInsight-kluster

Anteckning

Det finns för närvarande inte stöd för att använda PowerShell för att skapa ett HDInsight-kluster med Azure Data Lake Storage Gen2.

Följande skript visar hur du skapar ett nytt kluster:

# Login to your Azure subscription
$context = Get-AzContext
if ($context -eq $null) 
{
    Connect-AzAccount
}
$context

# If you have multiple subscriptions, set the one to use
# $subscriptionID = "<subscription ID to use>"
# Select-AzSubscription -SubscriptionId $subscriptionID

# Get user input/default values
$resourceGroupName = Read-Host -Prompt "Enter the resource group name"
$location = Read-Host -Prompt "Enter the Azure region to create resources in"

# Create the resource group
New-AzResourceGroup -Name $resourceGroupName -Location $location

$defaultStorageAccountName = Read-Host -Prompt "Enter the name of the storage account"

# Create an Az.Storage account and container
New-AzStorageAccount `
    -ResourceGroupName $resourceGroupName `
    -Name $defaultStorageAccountName `
    -Type Standard_LRS `
    -Location $location
$defaultStorageAccountKey = (Get-AzStorageAccountKey `
                                -ResourceGroupName $resourceGroupName `
                                -Name $defaultStorageAccountName)[0].Value

$storageAccountResourceId = (Get-AzStorageAccount -ResourceGroupName $resourceGroupName -AccountName $defaultStorageAccountName).Id  

$defaultStorageContext = New-AzStorageContext `
                                -StorageAccountName $defaultStorageAccountName `
                                -StorageAccountKey $defaultStorageAccountKey

# Get information for the HDInsight cluster
$clusterName = Read-Host -Prompt "Enter the name of the HDInsight cluster"
# Cluster login is used to secure HTTPS services hosted on the cluster
$httpCredential = Get-Credential -Message "Enter Cluster login credentials" -UserName "admin"
# SSH user is used to remotely connect to the cluster using SSH clients
$sshCredentials = Get-Credential -Message "Enter SSH user credentials" -UserName "sshuser"

# Default cluster size (# of worker nodes), version, type, and OS
$clusterSizeInNodes = "4"
$clusterVersion = "5.1"
$clusterType = "Hadoop"
$clusterOS = "Linux"
# Set the storage container name to the cluster name
$defaultBlobContainerName = $clusterName

# Create a blob container. This holds the default data store for the cluster.
New-AzStorageContainer `
    -Name $clusterName -Context $defaultStorageContext 

# Create the HDInsight cluster
    New-AzHDInsightCluster `
    -ResourceGroupName $resourceGroupName `
    -ClusterName $clusterName `
    -Location $location `
    -ClusterSizeInNodes $clusterSizeInNodes `
    -ClusterType $clusterType `
    -OSType $clusterOS `
    -Version $clusterVersion `
    -HttpCredential $httpCredential `
    -StorageAccountResourceId $storageAccountResourceId `
    -StorageAccountKey $defaultStorageAccountKey `
    -StorageContainer $defaultBlobContainerName `
    -SshCredential $sshCredentials

De värden som du anger för klusterinloggningen används för att skapa Hadoop-användarkontot för klustret. Använd det här kontot för att ansluta till tjänster som finns i klustret, till exempel webb-API:er eller REST-API:er.

De värden som du anger för SSH-användaren används för att skapa SSH-användaren för klustret. Använd det här kontot för att starta en fjärr-SSH-session i klustret och köra jobb. Mer information finns i dokumentet Använda SSH med HDInsight.

Viktigt

Om du planerar att använda fler än 32 arbetsnoder (antingen när klustret skapas eller genom att skala klustret när det har skapats) måste du också ange en huvudnodstorlek med minst 8 kärnor och 14 GB RAM-minne.

Mer information om nodstorlekar och relaterade kostnader finns i HDInsight-prissättning.

Det kan ta upp till 20 minuter att skapa ett kluster.

Skapa kluster: Konfigurationsobjekt

Du kan också skapa ett HDInsight-konfigurationsobjekt med hjälp av New-AzHDInsightClusterConfig cmdleten . Du kan sedan ändra det här konfigurationsobjektet för att aktivera ytterligare konfigurationsalternativ för klustret. Använd slutligen parametern -Config för cmdleten New-AzHDInsightCluster för att använda konfigurationen.

Anpassa kluster

Ta bort klustret

Varning

Faktureringen för HDInsight-kluster beräknas proportionellt per minut, oavsett om du använder dem eller inte. Se till att ta bort klustret när du har använt det. Se hur du tar bort ett HDInsight-kluster.

Felsöka

Om du får problem med att skapa HDInsight-kluster läser du åtkomstkontrollkrav.

Nästa steg

Nu när du har skapat ett HDInsight-kluster kan du använda följande resurser för att lära dig hur du arbetar med klustret.

Apache Hadoop-kluster

Apache HBase-kluster

Apache Spark-kluster