If your services prioritize reliability and data accuracy over speed, such as for file transfers, email, and remote logon, you can add a TCP listener to your Classic Load Balancer (CLB) instance. The listener forwards TCP requests from clients to backend servers for processing.
Prerequisites
Create a CLB instance. For more information, see Create and manage CLB instances.
Procedure
Step 1: Configure the listener
Log on to the Classic Load Balancer (CLB) console.
In the top navigation bar, select the region where the CLB instance is deployed.
Use one of the following methods to open the listener configuration wizard:
On the Manage Instance page, find the target instance, and then click Configure Listener in the Operations column.
On the Manage Instance page, find the target instance and click its ID. On the instance details page, click the Listener tab and then click Add Listener.
In the Protocol & Listener step, configure the following parameters and click Next.
Configuration
Description
Select Listener Protocol
Select TCP.
Backend Protocol
Selecting TCP as the listener protocol automatically sets the Backend Protocol to TCP.
Listener Port
Specify the port to receive and forward requests to backend servers. The port number must be between 1 and 65535.
Tag
Select or enter a Tag Key and Tag Value.
Advanced Settings
Click Modify to expand the advanced settings.
Scheduling Algorithm
Select a scheduling algorithm. Round Robin (RR) is selected by default. For more information about scheduling algorithms and their use cases, see Load balancing scheduling algorithms.
Weighted Round-robin (WRR): Backend servers with higher weights receive more requests.
Round Robin (RR): Incoming requests are distributed to backend servers in sequential order.
Consistent Hashing (CH):
Four-element: Distributes requests based on a four-tuple (source IP, destination IP, source port, and destination port). Requests from the same flow are routed to the same backend server.
Source IP: Distributes requests based on the source IP address. Requests from the same source IP address are routed to the same backend server.
NoteOnly Consistent Hashing instances support the Consistent Hashing (CH) scheduling algorithm.
You cannot change the scheduling algorithm of an existing TCP listener to Consistent Hashing (CH) if the scheduling algorithm is set to Weighted Round-robin (WRR) or Round Robin (RR). To use the Consistent Hashing (CH) scheduling algorithm, you must create a new TCP listener and set its scheduling algorithm to Consistent Hashing (CH).
Session Persistence
This feature is disabled by default.
If you enable session persistence, the listener routes requests from the same client to the same backend server.
For the TCP protocol, session persistence is based on the client IP address.
Access Control
This feature is disabled by default.
After you enable access control, select an access control method and an Access Control List (ACL) to use as an allowlist or a denylist for this listener.
Whitelist: Allows Specified IP Addresses to Access the SLB Instance. The CLB instance forwards requests only from the IP addresses or CIDR blocks specified in the selected ACL. Use this mode to allow access only from specific IP addresses. Exercise caution when you configure an allowlist.
If an allowlist is enabled but no IP addresses are added to the ACL, the listener forwards all requests.
Blacklist: Forbids Specified IP Addresses to Access the SLB Instance. The CLB instance denies requests from the IP addresses or CIDR blocks specified in the selected ACL. Use this mode to block access from specific IP addresses.
If a denylist is enabled but no IP addresses are added to the ACL, the listener forwards all requests.
NoteAn IPv4 instance can only be associated with an IPv4 ACL. An IPv6 instance can only be associated with an IPv6 ACL. For more information, see Create an Access Control List.
Bandwidth Throttling for Listeners
For a pay-by-bandwidth CLB instance, you can set a maximum bandwidth for each listener to limit its traffic. The total bandwidth of all listeners cannot exceed the bandwidth of the instance.
By default, this feature is disabled and all listeners share the total bandwidth of the instance. For more information about how bandwidth is shared, see Listeners of a CLB instance share the bandwidth of the instance.
ImportantIf you have a public-facing CLB instance with a total bandwidth of 5 Mbit/s and two listeners, and you allocate the full 5 Mbit/s to Listener A while leaving Listener B unconfigured, Listener B becomes inaccessible. Allocate bandwidth with caution.
If you have a private-facing CLB instance with three listeners, and you allocate a total of 5,120 Mbit/s to Listeners A and B, Listener C becomes inaccessible. Allocate bandwidth with caution.
For pay-by-traffic instances, the listener bandwidth is not limited by default.
Connection Timeout Period
Specifies the maximum period for which a TCP connection between a client and the CLB instance can remain idle. The value must be between 10 and 900 seconds. The default value is 900 seconds.
If no request is received within the timeout period, CLB closes the connection. A new connection is established when the next request arrives.
NoteThis setting applies to the entire listener. To set a different connection timeout for a specific backend server, you must configure a separate listener for that server and set the desired timeout in the new listener.
Configure the proxy protocol.
Enables the Proxy Protocol to pass client IP addresses to backend servers. For more information, see Preserve client IP addresses for Layer 4 listeners.
ImportantPrivateLink does not support preserving client IP addresses by using the Proxy Protocol.
To use the Proxy Protocol, both the proxy server and the backend servers must support it. If your backend servers cannot parse the Proxy Protocol, enabling this feature may cause parsing errors and service disruptions.
Obtain Client Source IP Address
For Layer 4 listeners, backend servers can directly obtain the client IP addresses. This feature is enabled by default.
Automatically Enable Listener
Specifies whether to enable the listener immediately after it is created. This feature is enabled by default.
Step 2: Add backend servers
Add backend servers to process client requests. You can use the default server group configured for the instance, or you can configure a vServer group or a primary/secondary server group for the listener. For more information, see CLB server groups. This topic uses the default server group as an example.
In the Backend Servers step, select Default Server Group and click Add More.
In the Select Servers step, select the backend servers that you want to add and click Next.
In the Ports/Weights step, set the weight for each server, and click Add.
NoteThe default weight is 100. A backend server with a higher weight receives more requests.
A server with a weight of 0 does not receive new requests.
Configure the port on which each backend server (ECS instance) receives requests, and then click Next. The port number must be between 1 and 65535.
NoteBackend servers of the same CLB instance can use the same port.
Step 3: Configure a health check
CLB uses health checks to determine the availability of backend servers, which improves the overall availability of frontend services and prevents abnormal backend servers from affecting the service.
You cannot disable health checks for listeners of a primary/secondary server group.
Optional: In the Health Check step, click Modify to change the health check configuration, and then click Next. For more information, see Configure and manage CLB health checks.
In the Configuration Review step, review the listener configuration and click Modify if you need to make changes.
After you confirm the settings, click Submit. After the listener is created, click OK.
After the configuration is complete, the new listener appears on the Listeners tab.
FAQ
Domain name access for TCP listeners
Point your domain name to the public IP address of the CLB instance. For more information, see Use an A record to resolve a domain name to an IP address.
References
To learn how to manage backend server groups, see the following topics:
For information about how health checks work, see Health checks for CLB. For information about how to configure health check parameters, see Configure and manage CLB health checks.
If you encounter issues related to listeners, see FAQ about CLB listeners for troubleshooting.
For more information about scheduling algorithms, see Load balancing scheduling algorithms.
To preserve client IP addresses when using a TCP listener, see the Preserve client IP addresses for Layer 4 listeners tutorial.