Adding a TCP Listener

Scenarios

You can add a TCP listener, if high reliability and high accuracy are required, but slow speed is acceptable, such as file transfer, email sending and receiving, and remote login.

Adding a TCP Listener to a Shared Load Balancer

  1. Log in to the management console.
  2. In the upper left corner of the page, click and select the desired region and project.
  3. Click Service List. Under Network, click Elastic Load Balance.
  4. Locate the load balancer and click its name.
  5. Under Listeners, click Add Listener.
  6. Configure the listener based on Table 1 and click Next.
    Table 1 Parameters for configuring a listener

    Parameter

    Description

    Example Value

    Name

    Specifies the listener name.

    listener-pnqy

    Frontend Protocol/Port

    Specifies the protocol and port used by the load balancer to receive requests from clients and forward the requests to backend servers.

    Port range: 1 to 65535

    TCP/80

    Obtain Client IP Address

    Specifies whether to transmit the EIP bound to the load balancer to backend servers. This parameter is available when you have set Frontend Protocol to TCP or UDP.

    This function is enabled for dedicated load balancers by default and cannot be disabled.

    CAUTION:

    If you enable this option, you cannot change the specifications of backend servers.

    N/A

    Advanced Settings

    Access Policy

    Specifies how access to the listener is controlled. For more information, see Access Control. The following options are available:

    • All IP addresses
    • Blacklist
    • Whitelist

    Blacklist

    IP Address Group

    Specifies the IP address group associated with a whitelist or blacklist. If there is no IP address group, create one first. For more information, see IP Address Group.

    ipGroup-b2

    Idle Timeout

    Specifies the length of time for a connection to keep alive, in seconds. If no request is received within this period, the load balancer closes the connection and establishes a new one with the client when the next request arrives.

    300S

    Description

    Provides supplementary information about the listener.

    N/A

  7. Configure the backend server group based on Table 2, configure the health check based on Table 3, and click Finish.
    Table 2 Parameters for configuring a backend server group

    Parameter

    Description

    Example Value

    Backend Server Group

    Specifies a group of servers that have the same features and receive requests from the load balancer. Two options are available:

    • Create new
    • Use existing
      NOTE:

      To associate an existing backend server group, ensure that it is not in use. Select the backend server group with the correct protocol. For example, if the frontend protocol is TCP, the backend protocol can only be TCP.

    Create new

    Name

    Specifies the backend server group name.

    server_group-sq4v

    Backend Protocol

    Specifies the protocol used by backend servers to receive requests. The backend protocol is TCP by default when you have set Frontend Protocol to TCP.

    TCP

    Load Balancing Algorithm

    Specifies the algorithm used by the load balancer to distribute traffic.

    • Weighted round robin: Requests are distributed across backend servers in sequence based on their weights. Backend servers with higher weights receive proportionately more requests, whereas equal-weighted servers receive the same number of requests.
    • Weighted least connections: This algorithm is designed based on the least connections algorithm that uses the number of active connections to each backend server to make its load balancing decision. In addition to the number of connections, each server is assigned a weight based on its capacity. Requests are routed to the server with the lowest connections-to-weight ratio.
    • Source IP hash: The source IP address of each request is calculated using the consistent hashing algorithm to obtain a unique hash key, and all backend servers are numbered. The generated key allocates the client to a particular server. This allows requests from different clients to be routed based on source IP addresses and ensures that a client is directed to the same server that it was using previously.
    NOTE:
    • Choose an appropriate algorithm based on your requirements for better traffic distribution.
    • For Weighted round robin or Weighted least connections, no access request will be routed to a server if its weight is 0.

    Weighted round robin

    Sticky Session

    Specifies whether to enable sticky sessions. If you enable sticky sessions, all requests from the same client during one session are sent to the same backend server.

    NOTE:

    Sticky sessions can be enabled only if you select Weighted round robin or Weighted least connections for Load Balancing Algorithm.

    N/A

    Sticky Session Type

    Specifies the type of sticky sessions. Source IP address is the only choice available when TCP is used as the frontend protocol.

    Requests with the same source IP address are routed to the same backend server during the session.

    Source IP address

    Stickiness Duration (min)

    Specifies the minutes that sticky sessions are maintained. Set the stickiness duration when you have selected Weighted round robin and enabled sticky sessions.

    The stickiness duration ranges from 1 to 60.

    20

    Description

    Provides supplementary information about the backend server group.

    N/A

    Table 3 Parameters for configuring a health check

    Parameter

    Description

    Example Value

    Enable Health Check

    Specifies whether to enable health checks.

    N/A

    Protocol

    Specifies the protocol used by the load balancer to perform health checks on backend servers. You can use either TCP or HTTP. A selected protocol cannot be changed.

    HTTP

    Domain Name

    Specifies the domain name in the health check request. The domain name can contain digits, letters, hyphens (-), and periods (.), and must start with a digit or letter. This parameter is left blank by default and needs to be set only when the health check protocol is HTTP.

    www.elb.com

    Port

    Specifies the port used by the load balancer to perform health checks on backend servers.

    Port range: 1 to 65535

    NOTE:

    This parameter is optional. If you do not specify a health check port, the port of each backend server will be used for health checks by default.

    80

    Advanced Settings

    Interval (s)

    Specifies the maximum time between health checks, in seconds.

    The interval ranges from 1 to 50.

    5

    Timeout (s)

    Specifies the maximum time required for waiting for a response from the health check, in seconds. The timeout duration ranges from 1 to 50.

    10

    Check Path

    Specifies the health check URL, which is the destination on backend servers for health checks. This parameter is available only when you have set Protocol to HTTP. The path can contain 1 to 80 characters and must start with a slash (/).

    /index.html

    Maximum Retries

    Specifies the maximum number of health check retries. The value ranges from 1 to 10.

    3

  8. Click OK.

