你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

使用 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

安装了 Az PowerShell 模块

创建群集

若要创建群集,请参阅使用 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 资源管理器式下,每个 HDInsight 群集都属于一个 Azure 资源组。 若要查找资源组,请使用以下命令:

$clusterName = "<HDInsight Cluster Name>"

$cluster = Get-AzHDInsightCluster -ClusterName $clusterName
$resourceGroupName = $cluster.ResourceGroup

提交作业

若要使用以下产品提交作业,请按照参考中的说明操作:

将数据上传到 Azure Blob 存储

若要将数据上载到 Azure Blob 存储的信息,请参阅将数据上载到 HDInsight