使用 Azure CLI 建立 HDInsight 叢集

本檔中的步驟會逐步解說如何使用 Azure CLI 建立 HDInsight 4.0 叢集。

警告

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

如果您沒有 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、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
    
  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 叢集