Adding a TCP Listener to a Classic Load Balancer

  1. Log in to the management console.
  2. In the upper left corner of the page, click and select the desired region and project.
  3. Click Service List. Under Network, click Elastic Load Balance.
  4. In the classic load balancer list, locate the load balancer and click its name.
  5. Under Listeners, click Add Listener. In the Add Listener dialog box, specify the parameters by referring to Table 4.
    Table 4 Parameter description

    Parameter

    Description

    Example Value

    Name

    Specifies the listener name.

    listener-ssgu

    Frontend Protocol/Port

    Specifies the protocol and port used by the load balancer to receive requests from clients and forward the requests to backend servers.

    Port range: 1 to 65535

    TCP/80

    Backend Protocol/Port

    Specifies the protocol and port used by backend servers to receive requests.

    The protocol is TCP by default, and the port numbers range from 1 to 65535.

    TCP/22

    Load Balancing Algorithm

    Specifies the algorithm used by the load balancer to distribute traffic.

    • Round robin: Requests are distributed sequentially across all servers, so that the load is evenly shared.
    • Least connections: a dynamic scheduling algorithm that estimates backend server load based on the number of active connections. Requests are routed to servers with the minimum number of connections.
    • Source IP hash: The source IP address of each request is calculated using the consistent hashing algorithm to obtain a unique hash key, and all backend servers are numbered. The generated key allocates the client to a particular server. This allows requests from different clients to be routed based on source IP addresses and ensures that a client is directed to the same server that it was using previously.
    NOTE:

    Choose an appropriate algorithm based on your requirements for better traffic distribution.

    Round robin

    Sticky Session

    Specifies whether to enable sticky sessions.

    If you enable sticky sessions, all requests from the same client during one session are sent to the same backend server.

    NOTE:

    You can enable sticky sessions only if you have set Load Balancing Algorithm to Weighted round robin.

    N/A

    Stickiness Duration (min)

    Specifies the minutes that sticky sessions are maintained. The stickiness duration ranges from 1 to 1440.

    5

    Description

    Provides supplementary information about the listener.

    N/A

    Health Check Protocol/Port

    Specifies the protocol and port used for performing health checks on backend servers.

    You can specify either TCP or HTTP. A selected protocol cannot be changed.

    Port range: 1 to 65535

    TCP/80

    Interval (s)

    Specifies the maximum time between health checks, in seconds.

    The interval ranges from 1 to 50.

    5

    Timeout (s)

    Specifies the maximum time required for waiting for a response from the health check, in seconds.

    The timeout duration ranges from 1 to 50.

    10

    Healthy Threshold

    Specifies the number of consecutive health checks necessary for a backend server to be considered healthy. The threshold ranges from 1 to 10.

    3

    Unhealthy Threshold

    Specifies the number of consecutive health checks necessary for a backend server to be considered unhealthy. The threshold ranges from 1 to 10.

    3

    Check Path

    Specifies the health check URL, which is the destination on backend servers for health checks. This parameter is available only if you set Health Check Protocol to HTTP. The path can contain 1 to 80 characters and must start with a slash (/).

    NOTE:

    The path can contain only letters, digits, and the following special characters: -/.%?#&_=

    /test.html

  6. Click OK.