Add cross-region servers to an NLB
Network Load Balancer (NLB) allows you to add Elastic Compute Service (ECS) instances from different regions as backend servers. This topic explains how to use an NLB instance with Cloud Enterprise Network (CEN) transit routers to forward requests across regions.
Scenario
An enterprise has a VPC (VPC1) in the China (Chengdu) region that contains an NLB instance and an ECS instance (ECS1). ECS1 serves as a client to test cross-region load balancing. The enterprise also has two other VPCs: VPC2 in China (Shanghai) and VPC3 in China (Qingdao). These VPCs contain ECS2 and ECS3, respectively, both of which run the same service.
To achieve cross-region high availability, the enterprise will add the ECS instances in VPC2 and VPC3 as backend servers to the NLB instance in VPC1. This guide shows how to add backend servers to an NLB instance across regions.
Limitations
Backend server limitations
-
You can add cross-region backend servers only by specifying their IP addresses.
-
Only private IP addresses are supported; public IP addresses cannot be used.
Transit router and VPC limitations
An Enterprise Edition transit router creates an elastic network interface (ENI) on a vSwitch in a specified zone. This ENI serves as the entry point for traffic from the VPC to the Enterprise Edition transit router. When you create a VPC, you must create at least one vSwitch in a zone supported by the Enterprise Edition transit router. See Regions and zones supported by Enterprise Edition transit routers for more information.
Prerequisites
-
Before you begin, ensure you have created the resources described in the following table.
-
To learn how to create these resources, see the following topics:
-
Create an ECS instance. Ensure that the security groups for ECS2 and ECS3 allow inbound traffic on the application service port. Port 80 is used in this solution.
Step 1: Connect VPCs to transit routers
-
Log on to the CEN console, click the ID of the CEN instance that you created, and go to the page.
-
Find the TR1 instance and click Create Connection in the Actions column to connect VPC1 to TR1. On the Connection with Peer Network Instance page, configure the key parameters as shown in the following table, leave the other parameters at their default values, and then click OK.
Parameter
Description
Value
Instance Type
The type of network instance to attach to CEN.
VPC
Region
The region where the network instance is located. In this example, this is the region of VPC1.
China (Chengdu)
Account
The account that owns the network instance.
My Account
Networks
The VPC to attach to CEN.
VPC1
vSwitch
The vSwitch to attach to CEN.
A vSwitch within VPC1
-
Repeat the steps above to connect VPC2 to TR2 and VPC3 to TR3.
Step 2: Create inter-region connections
-
Log on to the Cloud Enterprise Network (CEN) console, click the instance ID, and go to the page.
-
Click Create Connection to the right of the TR1 instance to create an inter-region connection between TR1 and TR2. Configure the parameters as shown in the table, leave the other settings at their default values, and then click OK.
Parameter
Description
Value
Instance Type
The type of network instance to attach to the Cloud Enterprise Network.
inter-region connection
Region
The region where the transit router is deployed. In this example, this is the same region as TR1.
China (Chengdu)
Peer Region
The region where the peer transit router is deployed. You can select only a region that already contains a transit router.
China (Shanghai)
Bandwidth Allocation Mode
Use Cloud Data Transfer (CDT) to reduce costs for inter-region traffic in CEN. If you have not activated CDT, we recommend that you upgrade to CDT billing. Activating CDT is free of charge. You can also select a bandwidth plan based on your business requirements.
pay-by-data-transfer
-
Repeat the preceding step to create an inter-region connection between TR1 and TR3.
Step 3: Configure an NLB server group
-
Log on to the Network Load Balancer (NLB) server group console in the China (Chengdu) region and click Create Server Group.
-
Configure the parameters as described in the following table, leaving the other parameters at their default values. Then, click Create.
Parameter
Description
Value
Server Group Type
The type of backend servers to add.
IP
Server Group Name
-
test
VPC
The VPC where the server group resides.
VPC1
Resource Group
The resource group where the server group resides.
Default Resource Group
-
In the Actions column for the server group, click Modify Backend Server, and then click Add IP Address.
-
Add the IP addresses of ECS2 and ECS3. Then, click Next.
-
Set the port to the application service port on ECS2 and ECS3 (for example, port 80), leaving the other settings at their default values. Then, click OK.
Step 4: Configure the NLB listener
-
Log in to the Network Load Balancer console in the China (Chengdu) region. Find the instance and in the Actions column, click Create Listener.
-
Set the listener protocol to TCP and configure the listener port (for example, 80). Click Next.
-
Select the IP-based server group that you configured. Click Next.
-
Review the configuration and click Submit.
Step 5: Verify the results
-
Deploy test applications on ECS2 and ECS3:
-
Log in to the ECS instance console in the China (Shanghai) region. Find the ECS2 instance and click Connect in the Actions column. Use Workbench to remotely connect to the instance.
-
Run the following commands to deploy a test application on ECS2.
-
Log in to the ECS instance console in the China (Qingdao) region. Find the ECS3 instance and click Connect in the Actions column. Use Workbench to remotely connect to the instance.
-
Run the following commands to deploy a test application on ECS3.
-
-
Test availability from ECS1:
-
Log in to the ECS instance console in the China (Chengdu) region. Find the ECS1 instance and click Connect in the Actions column. Use Workbench to remotely connect to the instance.
-
Run the
sudo yum install -y telnetcommand to install Telnet. -
Run the
telnet <domain_name> <port>command. A response containing Connected to nlb-... indicates that the NLB instance can forward requests to the backend servers.[root@ym3ezdm85z35oijZ ~]# telnet xxx-xxx.cn-chengdu.elb.aliyuncs.com 80 Trying 172.16.xxx.xxx... Connected to xxx-xxx.cn-chengdu.elb.aliyuncs.com. Escape character is '^]'.
-
-
Simulate failures:
-
On ECS2, run the
systemctl stop nginx.servicecommand to stop the application. -
Wait for a few minutes, and then run the
telnet <domain_name> <port>command on ECS1 again. The command still returns a response containing Connected to nlb-.... -
On ECS2, run the
systemctl start nginx.servicecommand to restart the application. On ECS3, run thesystemctl stop nginx.servicecommand to stop the application. -
Wait for a few minutes, and then run the
telnet <domain_name> <port>command on ECS1 again. The command still returns a response containing Connected to nlb-..., as shown in the following output.[root@xxxym3ezdm85z35oijZ ~]# telnet xxx-xxx.cn-chengdu.elb.aliyuncs.com 80 Trying 172.16.xxx.xxx... Connected to xxx-xxx.cn-chengdu.elb.aliyuncs.com. Escape character is '^]'. -
This result shows that the NLB instance's availability is not affected when a single backend server fails.
-
Release resources
-
Release the CEN instance and Transit Routers (TRs):
-
Log on to the CEN console. Click the ID of the cen-test CEN instance to open the instance details page.
-
Delete the TR1 instance:
-
On the tab, click the ID of the TR1 instance to open its details page.
-
On the Intra-Region Connections tab, for each connected network instance, click Detach in the Actions column and confirm.
-
On the Inter-Region Connections tab, click Delete in the Actions column and confirm.
-
Return to the CEN instance details page. Click Delete to the right of the TR1 instance and confirm.
-
-
Repeat this process to delete the TR2 and TR3 instances.
-
Return to the CEN instances page. Find the CEN instance, click Delete in the Actions column, and confirm.
-
-
Release the ECS instances and their security groups:
-
Delete the ECS1 instance and its security group:
-
Log on to the ECS instance console for the China (Chengdu) region. Find the ECS1 instance, click the
icon in the Actions column, and then select Release. In the dialog box that appears, confirm your choice. -
Log on to the ECS security group console for the China (Chengdu) region. Select the checkbox for the custom security group of ECS1 and click Delete.
-
-
Repeat this process to delete the ECS2 and ECS3 instances and their security groups.
-
-
Delete the DNS records.
For details, see Delete a DNS Record.
-
Release the NLB resources:
-
Log on to the NLB instance console for the China (Chengdu) region. Find the NLB instance, click the
icon in the Actions column, and select Release. In the dialog box that appears, confirm your choice. -
Log on to the NLB server group console for the China (Chengdu) region. Find the server group, click the
icon in the Actions column, and select Delete. In the dialog box that appears, confirm your choice.
-
-
Release the VPC resources:
-
Log on to the VPC console for the China (Chengdu) region. Click Delete to the right of the VPC. In the dialog box that appears, select the force deletion checkbox and confirm. This deletes the VPC and its vSwitches.
-
Log on to the VPC console for the China (Shanghai) region. Click Delete to the right of the VPC. In the dialog box that appears, select the force deletion checkbox and confirm. This deletes the VPC and its vSwitches.
-
Log on to the VPC console for the China (Qingdao) region. Click Delete to the right of the VPC. In the dialog box that appears, select the force deletion checkbox and confirm. This deletes the VPC and its vSwitches.
-