使用 Azure PowerShell 在 HDInsight 中建立以 Linux 為基礎的叢集

Azure PowerShell 是功能強大的指令碼環境,可讓您在 Microsoft Azure 中控制和自動化工作量的部署與管理。 本文件提供如何使用 Azure PowerShell 建立以 Linux 為基礎之 HDInsight 叢集的相關資訊。 其中也包含一個範例指令碼。

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

必要條件

注意

建議您使用 Azure Az PowerShell 模組來與 Azure 互動。 請參閱安裝 Azure PowerShell 以開始使用。 若要了解如何移轉至 Az PowerShell 模組,請參閱將 Azure PowerShell 從 AzureRM 移轉至 Az

Azure PowerShell Az 模組。

建立叢集

警告

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

若要使用 Azure PowerShell 建立 HDInsight 叢集,您必須完成下列程序:

  • 建立 Azure 資源群組
  • 建立 Azure 儲存體帳戶
  • 建立 Azure Blob 容器
  • 建立 HDInsight 叢集

注意

目前不支援使用 PowerShell 建立包含 Azure Data Lake Storage Gen2 的 HDInsight 叢集。

下列指令碼示範如何建立新叢集:

# Login to your Azure subscription
$context = Get-AzContext
if ($context -eq $null) 
{
    Connect-AzAccount
}
$context

# If you have multiple subscriptions, set the one to use
# $subscriptionID = "<subscription ID to use>"
# Select-AzSubscription -SubscriptionId $subscriptionID

# Get user input/default values
$resourceGroupName = Read-Host -Prompt "Enter the resource group name"
$location = Read-Host -Prompt "Enter the Azure region to create resources in"

# Create the resource group
New-AzResourceGroup -Name $resourceGroupName -Location $location

$defaultStorageAccountName = Read-Host -Prompt "Enter the name of the storage account"

# Create an Az.Storage account and container
New-AzStorageAccount `
    -ResourceGroupName $resourceGroupName `
    -Name $defaultStorageAccountName `
    -Type Standard_LRS `
    -Location $location
$defaultStorageAccountKey = (Get-AzStorageAccountKey `
                                -ResourceGroupName $resourceGroupName `
                                -Name $defaultStorageAccountName)[0].Value

$storageAccountResourceId = (Get-AzStorageAccount -ResourceGroupName $resourceGroupName -AccountName $defaultStorageAccountName).Id  

$defaultStorageContext = New-AzStorageContext `
                                -StorageAccountName $defaultStorageAccountName `
                                -StorageAccountKey $defaultStorageAccountKey

# Get information for the HDInsight cluster
$clusterName = Read-Host -Prompt "Enter the name of the HDInsight cluster"
# Cluster login is used to secure HTTPS services hosted on the cluster
$httpCredential = Get-Credential -Message "Enter Cluster login credentials" -UserName "admin"
# SSH user is used to remotely connect to the cluster using SSH clients
$sshCredentials = Get-Credential -Message "Enter SSH user credentials" -UserName "sshuser"

# Default cluster size (# of worker nodes), version, type, and OS
$clusterSizeInNodes = "4"
$clusterVersion = "5.1"
$clusterType = "Hadoop"
$clusterOS = "Linux"
# Set the storage container name to the cluster name
$defaultBlobContainerName = $clusterName

# Create a blob container. This holds the default data store for the cluster.
New-AzStorageContainer `
    -Name $clusterName -Context $defaultStorageContext 

# Create the HDInsight cluster
    New-AzHDInsightCluster `
    -ResourceGroupName $resourceGroupName `
    -ClusterName $clusterName `
    -Location $location `
    -ClusterSizeInNodes $clusterSizeInNodes `
    -ClusterType $clusterType `
    -OSType $clusterOS `
    -Version $clusterVersion `
    -HttpCredential $httpCredential `
    -StorageAccountResourceId $storageAccountResourceId `
    -StorageAccountKey $defaultStorageAccountKey `
    -StorageContainer $defaultBlobContainerName `
    -SshCredential $sshCredentials

您為叢集登入指定的值會用來建立叢集的 Hadoop 使用者帳戶。 請使用此帳戶來連線叢集上裝載的服務,像是 web UI 或 REST API。

您為 SSH 使用者指定的值會用來建立叢集的 SSH 使用者。 使用此帳戶在叢集上啟動遠端 SSH 工作階段並執行工作。 如需詳細資訊,請參閱搭配 HDInsight 使用 SSH 文件。

重要

如果您規劃使用 32 個以上的背景工作角色節點 (在建立叢集時或在建立後調整叢集時),則您也必須指定具有至少 8 個核心和 14 GB RAM 的前端節點大小。

如需節點大小和相關成本的詳細資訊,請參閱 HDInsight 定價

建立叢集可能需要花費 20 分鐘的時間。

建立叢集:設定物件

您也可以使用 New-AzHDInsightClusterConfig Cmdlet 建立 HDInsight 設定物件。 然後,您可以修改此設定物件來啟用叢集的其他設定選項。 最後,請使用 New-AzHDInsightCluster Cmdlet 的 -Config 參數以使用設定。

自訂叢集

選取叢集

警告

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

疑難排解

如果您在建立 HDInsight 叢集時遇到問題,請參閱存取控制需求

下一步

您已成功建立 HDInsight 叢集,請使用下列資源,了解如何使用您的叢集。

Apache Hadoop 叢集

Apache HBase 叢集

Apache Spark 叢集