使用 Azure PowerShell 管理 HDInsight 上的 Apache Hadoop 叢集

Azure PowerShell 可讓您在 Azure 中用來控制和自動化工作負載的部署及管理。 在本文中,您將了解如何使用 Azure PowerShell Az 模組來管理 Azure HDInsight 中的 Apache Hadoop 叢集。 如需 HDInsight PowerShell Cmdlet 的清單,請參閱 Az.HDInsight 參考

如果您沒有 Azure 訂用帳戶,請在開始前建立免費帳戶

必要條件

注意

建議您使用 Azure Az PowerShell 模組來與 Azure 互動。 請參閱安裝 Azure PowerShell 以開始使用。 若要了解如何移轉至 Az PowerShell 模組,請參閱將 Azure PowerShell 從 AzureRM 移轉至 Az

安裝 PowerShell Az 模組

建立叢集

請參閱 使用 Azure PowerShell 在 HDInsight 中建立以 Linux 為基礎的叢集

列出叢集

使用下列命令列出目前訂用帳戶中的所有叢集:

Get-AzHDInsightCluster

顯示叢集

使用下列命令顯示目前訂用帳戶中特定叢集的詳細資料:

Get-AzHDInsightCluster -ClusterName <Cluster Name>

刪除叢集

使用下列命令來刪除叢集:

Remove-AzHDInsightCluster -ClusterName <Cluster Name>

您也可以移除包含叢集的資源群組來刪除叢集。 刪除資源群組會刪除群組中的所有資源 (包括預設儲存體帳戶)。

Remove-AzResourceGroup -Name <Resource Group Name>

擴充叢集

叢集調整功能可讓您變更在 Azure HDInsight 中執行的叢集所用的背景工作節點數目,而不需要重新建立叢集。 若要使用 Azure PowerShell 變更 Hadoop 叢集大小,請從用戶端電腦執行下列命令:

Set-AzHDInsightClusterSize -ClusterName <Cluster Name> -TargetInstanceCount <NewSize>

如需調整叢集的詳細資訊,請參閱調整 HDInsight 叢集

更新 HTTP 使用者認證

Set-AzHDInsightGatewayCredential 會設定 Azure 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('.')
$defaultStoreageType = $storageInfo[1]
$defaultStorageName = $storageInfo[0]

echo "Default Storage account name: $defaultStorageName"
echo "Default Storage account type: $defaultStoreageType"

if ($defaultStoreageType -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"
}

尋找資源群組

在 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 作業

請參閱在 HDInsight 中搭配 Apache Hadoop 使用 Apache Oozie 來定義並執行工作流程

將資料上傳至 Azure Blob 儲存體

請參閱將資料上傳至 HDInsight

另請參閱