Advertisement
Guest User

Untitled

a guest
Feb 4th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.06 KB | None | 0 0
  1.  
  2. Write-host -ForegroundColor Green "Hello! The first step in this lab is to login to your Azure account using your Microsoft credentials."
  3. Write-host -ForegroundColor Green "Make sure to use the email address you used when activating your azure pass!"
  4. Write-host -ForegroundColor Yellow "Press ENTER to continue"
  5.  
  6. $notNeeded = Read-Host
  7.  
  8. Login-AzureRmAccount
  9.  
  10.  
  11. function Get-Sub
  12. {
  13. $Subs = Get-AzureRmSubscription
  14. Write-host -ForegroundColor Green "In which subscription would you like to create your HDInsight Cluster?"
  15. $loopCounter = 0;
  16. ForEach( $individualSub In $Subs)
  17. {
  18. Write-Host "$loopCounter $($individualSub.SubscriptionName)";
  19. $loopCounter++
  20.  
  21. }
  22.  
  23. Write-host -ForegroundColor Yellow "Please enter the corresponding number of the subscription you would like to use"
  24. $subNum = Read-Host
  25. $Subs[$subNum]
  26. }
  27.  
  28. $Sub = Get-Sub
  29.  
  30.  
  31.  
  32. $token = "$(Get-Random)"
  33. $subscriptionID = $($sub.SubscriptionId) # Provide your Subscription Name
  34.  
  35. $resourceGroupName = "$($token)rg" # Provide a Resource Group name
  36. $clusterName = "a$($token)"
  37. $defaultStorageAccountName = $token + "store" # Provide a Storage account name
  38. $defaultStorageContainerName = $token + "container"
  39. $location = "East US 2" # Change the location if needed
  40. $clusterNodes = 1 # The number of nodes in the HDInsight cluster
  41.  
  42.  
  43. # Select the subscription to use if you have multiple subscriptions
  44. $notNeeded = Select-AzureRmSubscription -SubscriptionId $subscriptionID
  45.  
  46.  
  47. # Create an Azure Resource Group
  48. New-AzureRmResourceGroup -Name $resourceGroupName -Location $location
  49.  
  50. # Create an Azure Storage account and container used as the default storage
  51. New-AzureRmStorageAccount `
  52. -ResourceGroupName $resourceGroupName `
  53. -StorageAccountName $defaultStorageAccountName `
  54. -Location $location `
  55. -Type Standard_LRS
  56. $defaultStorageAccountKey = (Get-AzureRmStorageAccountKey -Name $defaultStorageAccountName -ResourceGroupName $resourceGroupName)[0].Value
  57. $destContext = New-AzureStorageContext -StorageAccountName $defaultStorageAccountName -StorageAccountKey $defaultStorageAccountKey
  58. New-AzureStorageContainer -Name $defaultStorageContainerName -Context $destContext
  59.  
  60. #HDI Cluster Credentials
  61. $clusterUserName = "admintime"
  62. $clusterPassword = ConvertTo-SecureString "Pa55w.rd" -AsPlainText -Force
  63. $credentials = New-Object System.Management.Automation.PSCredential($clusterUsername, $clusterPassword)
  64.  
  65.  
  66. $sshUserName = "sshadmin"
  67. $sshUnsecuredPassword = "Pa55w.rd"
  68. $sshPassword = ConvertTo-SecureString $sshUnsecuredPassword -AsPlainText -Force
  69. $sshCredentials = New-Object System.Management.Automation.PSCredential($sshUserName, $sshPassword)
  70.  
  71.  
  72. # The location of the HDInsight cluster must be in the same data center as the Storage account.
  73. $location = Get-AzureRmStorageAccount -ResourceGroupName $resourceGroupName -StorageAccountName $defaultStorageAccountName | %{$_.Location}
  74.  
  75. Write-Host -ForegroundColor Green "We are now creating your HDInsight Cluster. Please continue on with your lesson as it is created."
  76.  
  77. New-AzureRmHDInsightCluster `
  78. -ClusterName $clusterName `
  79. -ResourceGroupName $resourceGroupName `
  80. -HttpCredential $credentials `
  81. -Location $location `
  82. -DefaultStorageAccountName "$defaultStorageAccountName.blob.core.windows.net" `
  83. -DefaultStorageAccountKey $defaultStorageAccountKey `
  84. -DefaultStorageContainer $defaultStorageContainerName `
  85. -ClusterSizeInNodes $clusterNodes `
  86. -ClusterType Hadoop `
  87. -OSType Linux `
  88. -Version "3.5" `
  89. -SshCredential $sshCredentials
  90.  
  91. Write-Host -ForegroundColor Green "Congratulations! Your cluster has been created and is named $($clusterName). Press Enter when you are ready to run your first MapReduce job"
  92.  
  93. $holder = Read-Host
  94.  
  95. Write-Host "Defining Word Count MapReduce Job" -ForegroundColor Green
  96.  
  97. $wordCountJobDefinition = New-AzureRmHDInsightMapReduceJobDefinition `
  98. -JarFile "/example/jars/hadoop-mapreduce-examples.jar" `
  99. -ClassName "wordcount" `
  100. -Arguments `
  101. "/example/data/gutenberg/davinci.txt", `
  102. "/example/data/WordCountOutput"
  103.  
  104. Write-Host "Reading data from /example/data/gutenberg/davinci.tx" -ForegroundColor Green
  105. Write-Host "Writing output to /example/data/WordCountOutput" -ForegroundColor Green
  106.  
  107.  
  108. #Submit the job to the cluster
  109. Write-Host "Submitting MapReduce job..." -ForegroundColor Green
  110. $wordCountJob = Start-AzureRmHDInsightJob `
  111. -ClusterName $clusterName `
  112. -JobDefinition $wordCountJobDefinition `
  113. -HttpCredential $credentials
  114.  
  115. #Wait for the job to complete
  116. Write-Host "Job is running. Please wait for completion..." -ForegroundColor Green
  117. Wait-AzureRmHDInsightJob `
  118. -ClusterName $clusterName `
  119. -JobId $wordCountJob.JobId `
  120. -HttpCredential $credentials
  121.  
  122. # Download the output
  123. Get-AzureStorageBlobContent `
  124. -Blob 'example/data/WordCountOutput/part-r-00000' `
  125. -Container $defaultStorageContainerName `
  126. -Destination WordCountOutput.txt `
  127. -Context $destContext
  128.  
  129. Write-Host -ForegroundColor Green "Downloaded output to WordCountOutput.txt. By Default to /WordCountOutput.txt"
  130.  
  131. # Print the output of the job.
  132. $notNeeded = Get-AzureRmHDInsightJobOutput `
  133. -Clustername $clusterName `
  134. -JobId $wordCountJob.JobId `
  135. -HttpCredential $credentials
  136.  
  137.  
  138. Get-Content WordCountOutput.txt -First 75
  139.  
  140. Write-Host -ForegroundColor Green "Abbreviated output. Full output can be found in WordCountOutput.txt. Typically stored in C:/Users/<Username>/WordCountOutput.txt"
  141. Write-Host -ForegroundColor Green "Output shows the word and then the number of times it is found in the input file"
  142. Write-Host -ForegroundColor Green "Now go to section Run a Yarn Job to use HDInsight to solve a Sudoku puzzle!"
  143. Write-Host -ForegroundColor Cyan "Host Name: $($clusterName)-ssh.azurehdinsight.net"
  144. Write-Host -ForegroundColor Cyan "SSH User Name: $($sshUserName)"
  145. Write-Host -ForegroundColor Cyan "SSH Password: $($sshUnsecuredPassword)"
  146. Write-Host -ForegroundColor Cyan "Resource Group Name: $($resourceGroupName)"
  147.  
  148.  
  149. Write-Host -ForegroundColor yellow "Press enter to end this script."
  150.  
  151. Read-Host
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement