可以使用Azure PowerShell来控制和管理Azure中工作负荷的部署和管理。 本文介绍如何使用 Az PowerShell 模块管理 Azure HDInsight Apache Hadoop 群集。 有关 HDInsight PowerShell 命令列表,请查看 Az.HDInsight 文档。
如果没有 Azure 订阅,请在开始前创建试用订阅。
先决条件
注意
建议使用 Azure Az PowerShell 模块与Azure交互。 若要开始,请参阅 Install Azure PowerShell。 若要了解如何迁移到 Az PowerShell 模块,请参阅 Migrate 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 -Environment AzureChinaCloud
$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:将 Apache Sqoop 与 HDInsight 配合使用
- Apache Oozie:在 HDInsight 中将 Apache Oozie 与 Apache Hadoop 配合使用以定义和运行工作流
将数据上传到Azure Blob Storage
若要将数据上传到Azure Blob Storage,请参阅将数据加载到 HDInsight。
相关内容
- Az.HDInsight cmdlet
- 使用 Azure 门户管理 HDInsight 中的 Apache Hadoop 群集
- 使用命令行接口管理 HDInsight
- 创建 HDInsight 群集
- 以编程方式提交 Apache Hadoop 作业
- 开始使用 Azure HDInsight