All Products
Search
Document Center

Server Load Balancer:Create and manage a server group

Last Updated:Nov 21, 2024

Before you use the Network Load Balancer (NLB) service, you must create a server group and add one or more backend servers to the server group to receive client requests forwarded by NLB. By default, NLB uses the ports and protocols that you specify for server groups to forward requests to specified backend servers. This topic describes how to create and manage a server group.

Prerequisites

  • Before you add Elastic Compute Service (ECS) instances, elastic network interfaces (ENIs), or elastic container instances to a server group, make sure that the resources are created and applications are deployed on the resources to receive requests forwarded by NLB.

  • To forward requests to the backend servers in a server group, specify the server group when you create a listener or a forwarding rule. For more information, see Overview of NLB listeners.

Create a server group

  1. Log on to the NLB console.
  2. In the top navigation bar, select the region in which the NLB instance is deployed.

  3. In the left-side navigation pane, choose NLB > Server Group.

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

  5. In the Create Server Group dialog box, configure the parameters and click Create. The following table describes the parameters.

    Parameter

    Description

    Server Group Type

    Select a server group type. Valid values:

    • Server Type: allows you to add backend servers by specifying ECS instances, ENIs, or elastic container instances.

    • IP: allows you to add backend servers by specifying IP addresses.

    Note When you add backend servers by specifying IP addresses, you can specify only private IP addresses. You cannot specify public IP addresses.

    Server Group Name

    Enter a name for the server group.

    VPC

    Select a virtual private cloud (VPC) from the drop-down list.

    Backend Server Protocol

    Select a backend protocol. Valid values:

    • TCP: If you select this option, you can associate the server group with a TCP listener or a TCP/SSL listener.

    • UDP: If you select this option, you can associate the server group with a UDP listener.

    Scheduling Algorithm

    Select a scheduling algorithm. Valid values:

    • Round-Robin: Requests are forwarded to backend servers in sequence.

    • Weighted Round-Robin (default): Backend servers that have higher weights receive more requests than backend servers that have lower weights.

    • Source IP Hashing: specifies consistent hashing that is based on source IP addresses. Requests from the same source IP address are distributed to the same backend server.

    • Four-Element Hashing: specifies consistent hashing that is based on the following factors: source IP address, destination IP address, source port, and destination port. Requests that contain the same information based on the preceding factors are forwarded to the same backend server.

    • QUIC ID Hashing: specifies consistent hashing based on QUIC IDs. Requests with the same QUIC ID are forwarded to the same backend server.

    • Weighted Least Connections: Requests are forwarded based on the weights and the number of connections to backend servers. If two backend servers have the same weight, the backend server that has fewer connections receives more requests.

      Note

      You can select the QUIC ID hashing algorithm only when the backend protocol is UDP.

    Resource Group

    Select the resource group to which the server group belongs.

    Tag

    Configure the Tag Key and Tag Value parameters.

    IPv6

    Specify whether to enable IPv6.

    • If you enable IPv6, you can add IPv4 and IPv6 backend servers to the server group.

    • If you do not enable IPv6, you can add only IPv4 backend servers to the server group.

    Note

    If IPv6 is disabled for the VPC that you select for the server group, IPv6 is disabled for the server group by default.

    Connection Draining

    Specify whether to enable connection draining. By default, connection draining is disabled.

    To enable connection draining, set the Connection Draining Timeout Period parameter. Valid values: 0 to 900. Unit: seconds. A value of 0 specifies immediate disconnection.

    When you remove a backend server or a backend server is declared unhealthy, connection draining is disabled by default. Existing connections remain open until the clients proactively close the connections or the session persistence duration ends. After you enable connection draining, existing connections remain open for data transmission until the connection draining timeout period ends. Connection draining ensures a smooth undeployment of services.

    Client IP Preservation

    Specify whether to preserve client IP addresses. If client IP preservation is enabled, backend servers can retrieve client IP addresses.

    If client IP preservation is disabled, a backend server can work as a client to access your NLB instance. In this case, if you still want to retrieve client IP addresses, enable Proxy Protocol for the associated listener.

    Note

    You cannot enable client IP preservation for a server group of the IP type. If you want the server group to retrieve client IP addresses, enable Proxy Protocol for the associated listener.

    Enable All-port Forwarding

    Specify whether to enable multi-port forwarding. After you enable multi-port forwarding, you do not need to specify a port when you add a backend server. The NLB instance forwards requests to a backend server based on the frontend port.

    Note

    If you enable all-port forwarding for your listener, you must enable this feature for the backend server group.

    Enable Health Check

    Specify whether to enable health checks.

    Health Check Settings

    After health checks are enabled, you can click Modify to modify health check settings.

    Health Check Protocol

    Select a health check protocol. Valid values:

    • TCP (default): To perform TCP health checks, NLB sends SYN packets to a backend server to check whether the port of the backend server can receive requests.

    • HTTP: To perform HTTP health checks, NLB sends HEAD or GET requests to a backend server to check whether the backend server is healthy.

    • UDP: To perform UDP health checks, NLB sends ICMP echo requests and UDP probe packets to check whether the backend server is healthy.

    Note

    You can set Health Check Protocol to UDP only if you set the backend server protocol to UDP.

    Health Check Method

    Select an HTTP method that is used for health checks. Valid values:

    • GET: If the size of a response exceeds 8 KB, the response is truncated. However, the results of the health check are not affected.

    • HEAD: HTTP health checks use the HEAD method by default. Make sure that your backend servers support HEAD requests. If your backend server does not support the HEAD method or the HEAD method is disabled, the health check may fail. In this case, you can use the GET method.

    Note

    This parameter takes effect only if HTTP is specified as the health check protocol.

    Health Check Port

    Specify the ports that are probed by health checks.

    • Backend Server Port: Health checks probe the ports of backend servers. This is the default setting.

    • Custom Port: Health checks probe a specified port.

    Note

    If all-port forwarding is enabled, you must specify a specific health check port.

    Health Check Path

    Enter the URL of the health check page.

    Note

    This parameter takes effect only if HTTP is specified as the health check protocol.

    Health Check Domain Name

    Enter the domain name that is used for health checks.

    • Backend Server Internal IP: NLB uses the private IP addresses of backend servers for health checks. This is the default value.

    • Custom Domain Name: Enter a domain name.

    Note

    This parameter takes effect only if HTTP is specified as the health check protocol.

    Health Check Status Codes

    Select one or more HTTP status codes that indicate that the health check is passed.

    Valid values: http_2xx (default), http_3xx, http_4xx, and http_5xx.

    Note

    This parameter takes effect only if HTTP is specified as the health check protocol.

    Custom Request/Response

    You can turn on Custom Request/Response for UDP listener health checks. In the Custom Request field, enter custom request content, such as youraccountID. In the Custom Response field, enter custom response content, such as slb123.

    Meanwhile, you can add health check response logic to the business logic of the backend server. For example, you can configure the backend server to

    return slb123 when the backend server receives youraccountID.

    In this case, if the NLB instance receives the expected response, the backend server is declared healthy. Otherwise, the backend server is declared unhealthy. You can use this method to improve the accuracy of UDP health checks.

    Note

    This parameter takes effect only when you set the health check protocol to UDP.

    Response Timeout Period

    Specify a timeout period for a health check response. If a backend server does not respond within the specified timeout period, the backend server is declared unhealthy.

    Health Check Interval

    Specify the interval between two consecutive health checks.

    Note

    If you set Health Check Protocol to UDP, you must set the Health Check Interval parameter to a value that is equal to or larger than the response timeout period to ensure that UDP response timeouts are not determined as no responses.

    Healthy Threshold

    Specify the number of times that an unhealthy backend server must consecutively pass the health check before it is declared healthy.

    Unhealthy Threshold

    Specify the number of times that a healthy backend server must consecutively fail the health check before it is declared unhealthy.

