使用 Azure CLI 创建 HDInsight 群集

本文介绍了使用 Azure CLI 创建 HDInsight 4.0 群集的相关步骤。

警告

HDInsight 群集是基于分钟按比例计费,而不管用户是否使用它们。 请务必在使用完群集之后将其删除。 请参阅如何删除 HDInsight 群集

如果没有 Azure 试用版订阅,请在开始前创建一个试用版订阅

先决条件

  • 如需在本地运行 CLI 参考命令,请安装 Azure CLI。 如果在 Windows 或 macOS 上运行,请考虑在 Docker 容器中运行 Azure CLI。 有关详细信息,请参阅如何在 Docker 容器中运行 Azure CLI

    • 如果使用的是本地安装,请使用 az login 命令登录到 Azure CLI。 若要完成身份验证过程,请遵循终端中显示的步骤。 有关其他登录选项,请参阅使用 Azure CLI 登录

    • 出现提示时,请在首次使用时安装 Azure CLI 扩展。 有关扩展详细信息,请参阅使用 Azure CLI 的扩展

    • 运行 az version 以查找安装的版本和依赖库。 若要升级到最新版本,请运行 az upgrade

创建群集

  1. 登录到 Azure 订阅。

    az login
    
    # If you have multiple subscriptions, set the one to use
    # az account set --subscription "SUBSCRIPTIONID"
    
  2. 设置环境变量。 本文中的变量用法基于 Bash。 其他环境需要稍有变化。 有关用于群集创建的可能参数的完整列表,请参见 az-hdinsight-create

    参数 说明
    --workernode-count 群集中的工作器节点数。 本文使用变量 clusterSizeInNodes 作为传递给 --workernode-count 的值。
    --version HDInsight 群集版本。 本文使用变量 clusterVersion 作为传递给 --version 的值。 另请参阅:支持的 HDInsight 版本
    --type HDInsight 群集的类型,例如:hadoop、交互式配置单元、hbase、kafka、spark、rservermlservices。 本文使用变量 clusterType 作为传递给 --type 的值。 另请参阅:群集类型和配置
    --component-version 各种 Hadoop 组件的版本,采用“component=version”格式的空格分隔版本。 本文使用变量 componentVersion 作为传递给 --component-version 的值。 另请参阅:Hadoop 组件

    RESOURCEGROUPNAMELOCATIONCLUSTERNAMESTORAGEACCOUNTNAMEPASSWORD 替换为所需的值。 根据需要更改其他变量的值。 然后输入 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
    
  3. 输入以下命令来创建资源组

    az group create \
        --location $location \
        --name $resourceGroupName
    

    有关有效位置的列表,请使用 az account list-locations 命令,并使用 name 值中的位置之一。

  4. 输入以下命令来创建 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
    
  5. 输入以下命令来从 Azure 存储帐户中提取主键,然后将其存储在某个变量中:

    export AZURE_STORAGE_KEY=$(az storage account keys list \
        --account-name $AZURE_STORAGE_ACCOUNT \
        --resource-group $resourceGroupName \
        --query [0].value -o tsv)
    
  6. 输入以下命令来创建 Azure 存储容器

    az storage container create \
        --name $AZURE_STORAGE_CONTAINER \
        --account-key $AZURE_STORAGE_KEY \
        --account-name $AZURE_STORAGE_ACCOUNT
    
  7. 输入以下命令来创建 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 群集后,请参考以下主题来了解如何使用群集:

Apache Hadoop 群集

Apache HBase 群集