使用 Azure CLI 管理 Azure HDInsight 群集Manage Azure HDInsight clusters using Azure CLI

了解如何使用 Azure CLI 管理 Azure HDInsight 群集。Learn how to use Azure CLI to manage Azure HDInsight clusters. Azure 命令行接口 (CLI) 是用于管理 Azure 资源的 Microsoft 跨平台命令行体验。The Azure command-line interface (CLI) is Microsoft's cross-platform command-line experience for managing Azure resources.

如果没有 Azure 订阅,可在开始前创建一个试用帐户If you don't have an Azure subscription, create a trial account before you begin.

先决条件Prerequisites

连接到 AzureConnect to Azure

登录到 Azure 订阅。Sign in to your Azure subscription. 输入以下命令:Enter the command below:

az login

# If you have multiple subscriptions, set the one to use
# az account set --subscription "SUBSCRIPTIONID"

列出群集List clusters

使用 az hdinsight list 列出群集。Use az hdinsight list to list clusters. 编辑以下命令,将 RESOURCE_GROUP_NAME 替换为资源组的名称,然后输入命令:Edit the commands below by replacing RESOURCE_GROUP_NAME with the name of your resource group, then enter the commands:

# List all clusters in the current subscription
az hdinsight list

# List only cluster name and its resource group
az hdinsight list --query "[].{Cluster:name, ResourceGroup:resourceGroup}" --output table

# List all cluster for your resource group
az hdinsight list --resource-group RESOURCE_GROUP_NAME

# List all cluster names for your resource group
az hdinsight list --resource-group RESOURCE_GROUP_NAME --query "[].{clusterName:name}" --output table

显示群集Show cluster

使用 az hdinsight show 显示指定群集的信息。Use az hdinsight show to show information for a specified cluster. 编辑以下命令,将 RESOURCE_GROUP_NAMECLUSTER_NAME 替换为相关信息,然后输入命令:Edit the command below by replacing RESOURCE_GROUP_NAME, and CLUSTER_NAME with the relevant information, then enter the command:

az hdinsight show --resource-group RESOURCE_GROUP_NAME --name CLUSTER_NAME

删除群集Delete clusters

使用 az hdinsight delete 删除指定的群集。Use az hdinsight delete to delete a specified cluster. 编辑以下命令,将 RESOURCE_GROUP_NAMECLUSTER_NAME 替换为相关信息,然后输入命令:Edit the command below by replacing RESOURCE_GROUP_NAME, and CLUSTER_NAME with the relevant information, then enter the command:

az hdinsight delete --resource-group RESOURCE_GROUP_NAME --name CLUSTER_NAME

还可以通过删除包含群集的资源组来删除群集。You can also delete a cluster by deleting the resource group that contains the cluster. 请注意,这会删除包括默认存储帐户的组中的所有资源。Note, this will delete all the resources in the group including the default storage account.

az group delete --name RESOURCE_GROUP_NAME

缩放群集Scale clusters

使用 az hdinsight resize 将指定的 HDInsight 群集调整为指定大小。Use az hdinsight resize to resize the specified HDInsight cluster to the specified size. 编辑以下命令,将 RESOURCE_GROUP_NAMECLUSTER_NAME 替换为相关信息。Edit the command below by replacing RESOURCE_GROUP_NAME, and CLUSTER_NAME with the relevant information. WORKERNODE_COUNT 替换为群集所需的工作器节点数。Replace WORKERNODE_COUNT with the desired number of worker nodes for your cluster. 有关缩放群集的详细信息,请参阅缩放 HDInsight 群集For more information about scaling clusters, see Scale HDInsight clusters. 输入以下命令:Enter the command:

az hdinsight resize --resource-group RESOURCE_GROUP_NAME --name CLUSTER_NAME --workernode-count WORKERNODE_COUNT

后续步骤Next steps

在本文中,已了解如何执行不同的 HDInsight 群集管理任务。In this article, you have learned how to perform different HDInsight cluster administrative tasks. 要了解更多信息,请参阅下列文章:To learn more, see the following articles: