Quickstart: IPv4 load balancing with ALB
Alibaba Cloud Application Load Balancer (ALB) supports HTTP, HTTPS, and QUIC protocols and is designed for the application layer. This topic shows you how to quickly create an IPv4 ALB instance to forward requests from IPv4 clients to backend servers.
Prerequisites
-
You have created a Virtual Private Cloud (VPC) named VPC1 in the China (Shanghai) region. You have also created a vSwitch named VSW1 in Zone E and another vSwitch named VSW2 in Zone G. For more information, see Create a VPC and a vSwitch.
If you plan to deploy the ALB instance in VSW1 and VSW2, note that an upgraded ALB instance reserves three IP addresses from each specified vSwitch: one virtual IP address (VIP) for providing services and two local IP addresses for communicating with backend servers. If a vSwitch has insufficient available IP addresses, instance creation fails. Ensure that VSW1 and VSW2 have enough available IP addresses. This limitation does not apply to non-upgraded ALB instances.
Note-
To ensure that all elastic capabilities are available for ALB instance upgrades, we recommend that you reserve at least 8 IP addresses in each vSwitch that contains the instance.
-
To ensure proper communication between upgraded ALB instances and backend services, if your backend services use access control policies like iptables, allow traffic from the CIDR block of the ALB instance's vSwitch.
-
-
You have created an Elastic Compute Service (ECS) instance named ECS01 in VSW1 and another ECS instance named ECS02 in VSW2. Application services are deployed on both ECS01 and ECS02.
-
For more information about how to create an ECS instance, see Create an instance by using the wizard.
-
The following examples show how to deploy test applications on ECS01 and ECS02:
-
-
You have registered a domain name and completed ICP filing for it. For more information, see Register a domain name and ICP filing process.
The following table describes the VPC configurations used in this tutorial. The configurations are for reference only.
The following table describes the configurations of the ECS instances used in this tutorial. The configurations are for reference only.
Step 1: Create an ALB instance
Log on to the ALB console.
-
On the Instances page, click Create ALB.
-
On the Application Load Balancer (pay-as-you-go) purchase page, configure the instance.
Only the configuration items relevant to this topic are listed here. Use the default values for all other configuration items. For more information about the parameters, see Create and manage ALB instances.
Parameter
Description
Region
Select the region where you want to deploy the instance. This tutorial uses China (Shanghai).
Network Type
Select a network type for the instance. The system assigns a private or public IP address based on your selection. This tutorial uses the Public.
VPC
Select the VPC where you want to deploy the instance.
Zone ID
Select at least two zones. This tutorial uses Shanghai Zone E and its vSwitch VSW1, and Shanghai Zone G and its vSwitch VSW2.
IP Version
Select an IP version for the instance. This tutorial uses IPv4.
Edition (Instance Fee)
Select an edition for the instance. This tutorial uses Standard.
Instance Name
Enter a custom name for the instance.
Service-linked Role
The first time you create an ALB instance, you must click Create Service-Linked Role to create a service-linked role named AliyunServiceRoleForAlb. The system attaches the AliyunServiceRolePolicyForAlb permission policy to this role to grant ALB access to other cloud resources. For more information, see System permission policies for load balancing.
-
Click Buy Now and follow the on-screen instructions to complete the purchase.
-
Return to the Instances page. Your new instance appears in the list for the selected region.
Step 2: Create a 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 parameters for the server group and click Create.
Only the configuration items that are highly relevant to this topic are listed here. Use the default values for all other configuration items. For more information about the parameters, see Create/Delete Server Group.
Parameter
Description
Server Group Type
Select a server group type. This tutorial uses Server.
Server Group Name
Enter a name for the server group.
VPC
Select the VPC that contains your ECS instances.
NoteMake sure that the selected VPC is the same as the one selected when you created the ALB instance.
Backend Server Protocol
Select a backend protocol. This tutorial uses HTTP.
Scheduling Algorithm
Select a scheduling algorithm. This tutorial uses Weighted Round-robin.
Session Persistence
Enable or disable session persistence. This tutorial uses the default setting (disabled).
Backend Persistent Connection
Enable or disable backend persistent connections. This tutorial uses the default setting (enabled).
Health Check
Enable or disable health checks. This feature is enabled for this tutorial.
Health Check Settings
After enabling health checks, click Edit for advanced configuration.
-
In the The server group is created dialog box, click Add Backend Server.
-
On the Backend Servers tab, click Add Backend Server.
-
In the Add Backend Server panel, select the ECS01 and ECS02 instances that you created, and then click Next.
-
On the Ports/Weights wizard, set the Port and Weight for the added servers, and then click OK.
In this tutorial, the port for the ECS instances is set to 80, and the weight is set to the default value of 100.
Step 3: Configure a listener
-
In the left-side navigation pane, choose , and then click the instance ID.
-
Click the Listener tab and then click Create Listener.
-
On the Configure Listener wizard page, complete the configuration and click Next.
This section lists only the parameters that are relevant to this topic. For all other parameters, use the default values. For more information about how to configure a listener, see Add an HTTP listener.
Parameter
Description
Select Listener Protocol
Select the protocol for the listener. This tutorial uses HTTP.
Listener Port
The listener port used to receive and forward requests to backend servers. This tutorial uses port 80.
Listener Name
Enter a custom name for the listener.
Advanced Settings
Use the default settings. You can click Modify to change the settings.
-
In the Server Group configuration wizard, select a Server Type and the target server group under the Server Type, view the backend server information, and then click Next.
-
On the Configuration Review page, confirm the configuration, and then click Submit.
-
Click OK to return to the Listener tab. When the Health Check Status column for the listener shows Healthy, the backend servers ECS01 and ECS02 can process requests forwarded by the ALB instance.
Step 4: Configure DNS resolution
For production, we recommend mapping a custom domain name to the ALB instance's domain name by creating a CNAME record.
The domain names of load balancers have been upgraded. You can no longer directly access services by using the DNS name provided by ALB.
-
In the left-side navigation pane, choose .
-
On the Instances page, copy the DNS name of the created ALB instance.
-
Follow these steps to add a CNAME record.
NoteIf your domain name is registered by a provider other than Alibaba Cloud, you must add the domain name to the Alibaba Cloud DNS console before you can configure DNS resolution. For more information, see Manage domain names. If your domain name is registered with Alibaba Cloud, proceed with the following steps.
-
Log on to the Alibaba Cloud DNS console.
-
On the Authoritative DNS Resolution page, find the target domain name, and click Settings in the Operations column.
-
On the Settings page, click Add Record.
-
In the Add Record panel, configure the CNAME record by setting the following parameters, and then click OK.
Parameter
Description
Record Type
Select CNAME from the drop-down list.
Hostname
The prefix of your domain name. This tutorial uses @.
NoteTo use a root domain, set the hostname to
@.Query Source
Select Default.
Record Value
Enter the DNS name of the ALB instance that you copied.
TTL
Time to live (TTL) is the duration that a DNS record is cached on a DNS server. Use the default value.
-
Step 5: Test connectivity
Test the connectivity between a client and the ECS01 and ECS02 servers. This tutorial uses a client with public network access as an example.
In the address bar of your browser, enter your domain name, for example, http://<yourdomain.com>. Refresh the page multiple times. The displayed message alternates, demonstrating that the ALB is distributing requests to both backend servers.
One response will be Hello World ! This is ECS01., which indicates that the request was forwarded to the ECS01 server.
Hello World ! This is ECS02.
This confirms that the client can use the ALB instance to access different backend servers in a round-robin manner.
Clean up resources
-
Clean up ECS, security group, and other resources:
-
Delete the ECS01 instance and its security group:
-
Log on to the Elastic Compute Service console. In the top navigation bar, select the region where the instance is located. Find the ECS01 instance, click the
icon in the Actions column, select Release in the dialog box that appears, and confirm the release. -
Log on to the ECS Security Group console. In the top navigation bar, select the region where the instance is located, select the custom security group for ECS01, and click Delete.
-
-
Follow the preceding steps to delete the ECS02 instance and its corresponding security group.
-
-
Delete the DNS record
For more information, see Delete a DNS record.
-
Clean up ALB resources:
-
Release the ALB instance. Before you proceed, make sure you have deleted the listener associated with it. Log on to the ALB console. In the top navigation bar, select the region where the instance is located. Find the instance, click the
icon in the Actions column, select Release in the dialog box that appears, and confirm your action. -
Remove the backend servers from the server group. For more information, see Create and manage server groups.
-
Delete the server group. For more information, see Create and manage server groups.
-
-
Clean up VPC resources:
-
Log on to the Virtual Private Cloud console. In the top navigation bar, select the region where the instance is located.
-
Click Delete in the Actions column for the instance. The system checks for any undeleted cloud resources or associated resources. If dependent resources exist, you must release them completely before you can delete the VPC and vSwitches.
-
Related documents
-
Learn about the use cases and components of ALB in What is Application Load Balancer?.
-
Explore the features of ALB in Features.
-
Find a list of regions where ALB is available in Regions and zones that support ALB.
-
Learn about ALB quotas and how to request an increase in Quotas and limits.
-
For information about ALB billing, see Billing of ALB.