Azure PowerShell Serie (1): Simple HDInsight

Einen HDInsight-Cluster zu erstellen ist ja recht einfach. In der Blog-Serie Big Data Twitter Demo haben wir bereits einen HDInsight-Cluster von dem Windows Azure Management Portal aus erstellt (siehe Big Data Twitter Demo - HDInsight Cluster erstellen).

Wenn man jedoch so wie ich immer öfters einen neuen HDInsight-Cluster erstellt, lernt man PowerShell zu schätzen und lieben. Hier ist ein PowerShell Skript, mit dem man einen Cluster ohne große Mausbewegungen erstellen kann und dabei noch selber lernt.

Die Variabeln in den Abschnitten 0. Azure Account Details und 1. Input Information sollte man hierbei selber vervollständigen.

Happy PowerShell-Scripting! :)

001002003004005006007008009010011012013014015016017018019020021022023024025026027028029030031032033034035036037038039040041042043044045046047048049050051052053054055056057058059060 ######################################################## Create simple HDInsight Cluster: Quick Create# ISE is just awesomeise######################################################## 0. Azure Account DetailsAdd-AzureAccount$subName = "<AzureSbscriptionName>"Select-AzureSubscription $subName# Azure account details automatically set$subID = Get-AzureSubscription -Current | %{ $_.SubscriptionId } ######################################################## 1. Input information$clusterName = "<HDInsightClusterName>"$location = "<DatacenterLocation>" #e.g. North Europe, West Europe, etc.$numNodes = 1 #start small$storageAccount = "<StorageAccountName>"$defaultContainer = "<StorageContainerName>"######################################################## 2. Create storage accountNew-AzureStorageAccount -StorageAccountName $storageAccount -Location $location# Disbale geo replication to save costsSet-AzureStorageAccount -StorageAccountName $storageAccount -GeoReplicationEnabled $false# Variables automatically set for you$storageKey = Get-AzureStorageKey $storageAccount | %{ $_.Primary } $storageContext = New-AzureStorageContext -StorageAccountName $storageAccount -StorageAccountKey $storageKey$fullStorage = "${storageAccount}.blob.core.windows.net"# Create container in storage accountNew-AzureStorageContainer -Name $defaultContainer -Context $storageContext######################################################## 3. Create HDInsight cluster# Equivalent of quick create # Prompt for credentials for HDInsight cluster$clusterCreds = Get-Credential -Message "New admin account to be created for your HDInsight cluster"New-AzureHDInsightCluster -Subscription $subID -Location $location ` -Name $clusterName -ClusterSizeInNodes $numNodes -Credential $clusterCreds ` -DefaultStorageAccountName $fullStorage -DefaultStorageAccountKey $storageKey ` -DefaultStorageContainerName $defaultContainer######################################################## 4. Clean up: remove HDInsight clusterRemove-AzureHDInsightCluster -Name $clusterName -Subscription $subID

Weitere PowerShell-Skripte findet ihr unter der Übersicht Azure PowerShell Serie: Happy PowerShell-Scripting!