Add backend servers by specifying ECS instances, ENIs, or elastic container instances

If you set the server group type to Server Type, you must add backend servers by specifying ECS instances, ENIs, or elastic container instances. You cannot add the same ECS instance, ENI, or elastic container instance to a server group for which all-port forwarding is enabled.

  1. On the Server Groups page, use one of the following methods to go to the Backend Servers tab:

    • Find the server group that you want to manage and click Modify Backend Server in the Actions column.

    • Find the server group that you want to manage and click its ID. On the details page of the server group, click the Backend Servers tab.

  2. On the Backend Servers tab, click Add Backend Server.

  3. In the Add Backend Server panel, select a type of cloud service and click Next.

    • ECS instances

      Select ECS/ENI and select the ECS instances that you want to add.

      If no ECS instance is available, click Purchase ECS Instance in the upper-right corner of the server list.

    • ENIs

      1. Select ECS/ENI and turn on the Advanced Mode switch.

      2. Click the 展开符合 icon next to the ID of an ECS instance and select an ENI.

        • Make sure that the ENI is associated with the ECS instance. For more information about how to associate a secondary ENI with an ECS instance, see Bind an ENI.

        • If no ECS instance is available, click Purchase ECS Instance in the upper-right corner of the server list.

    • Elastic container instances

      Select ECI for Server Type and select an elastic container instance.

      If no elastic container instance is available, click Purchase Elastic Container Instance in the upper-right corner of the instance list. NLB does not support job-optimized elastic container instances as backend servers.

  4. Specify the ports and weights of the backend servers and click OK.

    Note

    If multi-port forwarding is enabled for a server group, you do not need to specify a port when you add a backend server. NLB forwards requests to the backend server based on the frontend port.

    The default weight is 100. A server that has a higher weight receives more requests.

    You can move the pointer over the 批量操作 icon to change the weights and ports of multiple servers.

    • If you click Replicate to Below, the weights and ports of all servers below the current server are set to the weight and port of the current server.

    • If you click Replicate to Above, the weights and ports of all servers above the current server are set to the weight and port of the current server.

    • If you click Replicate to All, the weights and ports of all servers in the server group are set to the weight and port of the current server.

    • Reset:

      • If you click Reset next to Weight, the weights of all servers in the server group are reset to the default value.

      • If you click Reset next to Port, the ports of all servers in the server group are cleared.

    Warning

    If you set the weight of a server to 0, the server does not receive requests.

Add backend servers by specifying IP addresses

If you set the server group type to IP, you must add IP addresses to receive requests. You cannot add duplicate IP addresses to a server group which has all-port forwarding enabled.

Note When you add backend servers by specifying IP addresses, you can specify only private IP addresses. You cannot specify public IP addresses.
  1. On the Server Groups page, use one of the following methods to add IP addresses:

    • Find the server group that you want to manage and click Modify Backend Server in the Actions column.

    • Find the server group that you want to manage and click its ID.

  2. On the details page of the server group, click the Backend Servers tab and click Add IP Address.

  3. On the Select Servers tab of the Add Backend Server panel, enter an IP address and click Next.

    You can specify multiple ports for an IP address and specify a weight for each port.

  4. On the Ports/Weights tab, specify the ports and weights of IP addresses, and then click OK.

    Note

    If multi-port forwarding is enabled for a server group, you do not need to specify a port when you add a backend server. NLB forwards requests to the backend server based on the frontend port.

    The default weight is 100. A server that has a higher weight receives more requests.

    You can move the pointer over the 批量操作 icon to change the weights and ports of multiple servers.

    • If you click Replicate to Below, the weights and ports of all servers below the current server are set to the weight and port of the current server.

    • If you click Replicate to Above, the weights and ports of all servers above the current server are set to the weight and port of the current server.

    • If you click Replicate to All, the weights and ports of all servers in the server group are set to the weight and port of the current server.

    • Reset:

      • If you click Reset next to Weight, the weights of all servers in the server group are reset to the default value.

      • If you click Reset next to Port, the ports of all servers in the server group are cleared.

    Warning

    If you set the weight of a server to 0, the server does not receive requests.

What to do next

Operation

Procedure

Modify the basic information about a server group

  1. On the Server Groups page, find the server group that you want to manage and click Modify Basic Information in the Actions column.

  2. In the Modify Basic Information dialog box, modify the Server Group Name, Scheduling Algorithm, Enable Connection Draining, and Client IP Preservation parameters.

Modify health check settings

  1. On the Server Groups page, find the server group that you want to manage and click Modify Health Check Settings in the Actions column.

  2. In the Modify Health Check Settings dialog box, you can modify the health check settings to meet your business requirements.

Warning
  • If health checks are disabled, NLB no longer checks backend servers. If a backend server fails, traffic cannot be automatically switched to healthy backend servers.

  • If a longer health check interval is specified, more time is required for NLB to detect unhealthy backend servers.

Remove a backend server

You can remove a backend server from a server group.

Warning

If you remove a backend server from a server group, your services may be interrupted. We recommend that you set the weight of the backend server to 0 before you remove the backend server from the server group.

  1. On the Server Groups page, find the server group that you want to manage and click its ID.

  2. Click the Backend Servers tab, find the backend server that you want to remove and click Remove in the Actions column.

  3. In the Remove Backend Server message, click OK.

Delete a server group

You can delete a server group when you no longer need it. After you delete a server group, the status of the specified backend servers remains unchanged. If you no longer need a specified backend ECS instance, ENI, or elastic container instance, you can disable or release the ECS instance, ENI, or elastic container instance.

  1. On the Server Groups page, find the server group that you want to delete and choose 更多 > Delete in the Actions column.

  2. In the Remove Backend Server message, click OK.

References