Alibaba Cloud Application Load Balancer (ALB) supports the HTTP, HTTPS, and QUIC protocols. Designed for the application layer, ALB provides powerful processing capabilities. This topic describes how to quickly create an IPv4 ALB instance and 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 Shanghai Zone E and a vSwitch named VSW2 in Shanghai Zone G. For more information, see Create a VPC and a vSwitch.
If you plan to deploy an ALB instance in VSW1 and VSW2, note that an upgraded ALB instance requires 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 IP addresses, an error is reported and the instance creation fails. Make sure that VSW1 and VSW2 have sufficient available IP addresses. This limit does not apply to ALB instances that are not upgraded.
NoteTo ensure that all elastic features of upgraded ALB instances are available, reserve at least eight IP addresses in each vSwitch that is associated with the ALB instance.
If your backend services use access policies, such as iptables or other third-party security policy software, you must allow traffic from the CIDR block of the vSwitch in which the ALB instance is deployed. This ensures proper connectivity between upgraded ALB instances and backend services.
You have created an Elastic Compute Service (ECS) instance named ECS01 in VSW1 and an ECS instance named ECS02 in VSW2. Application services are deployed on the ECS01 and ECS02 instances.
For more information about how to create an ECS instance, see Create an instance using the wizard.
The following code blocks show how to deploy test applications on ECS01 and ECS02:
You have registered a domain name and completed the ICP filing. For more information, see Register a domain name with Alibaba Cloud and ICP filing process.
The following table describes the configurations of the VPC instance in this topic. The configurations are for reference only.
The following table describes the configurations of the ECS instances in this topic. The configurations are for reference only.
Step 1: Create an ALB instance
Log on to the ALB console.
On the Instances page, click Create Application Load Balancer.
On the Application Load Balancer (Pay-As-You-Go) purchase page, set the parameters for the instance.
This topic describes only the required parameters. For all other parameters, you can use the default values. For more information about the parameters, see Create an instance.
Configuration
Description
Region
Select a region for the instance. In this topic, China (Shanghai) is selected.
Network Type
Select a network type for the instance. The system assigns a private or public endpoint based on your selection. In this topic, Internet is selected.
VPC
Select a VPC for the instance.
Zone
Select at least two zones. In this topic, Shanghai Zone E and its vSwitch VSW1, and Shanghai Zone G and its vSwitch VSW2 are selected.
Protocol Version
Select a protocol version for the instance. In this topic, IPv4 is selected.
Edition (Instance Fee)
Select an edition for the instance. In this topic, Standard Edition is selected.
Instance Name
Enter a custom instance name.
Service-linked Role
When you create an ALB instance for the first time, click Create Service-linked Role to create a service-linked role named AliyunServiceRoleForAlb. The system attaches the AliyunServiceRolePolicyForAlb policy to this role. This policy grants the ALB instance permissions to access other cloud resources. For more information, see System policies for ALB.
Click Buy Now and complete the payment.
Return to the Instances page and select the region where the ALB instance is deployed to view the ALB instance.
Step 2: Create a server group
In the navigation pane on the left, choose .
On the Server Group page, click Create Server Group.
In the Create Server Group dialog box, configure the parameters and click Create.
This topic describes only the required parameters. For all other parameters, you can use the default values. For more information about the parameters, see Create a server group.
Parameter
Description
Server Group Type
Select a server group type. In this topic, Server is selected.
Server Group Name
Enter a name for the server group.
VPC
From the VPC drop-down list, select the VPC where the ECS instances are deployed.
NoteMake sure that you select the same VPC that you selected for the ALB instance.
Backend Protocol
Select a backend protocol. In this topic, HTTP is selected.
Scheduling Algorithm
Select a scheduling algorithm. In this topic, Weighted Round-robin is selected.
Session Persistence
Enable or disable session persistence. In this topic, this feature is disabled by default.
Backend Persistent Connection
Enable or disable backend persistent connections. In this topic, this feature is enabled by default.
Health Check
Enable or disable health checks. In this topic, this feature is enabled.
Health Check Configuration
After you enable health checks, click Edit to configure more parameters.
In the The Server Group Is Created dialog box, click Add Backend Servers.
On the Backend Servers tab, click Add Backend Servers.
In the Add Backend Servers panel, select the ECS01 and ECS02 instances that you created, and then click Next.
In the Configure Ports and Weights step, set the Port and Weight for the backend servers, and then click OK.
In this topic, the port for the ECS instances is set to 80 and the default weight of 100 is used.
Step 3: Configure a listener
In the navigation pane on the left, choose , and then click the ID of the instance.
Click the Listeners tab and then click Create Listener.
On the Configure Listener page, set the following parameters and click Next.
This topic describes only the required parameters. For all other parameters, you can use the default values. For more information about how to configure a listener, see Add an HTTP listener.
Parameter
Description
Select Listener Protocol
Select a listener protocol. In this topic, HTTP is selected.
Listener Port
The listener port that is used to receive requests and forward them to backend servers. In this topic, enter 80.
Listener Name
Enter a custom listener name.
Advanced Settings
In this topic, the default settings are used. You can click Modify to change the settings.
In the Server Group step, select Server Type for Server Type, select the server group that you created, and then click Next.
In the Configuration Review step, review the listener configuration and click Submit.
Click OK to return to the Listeners tab. If the Health Check Status of the listener is Normal, it indicates that the ECS01 and ECS02 instances can process requests that are forwarded by the ALB instance.
Step 4: Set up domain name resolution
In a real-world scenario, you must use a custom domain name. To do this, create a CNAME record to map the custom domain name to the domain name of the ALB instance.
The domain names of Server Load Balancer (SLB) instances are upgraded. Therefore, you cannot directly use the DNS name of an ALB instance for access.
In the navigation pane on the left, choose
.On the Instances page, copy the DNS name of the ALB instance.
Perform the following steps to add a CNAME record.
NoteIf your domain name is not registered with Alibaba Cloud, you must first add the domain name to the Alibaba Cloud DNS console before you can add DNS records. For more information, see Manage domain names. If your domain name is registered with Alibaba Cloud, you can perform the following steps.
Log on to the Alibaba Cloud DNS console.
On the Authoritative Domain Names page, find the target domain name and click DNS Settings in the Actions column.
On the DNS Settings page, click Add Record.
In the Add Record panel, set the following parameters to add the CNAME record, and then click OK.
Configuration
Description
Record Type
From the drop-down list, select CNAME.
Host
The prefix of your domain name. In this topic, enter @.
NoteTo map a root domain, set Host to
@
.Request Source
Select Default.
Record Value
Enter the CNAME address, which is the DNS name of the ALB instance that you copied.
TTL
Time to Live (TTL) specifies the period of time that a DNS record is cached on a DNS server. In this topic, the default value is used.
Step 5: Test connectivity
Test the connectivity between the client and the ECS01 and ECS02 instances. In this topic, a client that can access the internet is used as an example.
Enter the domain name in your browser, for example, http://<Your domain name>
. Refresh the page multiple times. You can see that the client requests are distributed between the ECS01 and ECS02 instances.
The results show that the client can access different backend services through the ALB instance and that the ALB instance distributes requests in a round-robin manner.
Release resources
Release resources such as ECS instances and security groups:
Delete the ECS01 instance and its security group:
Log on to the ECS console. In the top navigation bar, select the region where the instance is located. On the right side of the ECS01 instance, click the
icon. In the window that appears, select Release, and then follow the prompts to immediately release the instance.
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 to delete the security group.
Repeat the preceding steps to delete the ECS02 instance and its security group.
Delete the DNS record
You can delete the DNS record. For more information, see Delete a DNS record.
Release ALB resources:
Log on to the ALB console. In the top navigation bar, select the region of the instance. On the right side of the instance, click the
icon. In the window that appears, select Release and follow the prompts to release the instance.
Remove the backend servers. For more information, see Remove backend servers.
Delete the server group. For more information, see Delete a server group.
Release VPC resources:
Log on to the VPC console. In the top navigation bar, select the region of the instance.
Click Delete in the Actions column corresponding to the instance. The system checks for existing cloud resources or associated resources. If dependent resources exist, you must release them before you can delete the VPC and its vSwitches.
References
For more information about the scenarios and components of ALB, see What is Application Load Balancer?.
For more information about the features of ALB, see Features.
For more information about the regions that support ALB, see Regions and zones that support ALB.
For more information about ALB quotas and how to increase them, see Limits.
For more information about the billing of ALB, see Product Billing.