Tutorial: Create a cross-region Azure Load Balancer
บทความ
A cross-region load balancer ensures a service is available globally across multiple Azure regions. If one region fails, the traffic is routed to the next closest healthy regional load balancer.
In this tutorial, you learn how to:
Create cross-region load balancer.
Create a backend pool containing two regional load balancers.
Create a load balancer rule.
Test the load balancer.
You can use the Azure portal, Azure CLI, or Azure PowerShell to complete this tutorial.
Append the name of the load balancers and virtual machines in each region with a -R1 and -R2.
Azure CLI installed locally or Azure Cloud Shell.
If you choose to install and use the CLI locally, this quickstart requires Azure CLI version 2.0.28 or later. To find the version, run az --version. If you need to install or upgrade, see Install the Azure CLI. When running Azure CLI locally, you'll need to sign in with az login to create a connection with Azure.
An Azure subscription. If you don’t have an Azure subscription, create a free account before you begin.
Two standard sku Azure Load Balancers with backend pools deployed in two different Azure regions.
Azure PowerShell installed locally or Azure Cloud Shell.
If you choose to install and use PowerShell locally, this article requires the Azure PowerShell module version 5.4.1 or later. Run Get-Module -ListAvailable Az to find the installed version. If you need to upgrade, see Install Azure PowerShell module. If you're running PowerShell locally, you also need to run Connect-AzAccount to create a connection with Azure.
Create cross-region load balancer
In this section, you create a cross-region load balancer with a public IP address, a frontend IP configuration, a backend pool with region load balancers added, and a load balancer rule.
In the search box at the top of the portal, enter Load balancer. Select Load balancer in the search results.
In the Load balancer page, select Create.
In the Basics tab of the Create load balancer page, enter, or select the following information:
Setting
Value
Project details
Subscription
Select your subscription.
Resource group
Select Create new and enter CreateCRLBTutorial-rg in the text box.
Instance details
Name
Enter myLoadBalancer-cr
Region
Select (US) East US.
Type
Select Public.
SKU
Leave the default of Standard.
Tier
Select Global
Select Next: Frontend IP configuration at the bottom of the page.
In Frontend IP configuration, select + Add a frontend IP.
Enter LoadBalancerFrontend in Name in Add frontend IP address.
Select IPv4 or IPv6 for IP version.
In Public IP address, select Create new. Enter myPublicIP-cr in Name. Select Save for the Add Public IP Address Dialog.
Select Save.
Select Next: Backend pools at the bottom of the page.
In Backend pools, select + Add a backend pool.
Enter myBackendPool-cr in Name in Add backend pool.
In Load balancers, select myLoadBalancer-r1 or your first regional load balancer in the Load balancer pull-down box. Verify the Frontend IP configuration and IP address correspond with myLoadBalancer-r1.
Select myLoadBalancer-r2 or your second regional load balancer in the Load balancer pull-down box. Verify the Frontend IP configuration and IP address correspond with myLoadBalancer-r2.
Select Add.
Select Next: Inbound rules at the bottom of the page.
In Inbound rules, select + Add a load balancing rule.
In Add load balancing rule, enter or select the following information:
Setting
Value
Name
Enter myHTTPRule-cr.
IP Version
Select IPv4 or IPv6 for IP Version.
Frontend IP address
Select LoadBalancerFrontend.
Protocol
Select TCP.
Port
Enter 80.
Backend pool
Select myBackendPool-cr.
Session persistence
Select None.
Idle timeout (minutes)
Enter or move the slider to 15.
TCP reset
Select Enabled.
Floating IP
Leave the default of Disabled.
Select Add.
Select Review + create at the bottom of the page.
Select Create in the Review + create tab.
Note
Cross region load-balancer deployment is listed to specific home Azure regions. For the current list, see Home regions in Azure for cross region load balancer.
Create a resource group
An Azure resource group is a logical container into which Azure resources are deployed and managed.
In this section, you place the resource IDs of two regional load balancers frontends into variables, and then use the variables to add the frontends to the backend address pool of the cross-region load balancer.
## Place the region one load balancer configuration in a variable ##
$region1 = @{
Name = 'myLoadBalancer-R1'
ResourceGroupName = 'CreatePubLBQS-rg-r1'
}
$R1 = Get-AzLoadBalancer @region1
## Place the region two load balancer configuration in a variable ##
$region2 = @{
Name = 'myLoadBalancer-R2'
ResourceGroupName = 'CreatePubLBQS-rg-r2'
}
$R2 = Get-AzLoadBalancer @region2
## Place the region one load balancer frontend configuration in a variable ##
$region1fe = @{
Name = 'MyFrontEnd-R1'
LoadBalancer = $R1
}
$R1FE = Get-AzLoadBalancerFrontendIpConfig @region1fe
## Place the region two load balancer frontend configuration in a variable ##
$region2fe = @{
Name = 'MyFrontEnd-R2'
LoadBalancer = $R2
}
$R2FE = Get-AzLoadBalancerFrontendIpConfig @region2fe
## Create the cross-region backend address pool configuration for region 1 ##
$region1ap = @{
Name = 'MyBackendPoolConfig-R1'
LoadBalancerFrontendIPConfigurationId = $R1FE.Id
}
$beaddressconfigR1 = New-AzLoadBalancerBackendAddressConfig @region1ap
## Create the cross-region backend address pool configuration for region 2 ##
$region2ap = @{
Name = 'MyBackendPoolConfig-R2'
LoadBalancerFrontendIPConfigurationId = $R2FE.Id
}
$beaddressconfigR2 = New-AzLoadBalancerBackendAddressConfig @region2ap
## Apply the backend address pool configuration for the cross-region load balancer ##
$bepoolcr = @{
ResourceGroupName = 'myResourceGroupLB-CR'
LoadBalancerName = 'myLoadBalancer-CR'
Name = 'myBackEndPool-CR'
LoadBalancerBackendAddress = $beaddressconfigR1,$beaddressconfigR2
}
Set-AzLoadBalancerBackendAddressPool @bepoolcr
In this section, you test the cross-region load balancer. You connect to the public IP address in a web browser. You stop the virtual machines in one of the regional load balancer backend pools and observe the failover.
Find the public IP address for the load balancer on the Overview screen. Select All services in the left-hand menu, select All resources, and then select myPublicIP-cr.
Copy the public IP address, and then paste it into the address bar of your browser. The default page of IIS Web server is displayed on the browser.
Stop the virtual machines in the backend pool of one of the regional load balancers.
Refresh the web browser and observe the failover of the connection to the other regional load balancer.
In this section, you test the cross-region load balancer. You connect to the public IP address in a web browser. You stop the virtual machines in one of the regional load balancer backend pools and observe the failover.
az network public-ip show \
--resource-group myResourceGroupLB-CR \
--name PublicIPmyLoadBalancer-CR \
--query ipAddress \
--output tsv
Copy the public IP address, and then paste it into the address bar of your browser. The default page of IIS Web server is displayed on the browser.
Stop the virtual machines in the backend pool of one of the regional load balancers.
Refresh the web browser and observe the failover of the connection to the other regional load balancer.
In this section, you test the cross-region load balancer. You connect to the public IP address in a web browser. You stop the virtual machines in one of the regional load balancer backend pools and observe the failover.