All Products
Search
Document Center

Server Load Balancer:Use ALB to quickly balance loads for IPv4 services

Last Updated:Sep 09, 2025

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.

    Note
    • To 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:

      Commands to deploy a service on ECS01

      yum install -y nginx systemctl start nginx.service cd /usr/share/nginx/html/ echo "Hello World ! This is ECS01." > index.html

      Commands to deploy a service on ECS02

      yum install -y nginx systemctl start nginx.service cd /usr/share/nginx/html/ echo "Hello World ! This is ECS02." > index.html
  • 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.

Click to view the VPC configurations

Configuration

Description

Name

VPC1

Region

China (Shanghai)

IPv4 CIDR Block

192.168.0.0/12

VSwitch

Name: VSW1

Zone: Shanghai Zone E

IPv4 CIDR Block: 192.168.5.0/24

Name: VSW2

Zone: Shanghai Zone G

IPv4 CIDR Block: 192.168.6.0/24

The following table describes the configurations of the ECS instances in this topic. The configurations are for reference only.

Click to view the ECS configurations

Name

Region

VPC

Zone and vSwitch

ECS configuration

ECS01

China (Shanghai)

VPC1

Shanghai Zone E | VSW1

  • Instance type: ecs.e-c1m1.large

  • CPU & Memory: 2 vCPU 2 GiB

  • Image: Alibaba Cloud Linux 3.2104 LTS 64-bit

ECS02

Shanghai Zone G | VSW2

Step 1: Create an ALB instance

  1. Log on to the ALB console.

  2. On the Instances page, click Create Application Load Balancer.

  3. 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.

  4. Click Buy Now and complete the payment.

  5. 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

  1. In the navigation pane on the left, choose Application Load Balancer > Server Group.

  2. On the Server Group page, click Create Server Group.

  3. 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.

    Note

    Make 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.

  4. In the The Server Group Is Created dialog box, click Add Backend Servers.

  5. On the Backend Servers tab, click Add Backend Servers.

  6. In the Add Backend Servers panel, select the ECS01 and ECS02 instances that you created, and then click Next.

  7. 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

  1. In the navigation pane on the left, choose Application Load Balancer > Instances, and then click the ID of the instance.

  2. Click the Listeners tab and then click Create Listener.

  3. 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.

  4. In the Server Group step, select Server Type for Server Type, select the server group that you created, and then click Next.

  5. In the Configuration Review step, review the listener configuration and click Submit.

  6. 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.

Important

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.

  1. In the navigation pane on the left, choose Application Load Balancer > Instances.

  2. On the Instances page, copy the DNS name of the ALB instance.

  3. Perform the following steps to add a CNAME record.

    Note

    If 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.

    1. Log on to the Alibaba Cloud DNS console.

    2. On the Authoritative Domain Names page, find the target domain name and click DNS Settings in the Actions column.

    3. On the DNS Settings page, click Add Record.

    4. 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 @.

      Note

      To 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.

image

image

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

  1. Release resources such as ECS instances and security groups:

    1. Delete the ECS01 instance and its security group:

      1. 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 image.png icon. In the window that appears, select Release, and then follow the prompts to immediately release the instance.

      2. 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.

    2. Repeat the preceding steps to delete the ECS02 instance and its security group.

  2. Delete the DNS record

    You can delete the DNS record. For more information, see Delete a DNS record.

  3. Release ALB resources:

    1. 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 image.png icon. In the window that appears, select Release and follow the prompts to release the instance.

    2. Remove the backend servers. For more information, see Remove backend servers.

    3. Delete the server group. For more information, see Delete a server group.

  4. Release VPC resources:

    1. Log on to the VPC console. In the top navigation bar, select the region of the instance.

    2. 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