共用方式為


建立具有跨訂用帳戶後端的全域負載平衡器

在本文中,您將了解如何建立具有跨訂用帳戶後端的全域負載平衡器。

跨訂用帳戶負載平衡器可以參考位於負載平衡器以外不同訂用帳戶中的虛擬網路。 此功能可讓您在一個訂用帳戶中部署負載平衡器,並參考另一個訂用帳戶中的虛擬網路。

必要條件

  • 兩個 Azure 訂用帳戶。
  • 具有有效訂用帳戶的 Azure 帳戶。 免費建立帳戶
  • 部署在 Azure 訂用帳戶 A 中的全域公用 IP 位址,位於全域負載平衡器首頁區域
  • 部署在 Azure 訂用帳戶 A 中的區域負載平衡器。
  • 已在本地安裝 Azure PowerShell 或 Azure Cloud Shell。

如果您選擇在本機安裝和使用 PowerShell,本文會要求使用 Azure PowerShell 模組版本 5.4.1 或更新版本。 執行 Get-Module -ListAvailable Az 以尋找安裝的版本。 如果您需要升級,請參閱安裝 Azure PowerShell 模組。 如果正在本機執行 PowerShell,也需要執行 Connect-AzAccount,以建立與 Azure 的連線。

重要

所有程式碼範例都會使用範例名稱和預留位置。 請務必以您環境中的值取代這些值。 需要取代的值會以角括弧括住,如下所示:<example value>

登入 Azure

使用 Azure PowerShell,您可以使用 登入 AzureConnect-AzAccount,並將訂用帳戶內容變更為 Azure 訂用Set-AzContext帳戶 A。然後使用 和Get-AzLoadBalancerFrontendIpConfig取得區域負載平衡器資訊Get-AzLoadBalancer。 您需要來自環境的 Azure 訂用帳戶識別碼、資源群組名稱和虛擬網路名稱。


# Sign in to Azure
Connect-AzAccount

# Set the subscription context to Azure Subscription A
Set-AzContext -Subscription '<Subscription ID of Subscription A>'     

# Get the Virtual Network information with Get-AzVirtualNetwork
$rlb= @{
    Name = 'load-balancer-regional'
    ResourceGroupName = 'resource-group-a'
}
$rlbinfo = Get-AzLoadBalancer @rlb
$rlbfe = Get-AzLoadBalancerFrontendIpConfig @rlbinfo

建立資源群組

在本節中,您會在 Azure 訂用帳戶 B 中建立資源群組。此資源群組適用於所有與您負載平衡器相關聯的資源。

使用 Azure PowerShell,您可以使用 Set-AzContext 切換訂用帳戶內容,並使用 New-AzResourceGroup 建立資源群組。


# Set the subscription context to Azure Subscription B
Set-AzContext -Subscription '<Azure Subscription B>'  

# Create a resource group  
$rg = @{
    Name = 'resource-group-b'
    Location = 'eastus2'
}
New-AzResourceGroup @rg

注意

為負載平衡器建立資源群組時,請使用與 Azure 訂用帳戶 A 中的虛擬網路相同的 Azure 區域。

建立全域負載平衡器

在本節中,您會建立全域負載平衡器所需的資源。 全域標準 SKU 公用 IP 用於全域負載平衡器的前端。

使用 Azure PowerShell,您可以:

# Create global IP address for load balancer
$ip = @{
    Name = 'public-IP-global'
    ResourceGroupName = 'resource-group-b'
    Location = 'eastus2'
    Sku = 'Standard'
    Tier = 'Global'
    AllocationMethod = 'Static'
}
$publicIP = New-AzPublicIpAddress @ip

# Create frontend configuration
$fe = @{
    Name = 'front-end-config-global'
    PublicIpAddress = $publicIP
}
$feip = New-AzLoadBalancerFrontendIpConfig @fe

# Create backend address pool
$be = @{
    Name = 'backend-pool-global'
}
$bepool = New-AzLoadBalancerBackendAddressPoolConfig @be

# Create the load balancer rule
$rul = @{
    Name = 'HTTP-rule-global'
    Protocol = 'tcp'
    FrontendPort = '80'
    BackendPort = '80'
    FrontendIpConfiguration = $feip
    BackendAddressPool = $bepool
}
$rule = New-AzLoadBalancerRuleConfig @rul

# Create global load balancer resource
$lbp = @{
    ResourceGroupName = 'resource-group-b'
    Name = 'load-balancer-global'
    Location = ‘eastus2’
    Sku = 'Standard'
    Tier = 'Global'
    FrontendIpConfiguration = $feip
    BackendAddressPool = $bepool
    LoadBalancingRule = $rule
}
$lb = New-AzLoadBalancer @lbp

將負載平衡器前端新增至全域負載平衡器

在本節中,您會將前端 IP 組態新增至全域負載平衡器。

使用 Azure PowerShell,您可以:


## Create the global backend address pool configuration for region 2 ##
$rlbbaf = @{
    Name = 'backend-pool-config-regional'
    LoadBalancerFrontendIPConfigurationId = $rlbfe.Id
}
$beaddressconfigRLB = New-AzLoadBalancerBackendAddressConfig @region2ap

## Apply the backend address pool configuration for the global load balancer ##
$bepoolcr = @{
    ResourceGroupName = 'resource-group-b'
    LoadBalancerName = 'load-balancer-global'
    Name = 'backend-pool-global'
    LoadBalancerBackendAddress = $beaddressconfigRLB
}
Set-AzLoadBalancerBackendAddressPool @bepoolcr