使用 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 -Environment AzureChinaCloud
$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 作业

请参阅将 Apache Sqoop 与 HDInsight 配合使用

提交 Apache Oozie 作业

请参阅在 HDInsight 中将 Apache Oozie 与 Apache Hadoop 配合使用以定义和运行工作流

将数据上传到 Azure Blob 存储

请参阅将数据上传到 HDInsight

另请参阅