Quickstart: Load balance IPv4 services with CLB

Updated at:
Copy as MD

Deploying an application on a single server creates a single point of failure (SPOF) if the server fails or traffic exceeds its capacity. This reduces system availability and degrades the user experience.

Overview

You can use a Classic Load Balancer (CLB) instance to load balance IPv4 services in three steps:

  1. Create an internet-facing CLB instance: An internet-facing CLB instance comes with a static public IP address. You do not need to associate an elastic IP address (EIP) with the CLB instance to provide services over the internet.

  2. Configure a listener and a server group for the CLB instance:

    1. A server group is a logical collection of backend servers that process requests distributed by a CLB instance.

    2. A listener checks for connection requests from clients on a specific protocol and port and forwards the requests to the specified server group for processing.

  3. Configure DNS resolution: A Classic Load Balancer (CLB) instance has a service address, which is its public IP address. In production, you point a domain name to this address so clients can access the service by its domain name.

The following figure shows the service architecture.

image

Prerequisites

  • You have created two Elastic Compute Service (ECS) instances: ECS01 and ECS02. The ECS instances must be in the same region as the CLB instance. For zonal high availability, we recommend creating the two ECS instances in different zones.

    Sample script for the test application on the ECS instances

    Commands to deploy the 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 the 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 completed domain name registration. If your domain name accesses an Alibaba Cloud server in mainland China, you must also complete an ICP filing.

Procedure

Step 1: Create an internet-facing CLB instance

  1. Log on to the Classic Load Balancer (CLB) console. In the top navigation bar, select the region where you want to create the instance.

  2. Click Create CLB. On the buy page, select the region and zone for the CLB instance and configure an instance name.

    Key parameters and recommended settings

    Parameter

    Description

    Recommendations

    SLB area/primary zone

    The region where the CLB instance is located and the zone that carries traffic.

    • Select a region that supports the multi-zone type.

    • Make sure the CLB instance and the ECS instances are in the same region.

    Zone type

    CLB is a regional resource.

    • Single-zone: The region supports CLB deployment in only a single zone.

    • Multi-zone: The region supports CLB deployment in multiple zones. By default, the CLB instance in the primary zone provides services. If the primary zone fails, traffic automatically fails over to the secondary zone. For more information, see Zone-disaster recovery.

    Instance billing method

    Pay-By-CLCU: Ideal for services in testing or with fluctuating traffic. The performance of the instance is automatically scaled. You do not need to specify an instance specification.

    Pay-By-CLCU

    Instance Type

    • Internet: Provides a public IP address to accept traffic from the internet.

    • Intranet: Provides a private IP address to accept traffic only within a Virtual Private Cloud (VPC).

    Internet

    IP Version

    The IP version of the service address provided by the CLB instance.

    • IPv4: The CLB instance provides only an IPv4 address.

    • IPv6: The CLB instance provides only an IPv6 address.

    IPv4

    Internet data transfer billing method

    Only Internet-facing CLB instances are charged for data transfer over the internet.

    pay-by-traffic: suitable for services with high traffic fluctuations.

    pay-by-traffic

    For more information about instance billing, see pay-as-you-go.

  3. Complete the payment to create the instance. The new instance appears in the Classic Load Balancer (CLB) console.

Step 2: Configure a listener and a server group

  1. On the Instances page, find the target instance and click Configure Listener in the Actions column.

  2. Configure the listener protocol and listener port.

    Key parameters and recommended settings

    Parameter

    Description

    Recommendations

    Listener Protocol

    The protocol used by the CLB instance to provide services.

    • TCP/UDP: known as Layer 4 listener protocols.

    • HTTP/HTTPS: known as Layer 7 listener protocols.

    Note

    How they work:

    • Layer 4 listener: Forwards requests by modifying the packet's destination IP address and port to match the configured backend server, then forwarding the packet directly.

    • Layer 7 listener: Acts as a reverse proxy by terminating the client connection and establishing a new one to a backend server. It forwards the request over this new connection, rather than forwarding the original packet.

    For more information, see Product architecture.

    HTTP

    Note

    A Layer 7 listener adds a processing step that can reduce performance in scenarios with high connection counts or client port exhaustion. For high-performance needs, a Layer 4 listener is recommended.

    Listener Port

    The port that the CLB instance uses to provide services.

    80

    For more information about listener parameters, see Add a CLB listener.

    image

  3. Configure a server group and add backend servers.image

    Select the servers that you want to add as backend servers for the CLB instance.

    image

    Configure the application port for the backend servers and add them to the server group.

    image

  4. We recommend that you use the default health check settings.

    Recommendations for health checks

    CLB uses health checks to determine the availability of backend servers.

    When a health check fails, CLB stops sending new requests to the unhealthy backend server and redirects them to healthy ones. Traffic automatically resumes when the server recovers. This mechanism improves service availability by preventing interruptions from failing backend servers.

    Important

    If your services are sensitive to load, frequent health check probes may affect normal service access. You can reduce the impact on your services by decreasing the health check frequency, increasing the health check interval, or changing Layer 7 health checks to Layer 4 health checks. However, to ensure service availability, we recommend that you do not disable health checks.

    For more information, see Health checks.

    image

  5. Review the configurations and submit them.image

