Network Load Balancer (NLB) allows you to add Elastic Compute Service (ECS) instances as backend servers across regions. This topic describes how to use an NLB instance and transit routers of a Cloud Enterprise Network (CEN) instance to forward requests to servers in other regions.
Scenario
An enterprise creates a virtual private cloud (VPC) named VPC1 in the China (Chengdu) region and then creates an NLB instance and an ECS instance named ECS1 in VPC1. ECS1 is used as a client to test cross-region load balancing. In addition, the enterprise creates a VPC named VPC2 in the China (Shanghai) region and a VPC named VPC3 in the China (Qingdao) region. The enterprise creates an ECS instance named ECS2 in VPC2 and an ECS instance named ECS3 in VPC3, and deploys the same service on ECS2 and ECS3.
The enterprise wants to add the ECS instances in VPC2 and VPC3 to the NLB instance in VPC1 as backend servers to achieve cross-region high availability. The enterprise can use the solution shown in the following figure to add backend servers to the NLB instance across regions.
Limits
Limits on backend servers
If you want to add ECS instances to an NLB instance in a different region, you must add the ECS instances to a server group of the IP type.
When you add backend servers by specifying IP addresses, you can specify only private IP addresses. You cannot specify public IP addresses.
Limits on transit routers and VPCs
When you associate Enterprise Edition transit routers with VPCs, elastic network interfaces (ENIs) are automatically created. Then, the ENIs are attached to the vSwitch in each zone. The ENIs are used to forward network traffic from the VPCs to the Enterprise Edition transit routers. When you create VPCs, you must specify at least one vSwitch in each zone of the Enterprise Edition transit routers. This way, network traffic can be routed from the VPCs to the transit routers. For more information, see How transit routers work.
Prerequisites
The resources that are described in the following table are created.
For more information about how to manually create the resources that are described in the preceding table, see the following topics:
Create an instance by using the wizard The security groups of ECS2 and ECS3 must allow network traffic to go through the port of the applications to be deployed on ECS2 and ECS3. In this example, 80 is used.
A domain name is registered, an Internet content provider (ICP) number is obtained for the domain name, and a CNAME record is created to map the custom domain name to the domain name of your NLB instance. For more information, see Register a generic domain nameRegister a domain name on Alibaba Cloud, ICP filing process, and Use NLB to balance loads for IPv4 services.
Step 1: Connect the VPCs to the transit routers
Log on to the CEN console. Click the ID of the CEN instance that you want to manage. The Transit Router tab of the Basic Settings tab appears.
On the Transit Router tab, find TR1 and click Create Connection in the Actions column. On the Connection with Peer Network Instance page, configure the parameters that are described in the following table, and use the default values for other parameters. Then, click OK.
Parameter
Description
Example
Instance Type
The type of the network instance that you want to attach to CEN.
VPC
Region
The region in which the network instance resides. In this example, the region in which VPC1 is deployed is selected.
China (Chengdu)
Resource Owner ID
The ID of the peer account to which the network instance belongs.
Current Account
Network Instance and VSwitch
The VPC that you want to attach to CEN.
VPC1 and its vSwitch
Repeat the preceding step to connect VPC2 to TR2 and VPC3 to TR3.
Step 2: Create inter-region connections
Log on to the CEN console. Click the ID of the CEN instance that you want to manage. The Transit Router tab of the Basic Settings tab appears.
Find TR1 and click Create Connection in the Actions column to create an inter-region connection between TR1 and TR2. On the Connection with Peer Network Instance page, configure the parameters that are described in the following table, and use the default values for other parameters. Then, click OK.
Parameter
Description
Example
Instance Type
The type of the network instance that you want to attach to CEN.
Inter-region Connection
Region
The region in which the network instance resides. In this example, the region in which TR1 is deployed is selected.
China (Chengdu)
Peer Region
The region in which the peer transit router is deployed. The region that you can select must contain a transit router.
China (Shanghai)
Bandwidth Allocation Mode
You can use Cloud Data Transfer (CDT) to reduce inter-region traffic costs for CEN. We recommend that you activate CDT. You are not charged for the activation operation. For more information, see Getting Started. 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 a server group for the NLB instance
Log on to the NLB console, select the region where the NLB instance resides, and then click the ID of the NLB instance that you want to manage. On the Server Groups page, click Create Server Group.
Configure the parameters that are described in the following table. Use the default values for other parameters. Then, click Create.
Parameter
Description
Example
Server Group Type
The type of the backend servers to be added to the server group.
IP
Server Group Name
-
test
VPC
The VPC to which the server group belongs.
VPC1
Resource Group
The resource group to which the server group belongs.
default resource group
After the server group is created, click Modify Backend Server in the Actions column of the server group. On the Backend Servers tab, click Add IP Address.
Add IP addresses. In the Select Servers step, set the IP Address parameter to the IP addresses of ECS2 and ECS3 and click Next.
In the Ports/Weights step, set the Port parameter to the port of the applications to be deployed on ECS2 and ECS3. In this example, 80 is used. Use the default values for other parameters. Then, click OK.
Step 4: Configure a listener for the NLB instance
Log on to the NLB console and select the region of the NLB instance that you want to manage. On the Instances page, find the NLB instance that you want to manage and click Create Listener in the Actions column.
In the Configure Listener step, set the Listener Protocol parameter to TCP and configure the Listener Port parameter. In this example, 80 is used. Click Next.
In the Select Server Group step, select the server group of the IP type that you configured. Click Next.
In the Configuration Review step, confirm the configuration information and click Submit.
Step 5: Verify the results
Deploy test applications on ECS2 and ECS3.
Log on to the ECS console and select the China (Shanghai) region. On the Instances page, find ECS2 and click Connect in the Actions column. In the Remote connection dialog box, click Sign in now in the Workbench section.
Run the following commands to deploy the test application on ECS2:
Log on to the ECS console and select the China (Qingdao) region. On the Instances page, find ECS3 and click Connect in the Actions column. In the Remote connection dialog box, click Sign in now in the Workbench section.
Run the following commands to deploy the test application on ECS3:
Test network connectivity on ECS1.
Log on to the ECS console and select the China (Chengdu) region. On the Instances page, find ECS1 and click Connect in the Actions column. In the Remote connection dialog box, click Sign in now in the Workbench section.
Run the
sudo yum install -y telnet
command to install telnet.Run the
telnet Domain name Port
command. If a message in the Connected to nlb-... format is returned, the connection is established and the NLB instance can forward requests to the backend servers, as shown in the following figure.
Simulate failures.
Run the
systemctl stop nginx.service
command on ECS2 to stop the application.Wait a few minutes and run the
telnet Domain name Port
command on ECS1 again. A message in the Connected to nlb-... format is returned, as shown in the following figure.Run the
systemctl start nginx.service
command on ECS2 to start the application and run thesystemctl stop nginx.service
command on ECS3 to stop the application.Wait a few minutes and run the
telnet Domain name Port
command on ECS1 again. A message in the Connected to nlb-... format is returned, as shown in the following figure.This indicates that the failure of a single backend server does not affect the availability of the NLB instance.
Release resources
Release the CEN instance and transit routers.
Log on to the CEN console. On the Instances page, find the CEN instance that you want to release and click the instance ID. The instance details page appears.
Delete TR1.
Go to the Basic Settings > Transit Router tab, find TR1, and then click its ID to go to the transit router details page.
On the Intra-region Connections tab, click Detach in the Actions column of each network instance.
On the Cross-region Connections tab, click Delete in the Actions column of the inter-region connection.
Return to the details page of the CEN instance. Click Delete in the Actions column of TR1.
Repeat the preceding step to delete TR2 and TR3.
Return to the Instances page and click Delete in the Actions column of the CEN instance.
Release the ECS instances and security groups.
Delete ECS1 and its security group.
Log on to the ECS console and select the China (Chengdu) region. On the Instances page, find ECS1, click the icon, and then click Release to immediately release ECS1.
Log on to the ECS console and select the China (Chengdu) region. On the Security Group page, find ECS1 Custom Security Group and click Delete in the Operation column.
Repeat the preceding step to delete ECS2, ECS3, and their security groups.
Delete the DNS record. For more information, see Delete a DNS Record.
Release the NLB instance and its server group.
Log on to the NLB console and select the China (Chengdu) region. On the Instances page, find the NLB instance, click the icon, and then click Release to release the NLB instance.
Log on to the NLB console and select the China (Chengdu) region. On the Instances page, find the NLB instance, click the icon, and then click Delete to delete the NLB instance.
Release the VPCs.
Log on to the VPC console and select the China (Chengdu) region. On the VPC page, find VPC1 and click Delete in the Actions column. In the message that appears, select Forcefully Delete to release the VPC and its vSwitches.
Log on to the VPC console and select the China (Shanghai) region. On the VPC page, find VPC2 and click Delete in the Actions column. In the message that appears, select Forcefully Delete to release the VPC and its vSwitches.
Log on to the VPC console and select the China (Qingdao) region. On the VPC page, find VPC3 and click Delete in the Actions column. In the message that appears, select Forcefully Delete to release the VPC and its vSwitches.