When applications are deployed on a single server, single points of failure (SPOFs) such as server breakdown or traffic exceeding server capacity will degrade overall system availability and user experience. Classic Load Balancer (CLB) can transform your system by distributing traffic across multiple backend servers, achieving a scalable and highly available application system.
Solution overview
Here's how to use CLB to balance loads for IPv4 services:
Create an Internet-facing CLB instance: The instance is assigned a static public IP address, enabling services to be accessed over the Internet without an elastic IP address (EIP).
Configure server groups and listeners for the CLB instance:
A CLB server group is a group of backend servers that handle business requests distributed by CLB. Adjust the number of backend servers to manage changing business traffic.
CLB listeners check for incoming requests from clients on specific protocols and ports, and forward them to the associated server group for processing.
Configure domain name resolution: CLB uses an IP address to provide services. In real-world scenarios, users typically resolve their custom domain names to their CLB instance's IP address to enable domain name-based access to the services.
The CLB service architecture is as follows:
Prerequisites
Elastic Compute Service (ECS) instances ECS01 and ECS02 are created in the same region, which is also where you will deploy a CLB instance. For zone-level high availability of your business, we recommend creating the two ECS instances in different zones.
A custom domain name is registered. If your ECS instances are deployed in a region within the Chinese mainland, you must obtain an Internet content provider (ICP) number for the domain name.
Procedure
Step 1: Create an Internet-facing CLB instance
Log on to the CLB console and select the region to deploy your CLB instance in the top menu bar.
Click Create CLB. On the buy page, set the parameters by referring to the following table:
Complete the instance purchase and creation process. Go to the Instances page in the CLB console to check the instance.
Step 2: Configure listeners and server groups
On the Instances page, click the ID of the CLB instance. On the instance details page, click the Listener tab, then click Add Listener.
Configure the listener protocol and port by referring to the following table:
Configure a server group and add backend servers to it.
Select the servers that you want to add as backend servers.
Configure the port for applications on the backend server to provide services and click Add.
(Recommended) Keep the default configurations for health checks.
Confirm and submit the configurations.
Step 3: Configure domain name resolution
On the Instances page, find the CLB instance you created and copy the IP address in the IP Address column.
Add an A record to resolve your custom domain name to the CLB's IP address.
Log on to the Alibaba Cloud DNS console, find the domain name you want, and click DNS Settings in the Actions column.
Click Add DNS Record, set Record Type, Hostname, and Record Value, and keep the default values for the other parameters.
Record Type: Specify an A record, which points the custom domain name to an IPv4 address.
Host Record: Specify the domain name prefix.
Record Value: Enter the CLB's IP address.
Step 4: Test the load balancing effect
Use any local PC as a client that accesses your services over the Internet.
Access your custom domain name in the browser several times. The accessed server alternates between ECS01 and ECS02, as shown in the following figures.
If the backend server protocol and port you configured to provide services are not the listener ones, enter the URL of your services in the address bar of the browser, for example: http://www.example.com:9000
.
Disable either of the ECS instances, and if client requests can still be processed normally, this shows that CLB maintains business availability even when one backend server fails.
Subsequent operations
Delete resources
If you no longer need the resources after testing the solution described in this topic, delete them right away to avoid undesired costs.
DNS record: Log on to the Alibaba Cloud DNS console. Click the domain name, find the record, and click Delete in the Actions column to remove it.
CLB instance: Log on to the CLB console. In the Actions column for the CLB instance, choose , select Release Now, and confirm the action.
ECS instances and security group:
Log on to the ECS console. Select the region where the ECS instances are located in the top menu bar, choose an instance, click
> Release in the Actions column, select Release Now in the dialog box, and confirm the action.
Log on to the Security Groups page of the ECS console, select the region where the security group is deployed in the top menu bar, find the security group, click Delete in the Actions column, and confirm the action.
VPC and related network resources: Log on to the VPC console, select the region where the VPC is located in the top menu bar. Click Delete in the Actions column and complete the process.
FAQs
What are the main differences between newly created Internet- and internal-facing CLB instances?
The network type of newly created internal-facing CLB instances is VPC (not classic network).
Comparison item | Internet-facing CLB | Internal-facing CLB |
Internet accessibility | A static public IP address is inherently associated with an Internet-facing CLB instance, which can be accessed over the Internet. When the instance is released, you can unassociate the public IP address and retain it as an EIP for other uses. | By default, internal-facing CLB cannot be accessed over the Internet. But it can be associated with an EIP to be accessible over the Internet. EIPs can be associated with and unassociated from CLB as required. |
IP address for providing services | Only uses a public IP address. | Uses a private IP address within a VPC. After associating an EIP with CLB, it also uses the EIP. |
Networking | ECS instances and elastic network interfaces (ENIs) both in the local VPC and in other VPCs can be associated with CLB as backend servers. | Only ECS instances and ENIs in the local VPC can be associated with CLB as backend servers. |
After creation, Internet- and internal-facing CLB instances cannot be converted to one another.
How do I choose a CLB instance type based on the billing method and data transfer fees?
Refer to the following table:
Billing method | Metering method | Instance type | Internet data transfer billing method | Scenarios |
Pay-by-LCU | Internet-facing | Pay-by-data-transfer |
| |
Internal-facing | N/A | |||
Pay-by-specification | Internet-facing | Pay-by-data-transfer |
| |
Pay-by-bandwidth | ||||
Internal-facing | N/A |
For CLB instances whose Internet metering method is By bandwidth, are the upstream and downstream maximum bandwidths the same?
Yes, they are.
For example, if you have a CLB instance with a maximum bandwidth of 20 Mbit/s, both the upstream and downstream maximum bandwidths are 20 Mbit/s.
What are the differences between specifications for CLB instances whose Internet metering method is By specification?
Different CLB instance specifications offer varying traffic processing performance. Key performance metrics include maximum connections, connections per second (CPS), and queries per second (QPS). For more information, see High-performance CLB instances.
Does CLB support migration between VPCs?
No, it does not.
If you want CLB services in another VPC, create a CLB instance in it.
Does CLB support forwarding traffic to non-Alibaba Cloud Internet-facing servers?
No, CLB currently only supports Alibaba Cloud's ECS instances, ENIs, and Elastic Container Instances as backend servers.
Can I associate ECS instances created with another account to CLB as backend servers?
No, CLB only supports adding backend servers created with the same account.
Can an EIP be associated with both an internal-facing CLB and a NAT Gateway at the same time?
No, an EIP can only be associated with one cloud resource at a time.
References
For CLB use scenarios and components, see What is CLB?
For CLB features, see Features.