本文档中的步骤逐步说明了如何使用 Azure CLI 创建 HDInsight 4.0 群集。
警告
HDInsight 群集按分钟按比例收费,无论是否使用。 请务必在使用完群集之后将其删除。 请参阅如何删除 HDInsight 群集。
如果没有 Azure 帐户,请在开始前创建一个免费帐户。
先决条件
在 Azure Cloud Shell 中使用 Bash 环境。 有关详细信息,请参阅 Azure Cloud Shell 入门。
如需在本地运行 CLI 参考命令,请安装 Azure CLI。 如果在 Windows 或 macOS 上运行,请考虑在 Docker 容器中运行 Azure CLI。 有关详细信息,请参阅如何在 Docker 容器中运行 Azure CLI。
如果使用的是本地安装,请使用 az login 命令登录到 Azure CLI。 若要完成身份验证过程,请遵循终端中显示的步骤。 有关其他登录选项,请参阅 使用 Azure CLI 向 Azure 进行身份验证。
出现提示时,请在首次使用时安装 Azure CLI 扩展。 有关扩展的详细信息,请参阅 使用和管理 Azure CLI 中的扩展。
运行 az version 以查找安装的版本和依赖库。 若要升级到最新版本,请运行 az upgrade。
创建群集
登录到 Azure 订阅。 如果你打算使用 Azure Cloud Shell,请在代码块的右上角选择“试用”。 否则,请输入以下命令:
az login # If you have multiple subscriptions, set the one to use # az account set --subscription "SUBSCRIPTIONID"
设置环境变量。 本文中的变量用法基于 Bash。 在其他环境中需要进行细微的更改。 有关用于群集创建的可能参数的完整列表,请参阅 az-hdinsight-create。
参数 DESCRIPTION --workernode-count
群集中的工作器节点数。 本文使用变量 clusterSizeInNodes
作为传递给--workernode-count
的值。--version
HDInsight 群集版本。 本文使用变量 clusterVersion
作为传递给--version
的值。 另请参阅:支持的 HDInsight 版本。--type
HDInsight 群集的类型,例如:hadoop、交互式 hive、hbase、kafka、spark、 rserver
、mlservices
。 本文使用变量clusterType
作为传递给--type
的值。 另请参阅:群集类型和配置。--component-version
各种 Hadoop 组件的版本,采用“component=version”格式的空格分隔版本。 本文使用变量 componentVersion
作为传递给--component-version
的值。 另请参阅:Hadoop 组件。将
RESOURCEGROUPNAME
、LOCATION
、CLUSTERNAME
、STORAGEACCOUNTNAME
和PASSWORD
替换为所需的值。 根据需要更改其他变量的值。 然后输入 CLI 命令。export resourceGroupName=RESOURCEGROUPNAME export ___location=LOCATION export clusterName=CLUSTERNAME export AZURE_STORAGE_ACCOUNT=STORAGEACCOUNTNAME export httpCredential='PASSWORD' export sshCredentials='PASSWORD' export AZURE_STORAGE_CONTAINER=$clusterName export clusterSizeInNodes=1 export clusterVersion=4.0 export clusterType=hadoop export componentVersion=Hadoop=3.1
输入以下命令来创建资源组:
az group create \ --___location $___location \ --name $resourceGroupName
有关有效位置的列表,请使用
az account list-locations
命令,并使用name
值中的位置之一。输入以下命令来创建 Azure 存储帐户:
# Note: kind BlobStorage is not available as the default storage account. az storage account create \ --name $AZURE_STORAGE_ACCOUNT \ --resource-group $resourceGroupName \ --https-only true \ --kind StorageV2 \ --___location $___location \ --sku Standard_LRS
输入以下命令来从 Azure 存储帐户中提取主键,然后将其存储在某个变量中:
export AZURE_STORAGE_KEY=$(az storage account keys list \ --account-name $AZURE_STORAGE_ACCOUNT \ --resource-group $resourceGroupName \ --query [0].value -o tsv)
输入以下命令来创建 Azure 存储容器:
az storage container create \ --name $AZURE_STORAGE_CONTAINER \ --account-key $AZURE_STORAGE_KEY \ --account-name $AZURE_STORAGE_ACCOUNT
输入以下命令来创建 HDInsight 群集:
az hdinsight create \ --name $clusterName \ --resource-group $resourceGroupName \ --type $clusterType \ --component-version $componentVersion \ --http-password $httpCredential \ --http-user admin \ --___location $___location \ --workernode-count $clusterSizeInNodes \ --ssh-password $sshCredentials \ --ssh-user sshuser \ --storage-account $AZURE_STORAGE_ACCOUNT \ --storage-account-key $AZURE_STORAGE_KEY \ --storage-container $AZURE_STORAGE_CONTAINER \ --version $clusterVersion
重要
HDInsight 群集具有各种不同的类型,与该群集进行优化的工作负载或技术相对应。 不支持在一个群集上创建合并了多种类型的群集,例如 HBase。
可能需要几分钟时间才能完成群集创建过程。 通常大约为 15 分钟。
清理资源
完成本文后,可以删除群集。 有了 HDInsight,便可以将数据存储在 Azure 存储中,因此可以在群集不用时安全地删除群集。 此外,还需要为 HDInsight 群集付费,即使不用也是如此。 由于群集费用数倍于存储空间费用,因此在群集不用时删除群集可以节省费用。
输入以下命令中的全部或部分来删除资源:
# Remove cluster
az hdinsight delete \
--name $clusterName \
--resource-group $resourceGroupName
# Remove storage container
az storage container delete \
--account-name $AZURE_STORAGE_ACCOUNT \
--name $AZURE_STORAGE_CONTAINER
# Remove storage account
az storage account delete \
--name $AZURE_STORAGE_ACCOUNT \
--resource-group $resourceGroupName
# Remove resource group
az group delete \
--name $resourceGroupName
疑难解答
如果在创建 HDInsight 群集时遇到问题,请参阅访问控制要求。
后续步骤
使用 Azure CLI 成功创建 HDInsight 群集后,请参考以下主题来了解如何使用群集: