You can use Alibaba Cloud Network Load Balancer (NLB) to efficiently route traffic to an RDS Custom instance, ensuring balanced traffic distribution. This solution also connects your RDS Custom instance to the internet, protecting your internal network while improving service availability and scalability.
Prerequisites
An application service must be deployed on the target RDS Custom instance. This topic uses an Nginx service as an example. Run the following commands on the target RDS Custom instance:
yum install -y nginx
systemctl start nginx.service
cd /usr/share/nginx/html/
echo "Hello World ! this is RDS Custom." > index.html
Step 1: Create an NLB instance
Log on to the NLB console.
-
In the top navigation bar, select the same region as your target RDS Custom instance.
-
On the Instance page, click Create NLB.
-
On the NLB (Pay-As-You-Go) purchase page, configure the following parameters, click Buy Now, and follow the on-screen prompts to create the instance.
Only the relevant parameters are described below. Use the default values for other parameters. For details, see Create and manage NLB instances.
Parameter
Description
Region
Select the same region as your target RDS Custom instance.
Network Type
Select a network type for the instance. The system assigns a private or public service address based on your selection. In this topic, Private is selected.
-
Private: A private IP address is provided for each zone. The NLB instance can be accessed only over the Alibaba Cloud internal network, for example, from an ECS instance in the same VPC. The NLB instance cannot be accessed from the internet.
-
Public: A public IP address and a private IP address are provided for each zone. An Internet-facing NLB instance uses an elastic IP address (EIP) to provide public services. If you select this option, you are charged for the EIP instance, and for bandwidth or data transfer.
VPC
Select the same VPC as your target RDS Custom instance.
Zone
Select at least two zones. For example, if your RDS Custom instance is in the China (Shanghai) region, you can select China (Shanghai) Zone E and a vSwitch in that zone, and China (Shanghai) Zone L and a vSwitch in that zone.
Protocol Version
Select an IP version for the instance. In this topic, IPv4 is selected.
Service-linked Role
If you are creating an NLB instance for the first time, click Create Service-linked Role to create a service-linked role named AliyunServiceRoleForNlb. The system grants this role the AliyunServiceRolePolicyForNlb policy, which allows NLB to access other cloud resources. For more information, see System policies for Network Load Balancer.
Instance Name
Enter a custom name for the instance.
Resource Group
Select a resource group to which the instance belongs.
-
Step 2: Create an NLB server group
-
In the left-side navigation pane, choose .
-
On the Server Group page, click Create Server Group.
-
In the Create Server Group dialog box, configure the following parameters and click Create.
The following table describes only the key parameters. Use the default values for other parameters. For details, see Create a server group.
Parameter
Description
Server Group Type
The type of backend server to add to the server group. In this topic, IP Type is selected.
Server Group Name
Enter a name for the server group.
VPC
Select the same VPC as your target RDS Custom instance.
Backend Server Protocol
Select a backend protocol. In this topic, TCP is selected.
Scheduling Algorithm
Select a scheduling algorithm. In this topic, Weighted Round-robin is selected.
Health Check
Enable health checks and use the default settings.
-
After the server group is created, click its ID, and then click the Backend Servers tab.
-
Click Add IP Address. In the Add Backend Server panel, enter the private IP address of your RDS Custom instance, and then click Next.
-
In the Configure Ports and Weights step, set the port to 80 and keep the default weight of 100. Then, click OK.
NoteIf any-port forwarding is enabled for the server group, you do not need to specify a port when you add a backend server. NLB forwards traffic to backend servers based on the frontend request port.
Step 3: Configure a listener
-
In the left-side navigation pane, choose .
-
On the Instance page, find the target instance and click Create Listener in the Actions column.
-
In the Configure Server Load Balancer wizard, configure the following parameters and click Next.
Only the relevant parameters are described below. Use the default values for other parameters. For details about how to configure a listener, see Add a TCP listener.
Parameter
Description
Select Listener Protocol
Select a protocol for the listener. In this topic, TCP is selected.
Listener Port
The port that receives requests and forwards them to backend servers. In this topic, enter 80.
Listener Name
Enter a custom name for the listener.
Advanced Settings
Use the default settings. You can click Modify to change them.
-
In the Server Group step, select IP Type as the server group type and then select the target server group. Review the added backend server information, and then click Next.
-
In the Confirm step, confirm the configurations and click Submit.
-
Click OK. On the Listener tab, check the Health Check Status column for the listener. If the status is Normal, the backend RDS Custom instance can process requests forwarded by the NLB instance.
Step 4: Verify the result
-
On the NLB instance details page, obtain the Domain Name of the instance.
You can create a CNAME record to map a custom domain name to the DNS name of the NLB instance. For more information, see Add a DNS record.
-
On an ECS instance in the same region and VPC as your RDS Custom instance, run the following
telnetcommand to verify the routing. This example uses an ECS instance that runs CentOS 7.NoteIf telnet is not installed, run the
yum install -y telnetcommand to install it.telnet <target_address> <listener_port>-
target_address: The DNS name of the NLB instance or the private IP address of the RDS Custom instance. This topic uses the DNS name of the NLB instance as an example. -
listener_port: The listener port that you configured for the NLB instance. This topic uses 80 as an example.
Example:
telnet nlb-r3rw8kyfwm5bfm****.cn-shanghai.nlb.aliyuncsslb.com 80If you receive the following response, the NLB instance can forward requests to the backend server.
Trying 47.116.XXX.XXX... Connected to nlb-r3rw8kyfwm5bfm****.cn-shanghai.nlb.aliyuncsslb.com. Escape character is '^]'. -
-
Run the
curlcommand to access the default webpage of the Nginx service on the RDS Custom instance.curl http://nlb-r3rw8kyfwm5bfm****.cn-shanghai.nlb.aliyuncsslb.comThe following response is returned:
Hello World ! this is RDS Custom.
(Optional) Route internet traffic to RDS Custom
-
Log on to the Network Load Balancer console.
-
In the top navigation bar, select the instance's region.
-
On the Instance page, find the target internal-facing NLB instance and click its ID.
-
On the Instance Details tab, go to the Basic Information section. Find Network Type and click Change Network Type next to IPv4.
-
In the Change Network Type dialog box, select EIP for IP Type.
-
From the Associate EIP drop-down list for each zone, select Purchase EIP or an existing EIP. Then, click Confirm change.
NoteYou must allocate an EIP for each zone in the list.
If you select Purchase EIP, the new EIP is released when you release the NLB instance or change its network type from Internet-facing to internal-facing. If you select an existing EIP, the EIP is retained in these scenarios.
You can view information about your EIPs in the Elastic IP Addresses console.
-
On the Instance Details tab, check the Network Type.
The change takes about one minute to take effect. The operation is successful when the Network Type for IPv4 on the Instance Details tab changes to Public.
-
Verify the result.
In a web browser, go to
http://nlb-r3rw8kyfwm5bfm****.cn-shanghai.nlb.aliyuncsslb.com. The page loads and displaysHello World ! this is RDS Custom..