Step 3: Configure DNS resolution

  1. On the Instances page, find the target instance and copy the IP address from the IP Address column.

  2. Add an A record to map your domain name to the CLB instance's service address.

    1. Log on to the Alibaba Cloud DNS console, find the target domain name, and click Settings in the Actions column.

    2. Click Add Record, configure the record type, hostname, and record value, and keep the default values for other parameters.

      • Record Type: Select A to map a domain name to an IPv4 address.

      • Hostname: The prefix of the domain name.

      • Record Value: The service address of the CLB instance.

Verification

Use a client that can access the internet.

In a browser, enter the domain name and refresh the page several times. You can see that requests alternate between ECS01 and ECS02.

Note

If the port that you configured is not the default port of the listener protocol, you must enter the full address, including the protocol, domain name, and port. Example: http://www.example.com:9000.

image

image

Stop one of the ECS instances. Client requests are still processed normally. This demonstrates that the load balancer ensures service availability even if a backend server fails.

More operations

Delete resources

If you no longer need the resources after your test, delete them to avoid incurring fees.

  1. Delete the DNS record: Log on to the Alibaba Cloud DNS console and click the target domain name. Find the target DNS record and click Delete in the Actions column to delete the record.

  2. Delete the CLB instance: Log on to the Classic Load Balancer (CLB) console. In the Actions column of the target instance, choose 2 > Release Settings, and then release the instance.

  3. Delete the ECS instances and security group:

    1. Log on to the Elastic Compute Service (ECS) console. In the top navigation bar, select the region where the instances are deployed. Find the target instance, click image.png in the Actions column, select Release in the pop-up window, and then release the instance.

    2. Log on to the Security Groups page of the ECS console. In the top navigation bar, select the region where the security group is deployed, find the target security group, and click Delete in the Actions column.

  4. Delete the VPC and related resources: Log on to the Virtual Private Cloud (VPC) console. In the top navigation bar, select the region where the instance is deployed. Click Delete in the Actions column of the VPC instance to delete the VPC, vSwitches, and other network resources.

FAQ

Internet-facing and internal-facing CLB instances

Feature

Internet-facing CLB instance

Internal-facing CLB instance

Internet accessibility

An Internet-facing Classic Load Balancer (CLB) instance is provisioned with a static public IP address that is tightly bound to the instance.

When you release an instance, you can choose to convert its public IP address into an Elastic IP Address (EIP) and retain it.

An internal-facing CLB instance is deployed in a VPC and does not provide internet access by default.

You can associate an elastic IP address (EIP) with an internal-facing CLB instance to enable internet access. You can associate an EIP with or disassociate an EIP from a CLB instance at any time.

Service address

Provides only a public IP address.

Provides a private IP address within a VPC.

If an EIP is associated, the instance also provides the public IP address of the EIP.

Network capability

Can add backend servers (ECS instances and ENIs) from different VPCs.

Can only add backend servers (ECS instances and ENIs) from the same VPC.

Note

After an instance is created, you cannot change its network type (Internet-facing or internal-facing).

Billing methods

Billing method

Instance metering method

Instance network type

Internet data transfer metering method

Use cases

Pay-as-you-go

Pay-by-LCU

Internet-facing

Pay-by-data-transfer

  • Workloads with periodic or large fluctuations, like gaming and video streaming.

  • Temporary traffic spikes.

Internal

N/A

Pay-by-specification (sale discontinued)

Internet-facing

Pay-by-data-transfer

  • Stable traffic volume.

  • Temporary traffic spikes.

Pay-by-bandwidth

Internal

N/A

Instance specifications

Note

Starting June 1, 2025, 00:00:00 (UTC+8), pay-by-specification CLB instances are no longer available for purchase. For more details, see End of sale for pay-by-specification CLB instances.

Different instance specifications provide different levels of performance. Key metrics include maximum connections, connections per second (CPS), and queries per second (QPS). For more information, see Instance specifications.

Inbound and outbound bandwidth

Yes. The configured bandwidth limit applies to both inbound and outbound traffic.

VPC migration

No.

To switch to another VPC, you must create a new CLB instance in that VPC.

Non-Alibaba Cloud backend servers

No. CLB instances support only Alibaba Cloud Elastic Compute Service (ECS) instances, elastic network interfaces (ENIs), and Elastic Container Instance (ECI) instances as backend servers.

Cross-account backend servers

No. You can only add backend servers from your own Alibaba Cloud account.

EIP association with multiple resources

No. An EIP can be associated with only one cloud resource at a time.

References