使用 PowerShell 管理 Azure HDInsight 中的 Apache Hadoop 叢集
您可以使用 Azure PowerShell 來控制及自動化 Azure 中工作負載的部署和管理。 在本文中,您將瞭解如何使用 Az PowerShell 模組來管理 Azure HDInsight 中的 Apache Hadoop 叢集。 如需 HDInsight PowerShell Cmdlet 的清單,請參閱 Az.HDInsight 參考。
如果您沒有 Azure 訂用帳戶,請在開始前建立免費帳戶。
必要條件
注意
建議您使用 Azure Az PowerShell 模組來與 Azure 互動。 若要開始使用,請參閱安裝 Azure PowerShell (部分機器翻譯)。 若要了解如何移轉至 Az PowerShell 模組,請參閱將 Azure PowerShell 從 AzureRM 移轉至 Az。
建立叢集
若要建立叢集,請參閱 使用 Azure PowerShell 在 HDInsight 中建立以 Linux 為基礎的叢集。
列出叢集
若要列出目前訂用帳戶中的所有叢集,請使用下列命令:
Get-AzHDInsightCluster
顯示叢集
若要顯示目前訂用帳戶中特定叢集的詳細數據,請使用下列命令:
Get-AzHDInsightCluster -ClusterName <Cluster Name>
刪除叢集
若要刪除叢集,請使用下列命令:
Remove-AzHDInsightCluster -ClusterName <Cluster Name>
您也可以移除包含叢集的資源群組來刪除叢集。 刪除資源群組會刪除群組中的所有資源,包括預設記憶體帳戶。
Remove-AzResourceGroup -Name <Resource Group Name>
擴充叢集
您可以使用叢集調整功能來變更 HDInsight 中執行之叢集所使用的背景工作節點數目,而不需要重新建立叢集。 若要使用 PowerShell 變更 Hadoop 叢集大小,請從用戶端電腦執行下列命令:
Set-AzHDInsightClusterSize -ClusterName <Cluster Name> -TargetInstanceCount <NewSize>
如需調整叢集的詳細資訊,請參閱調整 HDInsight 叢集。
更新 HTTP 使用者認證
Set-AzHDInsightGatewayCredential 參數會設定 HDInsight 叢集的網關 HTTP 認證。
$clusterName = "CLUSTERNAME"
$credential = Get-Credential -Message "Enter the HTTP username and password:" -UserName "admin"
Set-AzHDInsightGatewayCredential -ClusterName $clusterName -HttpCredential $credential
尋找預設的儲存體帳戶
下列 PowerShell 指令碼示範如何取得預設儲存體帳戶名稱和相關資訊:
#Connect-AzAccount
$clusterName = "<HDInsight Cluster Name>"
$clusterInfo = Get-AzHDInsightCluster -ClusterName $clusterName
$storageInfo = $clusterInfo.DefaultStorageAccount.split('.')
$defaultStorageType = $storageInfo[1]
$defaultStorageName = $storageInfo[0]
echo "Default Storage account name: $defaultStorageName"
echo "Default Storage account type: $defaultStorageType"
if ($defaultStorageType -eq "blob")
{
$defaultBlobContainerName = $cluster.DefaultStorageContainer
$defaultStorageAccountKey = (Get-AzStorageAccountKey -ResourceGroupName $resourceGroupName -Name $defaultStorageAccountName)[0].Value
$defaultStorageAccountContext = New-AzStorageContext -StorageAccountName $defaultStorageAccountName -StorageAccountKey $defaultStorageAccountKey
echo "Default Blob container name: $defaultBlobContainerName"
echo "Default Storage account key: $defaultStorageAccountKey"
}
尋找資源群組
在 Azure Resource Manager 模式中,每個 HDInsight 叢集都屬於 Azure 資源群組。 若要尋找資源群組,請使用下列命令:
$clusterName = "<HDInsight Cluster Name>"
$cluster = Get-AzHDInsightCluster -ClusterName $clusterName
$resourceGroupName = $cluster.ResourceGroup
提交工作
若要使用下列產品提交作業,請遵循參考中的指示:
- MapReduce: 執行 HDInsight 中包含的 MapReduce 範例
- Apache Hive:使用 PowerShell 執行 Apache Hive 查詢
- Apache Sqoop: 搭配 HDInsight 使用 Apache Sqoop
- Apache Oozie:搭配 Apache Hadoop 使用 Apache Oozie 在 HDInsight 中定義和執行工作流程
將資料上傳至 Azure Blob 儲存體
若要將數據上傳至 Azure Blob 儲存體,請參閱將數據上傳至 HDInsight。