Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
In unserer Azure PowerShell Serie knüpfen wir uns die etwas ausgefallenere Erstellung eines HDInsight-Clusters vor.
Im Azure Management Portal hieße das konkret folgendermaßen:
In dem untenstehenden PowerShell-Skript passieren noch viele weitere Sachen:
- Hive/Oozie Metastore
Hierfür wird im Skript selber ein Azure SQL Server und eine Datenbank erstellt. Analog in dem Azure Portal sieht es so aus:
- Ein weiteres Speicherkonto anhängen
Beim Erstellen eines HDInsight-Clusters wird immer ein dediziertes Speicherkonto hergenommen. Dabei kann man noch weitere Speicherkonten anhängen:
Der Skript ist dazu angedacht, die Parameter in den Abschnitten 0. Azure Account Details und 1. Input Information selber zu vervollständigen.
001002003004005006007008009010011012013014015016017018019020021022023024025026027028029030031032033034035036037038039040041042043044045046047048049050051052053054055056057058059060061062063064065066067068069070071072073074075076077078079080081082083084085086087088089090091092093094095096097098099100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 | #################################################### Create custom HDInsight Cluster: Custom 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# variables to HDInsight cluster$clusterName = "<HDInsightClusterName>"$___location = "<DatacenterLocation>" #e.g. North Europe, West Europe, etc.$numNodes = 1 #start small$clusterCreds = Get-Credential -Message "New admin account to be created for your HDInsight cluster" #this prompts you# variables to storage accounts$storageAccount1 = "<StorageAccountName1>"$defaultContainer = "<StorageContainerName>"$storageAccount2 = "<StorageAccountName2>"# admin credentials to Azure SQL Server$metastoreAzureSQLDBName = "<AzureSQLDatabaseName>"$sqlAdminLogin = "<SQLServerLogin>"$sqlAdminPasswd = "<SQLServerPassword>"#################################################### 2. Create storage accounts# Create first storage account without geo-replication and create default containerNew-AzureStorageAccount -StorageAccountName $storageAccount1 -Location $locationSet-AzureStorageAccount -StorageAccountName $storageAccount1 ` -GeoReplicationEnabled $false$fullStorage1 = "$storageAccount1.blob.core.windows.net" #full storage account name$storageKey1 = Get-AzureStorageKey $storageAccount1 | %{ $_.Primary } $storageContext1 = New-AzureStorageContext -StorageAccountName $storageAccount1 ` -StorageAccountKey $storageKey1New-AzureStorageContainer -Name $defaultContainer -Context $storageContext1New-AzureStorageContainer "hivelibs" -Context $storageContext1# Create second storage accountNew-AzureStorageAccount -StorageAccountName $storageAccount2 -Location $locationSet-AzureStorageAccount -StorageAccountName $storageAccount2 ` -GeoReplicationEnabled $false$fullStorage2 = "$storageAccount2.blob.core.windows.net" $storageKey2 = Get-AzureStorageKey $StorageAcct2 | %{ $_.Primary }$storageContext2 = New-AzureStorageContext -StorageAccountName $storageAccount2 ` -StorageAccountKey $storageKey2#################################################### 3. Create Azure SQL Database and Server$sqlServer = New-AzureSqlDatabaseServer -AdministratorLogin $sqlAdminLogin ` -AdministratorLoginPassword $sqlAdminPasswd -Location $___location# Configure Firewall: allow all IP addresses, and allow all windows Azure servicesNew-AzureSqlDatabaseServerFirewallRule -ServerName $sqlServer.ServerName ` -RuleName "allowall" -StartIpAddress 1.1.1.1 -EndIpAddress 255.255.255.255New-AzureSqlDatabaseServerFirewallRule -ServerName $sqlServer.ServerName ` -RuleName "allowallazureservices" -StartIpAddress 0.0.0.0 -EndIpAddress 0.0.0.0# Azure SQL Database$sqlServerCreds = New-Object System.Management.Automation.PSCredential($sqlAdminLogin,($sqlAdminPasswd ` | ConvertTo-SecureString -AsPlainText -Force))$sqlContext = New-AzureSqlDatabaseServerContext -ServerName $sqlServer.ServerName ` -Credential $sqlServerCreds$MetastoreAzureSQLDBName = $sqlDBNew-AzureSqlDatabase -DatabaseName $sqlDB -ConnectionContext $sqlContext$metastoreAzureServerName = "$($sqlServer.ServerName).database.windows.net" $metastoreCreds = Get-Credential -Message "existing id/password for your SQL Azure DB (metastore)" #This prompts for the existing id and password of your existing SQL Azure DB#################################################### 4. Hive Configuration# This value is set for you, don't change! $configvalues = new-object 'Microsoft.WindowsAzure.Management.HDInsight.Cmdlet.DataObjects.AzureHDInsightHiveConfiguration'$configvalues.Configuration = @{ “hive.exec.compress.output”=”true” } #this is an example of a config value you may pass in# Add a config file value # Add AVRO SerDe libraries for Hive (on storage 1) $configvalues.AdditionalLibraries = new-object 'Microsoft.WindowsAzure.Management.HDInsight.Cmdlet.DataObjects.AzureHDInsightDefaultStorageAccount' $configvalues.AdditionalLibraries.StorageAccountName = $fullStorage1$configvalues.AdditionalLibraries.StorageAccountKey = $storageKey1$configvalues.AdditionalLibraries.StorageContainerName = "hivelibs" #container called hivelibs must exist on specified storage account #################################################### 5. Create custom HDInsight ClusterNew-AzureHDInsightClusterConfig -ClusterSizeInNodes $numNodes ` | Set-AzureHDInsightDefaultStorage -StorageAccountName $fullStorage1 ` -StorageAccountKey $storageKey1 -StorageContainerName $defaultContainer ` | Add-AzureHDInsightStorage -StorageAccountName $fullStorage2 -StorageAccountKey $storageKey2 ` | Add-AzureHDInsightMetastore -SqlAzureServerName $metastoreAzureServerName ` -DatabaseName $metastoreAzureSQLDBName -Credential $metastoreCreds -MetastoreType OozieMetastore ` | Add-AzureHDInsightMetastore -SqlAzureServerName $metastoreAzureServerName ` -DatabaseName $metastoreAzureSQLDBName -Credential $metastoreCreds -MetastoreType HiveMetastore ` | Add-AzureHDInsightConfigValues -Hive $configvalues ` | New-AzureHDInsightCluster -Subscription $subID -Location $___location ` -Name $clusterName -Credential $clusterCreds#################################################### 6. get status, properties, etc. Get-AzureHDInsightProperties -Subscription $subIDGet-AzureHDInsightCluster -Subscription $subIDGet-AzureHDInsightCluster -Subscription $subID -Name $clusterName#################################################### 7. Clean up: HDInsight cluster, SQL Server & Database, storage accounts# Remove HDInsight clusterRemove-AzureHDInsightCluster -Name $ClusterName #-Subscription $SubName# Remove storage accountsRemove-AzureStorageAccount $storageAccount1Remove-AzureStorageAccount $storageAccount2# Remove SQL serverRemove-AzureSqlDatabaseServer -ServerName $sqlServer.ServerName |
Comments
- Anonymous
April 14, 2014
In dieser Serie werde ich meine Lieblings-PowerShell-Skripte veröffentlichen, die mir das Leben um einige - Anonymous
May 26, 2014
Upload Data Create HDInsight Cluster Mahout: general PowerShell command Scenario: Random Forest Build - Anonymous
May 26, 2014
Upload Data Create HDInsight Cluster Mahout: general PowerShell command Scenario: Random Forest Build