限制 Azure HDInsight 中的公開連線能力

在 Azure HDInsight 的預設虛擬網路架構 (部分機器翻譯) 中,HDInsight 資源提供者會透過公用網路與叢集進行通訊。 在本文中,您將了解可用來建立受限制的 HDInsight 叢集的進階控制項,其中輸入連線僅限於私人網路。

如果您想要 HDInsight 叢集間的公用連線能力以及相依資源,請考慮遵循控制 Azure HDInsight 中的網路流量中的指導方針,限制叢集的連線能力。 除了限制公用連線之外,您還可以將已啟用 Azure Private Link 相依性資源設定為搭配 HDInsight 叢集使用。

下圖顯示當 resourceProviderConnection 已設定為「輸出」時,潛在的 HDInsight 虛擬網路架構會如下圖所示:

Diagram of the HDInsight architecture using an outbound resource provider connection.

注意

限制公用連線能力是啟用 Private Link 的必要條件,不應視為相同功能。

將受限制的叢集初始化

根據預設,HDInsight 資源提供者會使用公用 IP 位址,與叢集進行「輸入」連線。 當 resourceProviderConnection 網路屬性設定為「輸出」時,會反轉 HDInsight 資源提供者的連線,讓連線一律從叢集內部起始,並移出至資源提供者。

在此設定中,若沒有輸入連線,就不需要在網路安全性群組中設定輸入服務標籤。 也不需要透過使用者定義的路由許可防火牆或網路虛擬裝置。

注意

Microsoft Azure Government 中的實作可能仍然需要網路安全性群組和使用者定義路由中的輸入服務標籤。

建立叢集之後,請新增限制 HDInsight 叢集所需的 DNS 記錄,以設定適當的 DNS 解析。 下列標準名稱 DNS 記錄 (CNAME) 會在 Azure 管理的公用 DNS 區域中建立:azurehdinsight.net

<clustername>    CNAME    <clustername>-int

若要使用完整功能變數名稱 (FQDN) 來存取叢集,您可以視需要使用下列任一技術:

  • 直接使用內部負載平衡器的私人 IP 位址。
  • 使用您自己的私人 DNS 區域來覆寫叢集端點。 在此情況下,區域功能變數名稱稱必須為 azurehdinsight.net

例如,針對私人 DNS 區域 azurehdinsight.net,您可以視需要新增私人 IP 位址:

<clustername>        A   10.0.0.1
<clustername-ssh>    A   10.0.0.2

注意

我們不建議將受限制的叢集 (和 azurehdinsight.net 的私人 DNS 區域) 放在相同的虛擬網路中,作為啟用公用連線的其他叢集。 這可能會導致非預期的 DNS 解析行為或衝突。

為了簡化 DNS 設定,我們會在叢集 GET 回應中傳回 FQDN 和對應的私人 IP 位址。 您可以使用此 PowerShell 程式碼片段作為開始:

<#
    This script is an example to help you get started with automation and can be adjusted based on your needs.
    This script assumes:
    - The HDInsight cluster has already been created, and the context where this script is run has permissions to read/write resources in the same resource group.
    - The private DNS zone resource exists in the same subscription as the HDInsight cluster.
We recommend that you use the latest version of the Az.HDInsight module.

#>
$subscriptionId = "<Replace with subscription for deploying HDInsight clusters, and containing private DNS zone resource>"

$clusterName = "<Replace with cluster name>"
$clusterResourceGroupName = "<Replace with resource group name>"

# For example, azurehdinsight.net for public cloud.
$dnsZoneName = "<Replace with private DNS zone name>"
$dnsZoneResourceGroupName = "<Replace with private DNS zone resource group name>"

Connect-AzAccount -SubscriptionId $subscriptionId

# 1. Get cluster endpoints
$clusterEndpoints = $(Get-AzHDInsightCluster -ClusterName $clusterName ` -ResourceGroupName $clusterResourceGroupName).ConnectivityEndpoints

$endpointMapping = @{}

foreach($endpoint in $clusterEndpoints)
{
    $label = $endpoint.Location.ToLower().Replace(".$dnsZoneName".ToLower(), "")
    $ip = $endpoint.PrivateIPAddress

    $endpointMapping.Add($label, $ip)
}

# 2. Confirm that the DNS zone exists.
Get-AzPrivateDnsZone -ResourceGroupName $dnsZoneResourceGroupName -Name $dnsZoneName -ErrorAction Stop

# 3. Update DNS entries for the cluster in the private DNS zone:
#    - If the entries already exist, update to the new IP.
#    - If the entries don't exist, create them.
$recordSets = Get-AzPrivateDnsRecordSet -ZoneName $dnsZoneName -ResourceGroupName $dnsZoneResourceGroupName -RecordType A

foreach($label in $endpointMapping.Keys)
{
    $updateRecord = $null

    foreach($record in $recordSets)
    {
        if($record.Name -eq $label)
        {
            $updateRecord = $record
            break;
        }
        
    }

    if($null -ne $updateRecord)
    {
        $updateRecord.Records[0].Ipv4Address = $endpointMapping[$label]
        Set-AzPrivateDnsRecordSet -RecordSet $updateRecord | Out-Null
    }
    else
    {
        New-AzPrivateDnsRecordSet `
            -ResourceGroupName $dnsZoneResourceGroupName `
            -ZoneName $dnsZoneName `
            -Name $label `
            -RecordType A `
            -Ttl 3600 `
            -PrivateDnsRecord (New-AzPrivateDnsRecordConfig -Ipv4Address $endpointMapping[$label]) | Out-Null
    }
}

resourceProviderConnection 設定為「輸出」也可讓您使用私人端點來存取叢集特定資源。 這些資源包括:

  • 儲存體:Azure Data Lake Storage Gen2 與 Azure Blob 儲存體
  • SQL 中繼存放區:Apache Ranger、Ambari、Oozie 和 Hive
  • Azure Key Vault

不需要針對這些資源使用私人端點。 但如果打算針對這些資源使用私人端點,您必須先建立資源並設定私人端點和 DNS 項目,才能建立 HDInsight 叢集。 所有這些資源都應該可從叢集子網內部存取,不論是透過私人端點或其他方式存取。 如果您打算使用私人端點,建議您利用叢集子網路。

當您透過私人端點連線至 Azure Data Lake Storage Gen2 時,請確定 Gen2 儲存體帳戶同時設定了 blobdfs 的端點。 如需詳細資訊,請參閱建立新的私人端點 (部分機器翻譯)。

使用防火牆 (選擇性)

HDInsight 叢集仍然可以連線到公用網際網路,以取得輸出相依性。 如果您想要限制存取,您可以設定防火牆 (部分機器翻譯),但並非必要。

建立叢集

下列 JSON 程式碼片段包含兩個網路屬性,您必須在 Azure Resource Manager 範本中設定,才能建立私人 HDInsight 叢集:

networkProperties: {
    "resourceProviderConnection": "Outbound"
}

如需具有許多 HDInsight 企業安全性功能 (包括 Private Link 在內) 的完整範本,請參閱 HDInsight 企業安全性範本

若要使用 PowerShell 建立叢集,請參閱範例

若要使用 Azure CLI 建立叢集,請參閱範例

下一步