使用 Azure CLI 建立 HDInsight 叢集

此文件中的步驟詳細說明如何使用 Azure CLI 建立 HDInsight 4.0 叢集。

警告

不論使用與否,HDInsight 叢集都是按分鐘計費。 請務必在使用完叢集後將它刪除。 請參閱如何刪除 HDInsight 叢集

如果您沒有 Azure 訂閱,請在開始之前,先建立 Azure 免費帳戶

必要條件

建立叢集

  1. 登入 Azure 訂用帳戶。 如果您打算使用 Azure Cloud Shell,則選取程式碼區塊右上角的 [試試看]。 另外,輸入下列命令:

    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、互動式 Hive、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 叢集