本檔中的步驟會逐步解說如何使用 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 。
參數 說明 --workernode-count叢集中的背景工作角色節點數目。 本文使用 變數 clusterSizeInNodes做為傳遞至--workernode-count的值。--versionHDInsight 叢集版本。 本文使用 變數 clusterVersion做為傳遞至--version的值。 另請參閱: 支援的 HDInsight 版本。--typeHDInsight 叢集的類型,例如: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 叢集,請使用下列項目來瞭解如何使用叢集: