Use GTM and CLB instances to implement cross-region load balancing
When services in one region fail, Global Traffic Manager (GTM) detects the failure through health checks and automatically reroutes DNS traffic to a healthy region—keeping your service online without manual intervention. This tutorial shows you how to pair GTM with Classic Load Balancer (CLB) instances in two regions to build a cross-region active-passive architecture.
How it works
GTM operates at the DNS layer. It monitors the health of your CLB instances in each region and responds to DNS queries with the IP address of a healthy endpoint. When a regional failure is detected, GTM stops returning that region's IP address and directs all traffic to the other region.
GTM can manage IP addresses from Alibaba Cloud and other service providers, enabling hybrid cloud deployments.
In this tutorial, Elastic Compute Service (ECS) instances run behind CLB instances in two regions—China (Hangzhou) and China (Beijing). GTM is configured to route traffic to both regions under normal conditions and to fail over to the surviving region when one becomes unavailable.
For more information about GTM, see What is Global Traffic Manager?.
Prerequisites
Before you begin, make sure you have:
-
Internet-facing CLB instances created in each region. See Create and manage a CLB instance.
-
A vServer group created for each CLB instance, with ECS instances added and applications deployed. See Create and manage a vServer group.
-
A listener created for each CLB instance. All listeners must use the same port. See Add a TCP listener, Add a UDP listener, Add an HTTP listener, and Add an HTTPS listener.
-
The public IP address of each CLB instance is accessible.
-
A registered domain name with an Internet content provider (ICP) number. See Register a domain name on Alibaba Cloud and ICP filing process.
Step 1: Purchase a GTM instance
-
Log in to the Alibaba Cloud DNS console.
-
In the left-side navigation pane, click Global Traffic Manager.
-
Click Purchase Instance.
-
On the purchase page, configure the parameters and complete the payment. The default settings are used in this tutorial.
Step 2: Configure GTM
Configure the GTM instance
-
On the Global Traffic Manager page, click the ID of the GTM instance, or click Settings in the Actions column.
-
If this is your first time configuring GTM, select Advanced Settings in the Select Configuration Method dialog box.
-
On the Basic Settings tab, click Modify. In the Modify Basic Settings panel, configure the following parameters and click OK.
Setting
Value
CNAME (Internet)
Select Custom Access Domain Name. Enter the prefix and suffix of your domain name. After you save the settings, a CNAME record is automatically generated that maps your domain to the GTM instance.
Global TTL Period
Set the duration that DNS resolvers cache the IP address.
Alert Group
Select a contact group to receive notifications when an endpoint becomes unhealthy. The CloudMonitor alert group appears in the list by default. See Create an alert contact or alert contact group.
Configure address pools
Each CLB instance must be placed in a separate address pool. This tutorial uses two address pools—one for each CLB instance.
Do not add both CLB instances to the same address pool. GTM requires each CLB public IP address to be in a different pool to route traffic independently.
-
On the Address Pools tab, click Create Address Pool.
-
In the Create Address Pool panel, set the Address parameter in the Addresses list to the public IP address of one of your CLB instances. Configure other parameters or use the default values, then click OK.
-
Repeat the preceding steps to create a second address pool with the public IP address of the other CLB instance.
Configure health checks
Configure a health check for each address pool so that GTM can detect regional failures.
-
On the Address Pools tab, find an address pool and click the
icon to expand its configuration. -
Click Add next to Health Check. In the Modify Health Check Settings panel, set the health check protocol and port to match the backend protocol and port of your CLB listener. Configure the remaining parameters or use the default values, then click OK.
-
Repeat the preceding steps to configure a health check for the other address pool.
Configure an access policy
-
On the Basic Settings tab, go to the Access Policy Type section and click Settings in the Geographical Location-based Access Policy card.
-
On the Geographical Location-based Access Policy page, click Create Access Policy.
-
In the Create Access Policy panel, configure the following parameters and click OK.
Setting
Value
DNS Request Source
Select Global to route traffic from different regions or Internet service providers (ISPs) to the address pools.
Primary Address Pool Set
Select the address pools in all regions.
Step 3: Verify the result
Verify both normal operation and failover behavior.
Test normal operation:
-
Open a browser and access your service using the CNAME generated in Step 2.
-
Confirm that the service loads successfully.
Test failover:
-
Disable the backend services in one of the regions to simulate a fault.
-
Wait a few seconds for the health check to detect the failure, then refresh the page.
-
Confirm that the service is still accessible—traffic has been rerouted to the other region.
To view detailed failover logs, go to the Alert Logs tab of your GTM instance.
What's next
Application Load Balancer (ALB) and Network Load Balancer (NLB) also support cross-region architectures. Choose the load balancer type that fits your protocol and traffic requirements: