You must create a server group and add one or more backend servers to the server group before you can use Application Load Balancer (ALB). After you complete these tasks, the specified backend servers can receive requests distributed by ALB. By default, ALB uses the ports and protocols that you specify for server groups to distribute requests to the specified backend servers.
Prerequisites
Elastic Compute Service (ECS) instances that you want to add to a server group are created and applications are deployed on the ECS instances to receive requests. For more information, see Create an instance by using the wizard and Manually build an LNMP environment on an Alibaba Cloud Linux 2 instance.
The server group to which you want to distribute requests is specified when you create a listener. For more information, see Add an HTTP listener, Add an HTTPS listener, or Add a QUIC listener.
(Optional) An IPv6 CIDR block is enabled for the virtual private cloud (VPC) of the server group for which you want to enable IPv6. For more information, see Enable IPv6 for a VPC.
Create a server group
- Log on to the ALB console.
In the top navigation bar, select the region where you want to create a server group.
In the left-side navigation pane, choose .
On the Server Groups page, click Create Server Group.
In the Create Server Group dialog box, configure the following parameters and click Create.
Server: Backend servers are added by specifying ECS instances.
IP: Backend servers are added by specifying IP addresses.
Function Compute: Backend servers are added by specifying functions.
HTTP: This is the default value. If you select this option, you can associate the server group with HTTPS, HTTP, and QUIC listeners.
HTTPS: If you select this option, you can associate the server group with HTTPS listeners.
gRPC: If you select this option, you can associate the server group with HTTPS listeners.
You can associate only server groups that use HTTPS or gRPC with HTTPS listeners of basic ALB instances.
This parameter is unavailable for server groups of the Function Compute type.
Weighted Round-robin: Backend servers that have higher weights receive more requests than backend servers that have lower weights.
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.
Consistent Hash: Requests from the same source IP address are forwarded to the same backend server.
Hash Factor: Select a hash factor.
Source IP: Requests from the same source IP address are forwarded to the same backend server.
URL Parameter: Requests for the same URL are forwarded to the same backend server. If you select this operation, specify the Specified URL parameter.
If you enable IPv6, you can add IPv4 and IPv6 backend servers to the server group. You can set Server Group Type only to Server.
If you disable IPv6, you can add only IPv4 backend servers to the server group. You can set Server Group Type to Server, IP, or Function Compute.
If IPv6 is disabled for the VPC of the server group, you cannot enable IPv6.
This parameter is unavailable for server groups of the IP and Function Compute types.
When you create a listener for an IPv4 ALB instance, you cannot add server groups for which IPv6 is enabled.
Cookie Option: Select a method to handle cookies.
Insert Cookie: ALB inserts a session cookie (SERVERID) into the first HTTP or HTTPS response that is sent to a client. Subsequent requests to ALB carry this cookie, and ALB determines the destination servers of the requests based on the cookie.
Rewrite Cookie: When ALB detects a user-defined cookie, ALB replaces the original cookie with the user-defined cookie. Subsequent requests to ALB carry this user-defined cookie, and ALB determines the destination servers of the requests based on the cookie.
Session Persistence Timeout Period: Specify the timeout period of session persistence. Valid values: 1 to 86400. Unit: seconds.
When you create a health check, you do not need to specify a server group or a listener. You can associate the health check with a server group or a listener after the health check is created.
You can configure only one health check for each backend server.
HTTP: ALB performs HTTP health checks by sending HEAD or GET requests to a backend server to check whether the backend server is healthy.
HTTPS: ALB performs HTTPS health checks by sending HEAD or GET requests to a backend server to check whether the backend server is healthy. For more information, see the Limits on HTTPS health checks section of this topic.
TCP: ALB performs TCP health checks by sending SYN packets to a backend server to check whether the port of the backend server is available to receive requests.
gRPC: ALB performs gRPC health checks by sending POST or GET requests to a backend server to check whether the backend server is healthy.
HEAD: By default, HTTP health checks use the HEAD method. Make sure that your backend servers support HEAD requests. If your backend servers do 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.
POST: By default, gRPC health checks use the POST method. Make sure that your backend servers support POST requests. If your backend servers do not support the POST method or the POST method is disabled, the health check may fail. In this case, you can use the GET method.
GET: If the size of a response exceeds 8 KB, the response is truncated. The results of the health check are not affected.
This parameter takes effect only if the Health Check Protocol parameter is set to HTTP, HTTPS, or gRPC.
HTTP and HTTPS health checks support the HEAD and GET health check methods. gRPC health checks support the POST and GET health check methods.
Backend Server Port: ALB uses the ports of backend servers to perform health checks. This is the default value.
Custom Port: ALB uses a specified port to perform health checks. Valid values: 1 to 65535.
Backend Server Internal IP: The private IP addresses of backend servers are used for health checks. This is the default value.
Custom Domain Name: Enter a domain name. The domain name must be 1 to 80 characters in length and can contain only lowercase letters, digits, periods (.), and hyphens (-). The domain name must contain at least one period (.), but cannot start or end with a period (.).
If the health check protocol is set to HTTP or HTTPS, you can select http_2xx, http_3xx, http_4xx, and http_5xx. http_2xx and http_3xx are selected by default.
If you set the Health Check Protocol parameter to gRPC, the valid values are 0 to 99. Value ranges are supported. You can enter up to 20 value ranges and must separate ranges with commas (,).
Parameter | Description |
Server Group Type | Select a server group type. Valid values: |
Server Group Name | Enter a name for the server group. |
VPC | Select a VPC from the VPC drop-down list. Only servers in the VPC can be added to the server group. Note This parameter is unavailable for server groups of the Function Compute type. |
Backend Server Protocol | Select a backend protocol. Valid values: Note |
Scheduling Algorithm | Select a scheduling algorithm. Valid values: Note This parameter is unavailable for server groups of the Function Compute type. |
Resource Group | Select the resource group to which the ALB instance belongs. |
Tag | Configure the Tag Key and Tag Value parameters. |
IPv6 Support | Specify whether to enable IPv6. IPv6 is disabled by default. Note |
Session Persistence | Specify whether to enable session persistence. If session persistence is enabled, ALB forwards all requests from a client to the same backend server. Note This parameter is unavailable for server groups of the Function Compute type. |
Persistent Connection | Specify whether to enable the persistent TCP connection feature. When this feature is enabled, a specific number of TCP connections are kept alive between ALB and the backend servers. When the ALB instance receives a new request and an idle persistent TCP connection exists, ALB preferentially uses the TCP connection to forward the request to the backend servers. This reduces the number of TCP handshakes and the loads of the backend servers. Note This parameter is unavailable for server groups of the Function Compute type. |
Health Check | Specify whether to enable health checks. |
Health Check Settings | If you enable health checks, you can click Modify on the right side of Health Check Setting to show more health check settings. |
Select and Load Health Check | Select and load a health check. Note |
Health Check Protocol | Select the protocol of the health check. For more information about the limits on HTTPS health checks, see Limits on HTTPS health checks. |
Health Check Method | Select a health check method. Valid values: Note |
Health Check Protocol Version | Select an HTTP version. Valid values: HTTP1.0 and HTTP1.1. Note This parameter is effective only if HTTP or HTTPS is specified as the health check protocol. |
Health Check Port | Specify the ports on which you want to perform health checks. |
Health Check Path | Enter the URL of the health check page. The URL must be 1 to 80 characters in length, and can contain letters, digits, hyphens (-), forward slashes (/), periods (.), percent signs (%), question marks (?), number signs (#), and ampersands (&). The URL can also contain the following extended characters: |
Health Check Domain Name | Enter a domain name that is used for health checks. |
Health Check Status Codes | Select one or more HTTP status codes. The specified HTTP status codes are used to indicate that a backend server passes a health check. Note This parameter takes effect only if HTTP, HTTPS, or gRPC is specified as the health check protocol. |
Response Timeout Period | Specify the timeout period of a health check response. If a backend server does not respond within the specified timeout period, the server fails the health check. |
Health Check Interval | Specify the interval between two consecutive health checks. |
Healthy Threshold | Specify the number of times that an unhealthy backend server must consecutively pass health checks before it is declared healthy. |
Unhealthy Threshold | Specify the number of times that a healthy backend server must consecutively fail health checks before it is declared unhealthy. |
Save the health check configurations as a template, which can facilitate health check creation and configurations | You can select the check box to save the health check template. If you select this option, you must enter a name for the template. Note This parameter takes effect only if you set the Select and Load Health Check parameter to Custom Health Check. |
Add backend servers
After you create a server group, you must add one or more backend servers to the server group. Then, the specified backend servers can receive requests distributed by ALB.
Add backend servers of the Server type
If you set the server group type to Server, you must add backend servers by specifying ECS instances, elastic network interfaces (ENIs), or elastic container instances.
- Log on to the ALB console.
In the left-side navigation pane, choose .
On the Server Groups page, find the server group that you want to manage and click Modify Backend Server in the Actions column.
On the Backend Servers tab, click Add Backend Server.
In the Add Backend Server panel, select a type of cloud service and click Next.
ECS instances
Select ECS/ENI for Server Type and select the ECS instances that you want to add.
If no ECS instance is available, click Buy ECS in the upper-right corner of the instance list.
ENIs
Select ECS/ENI for Server Type and turn on Advanced Mode.
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 Associate an ENI.
If no ECS instance is available, click Buy ECS in the upper-right corner of the instance 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.
In the Ports/Weights step, specify the ports and weights of the backend servers and click OK.
The default weight is 100. A server that has a higher weight receives more requests. If session persistence is enabled, requests may not be evenly distributed to backend servers.
You can change the weights of multiple servers by moving the pointer over the
icon.
If you click Replicate to Below, the weights of all servers listed below the current server are set to the same weight as the current server.
If you click Replicate to Above, the weights of all servers listed above the current server are set to the same weight as the current server.
If you click Replicate to All, the weights of all servers in the server group are set to the same weight as the current server.
If you click Reset next to Weight, the weights of all servers in the server group are reset to the default value.
WarningIf you set the weight of a server to 0, the server does not receive requests.
Add backend servers of the Function Compute type
If you set the server group type to Function Compute, you must add functions to receive requests. For more information, see Specify a function from Function Compute as a backend server of ALB.
ALB and Function Compute communicate over the secure internal network of Alibaba Cloud.
- Log on to the ALB console.
In the left-side navigation pane, choose .
On the Server Groups page, find the server group that you want to manage and click Modify Backend Server in the Actions column.
On the Backend Servers tab, click Add Function.
NoteYou can add only one function of Function Compute to a server group of an ALB instance.
In the Add Backend Server panel, use one of the following methods to add a function and click OK.
Add a function by selecting the function
Parameter
Description
Configuration Method
Select a mode for adding a backend server.
Select Service from the drop-down list.
Services
Select a Function Compute service. If no services are available, click Create a service to create a Function Compute service. For more information, see Create a function.
Version
Select LATEST.
By default, a newly created service runs only the LATEST version.
Function
Select the function that you created from the drop-down list. If no functions are available, click Create a function to create a function. For more information, see Manage functions.
Description
Enter a description.
Add a function by specifying the Alibaba Cloud Resource Name (ARN)
Parameter
Description
Configuration Method
Select a mode for adding a backend server.
Select ARN from the drop-down list.
ARN
Enter the ARN of the function that you want to add.
You can obtain the ARN of a function on the details page of the function in the Function Compute console. For more information, see Obtain the ARN of a function.
Description
Enter a description.
Add backend servers of the IP type
If you set the server group type to IP, you must add IP addresses to receive requests. If you do not enable the remote IP address feature, the IP addresses that you want to add must be within the CIDR block of the current VPC. If you enable the remote IP address feature, you can add IP addresses that are not within the current VPC CIDR block. For more information, see Specify an ECS instance in a VPC as a backend server of ALB in a different region and Specify an on-premises server as a backend server of ALB.
Limits:
You can add only internal-facing servers and cannot add Internet-facing servers.
You cannot add a backend server of the IP type to an ALB instance, a Network Load Balancer (NLB) instance, and a Classic Load Balancer (CLB) instance in the same VPC.
You can use Enterprise Edition transit routers and Express Connect circuits for cross-region forwarding. Basic Edition transit routers are not supported.
Each region in a network that is managed by a Cloud Enterprise Network (CEN) instance can have only one VPC that contains one or more ALB instances to which backend servers are added across regions.
You cannot enable ALB instances in multiple VPCs in the same region to use the same transit router to access backend services.
You cannot enable ALB instances in multiple VPCs in the same region to use multiple transit routers to access the same backend service.
Network traffic between an ALB instance and its backend servers can be routed only based on the system route table. VPC custom route tables are not supported.
- Log on to the ALB console.
In the left-side navigation pane, choose .
On the Server Groups page, find the server group that you want to manage and click Modify Backend Server in the Actions column.
On the Backend Servers tab, click Add IP Address.
In the Add Backend Server panel, enter the IP addresses of backend servers and click Next.
If you enable the remote IP address feature, IP addresses that fall into the following CIDR blocks are supported:
10.0.0.0/8
100.64.0.0/10
172.16.0.0/12
192.168.0.0/16
If you do not enable the remote IP address feature, only IP addresses that fall into the CIDR block of the VPC in which the server group is created are supported.
NoteYou can click + Add IP Address to add multiple backend servers.
In the Ports/Weights step, set the ports and weights of the backend servers and click OK.
The default weight is 100. A server that has a higher weight receives more requests. If session persistence is enabled, requests may not be evenly distributed to backend servers.
You can change the weights of multiple servers by moving the pointer over the
icon.
If you click Replicate to Below, the weights of all servers listed below the current server are set to the same weight as the current server.
If you click Replicate to Above, the weights of all servers listed above the current server are set to the same weight as the current server.
If you click Replicate to All, the weights of all servers in the server group are set to the same weight as the current server.
If you click Reset next to Weight, the weights of all servers in the server group are reset to the default value.
WarningIf you set the weight of a server to 0, the server does not receive requests.
Remove a backend server
You can remove a backend server from a server group as needed. After the server is removed, the server no longer processes client requests.
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.
- Log on to the ALB console.
In the left-side navigation pane, choose .
On the Server Groups page, find the server group that you want to manage and click its ID.
Click the Backend Servers tab, find the backend server that you want to remove, and then click Remove in the Actions column.
In the message that appears, click OK.
Modify health checks
You can modify the health check configurations of a server group as needed.
- Log on to the ALB console.
In the left-side navigation pane, choose .
On the Server Groups page, find the server group that you want to manage and click Modify Health Check Settings in the Actions column.
In the Modify Health Check dialog box, enable or disable the health check, or click Modify next to Advanced Settings to modify the health check parameters.
WarningAfter health checks are disabled, ALB no longer checks the health status of the backend servers. If a backend server is down, network traffic cannot be automatically switched to healthy backend servers.
If you specify a longer health check interval, more time is required for ALB to detect unhealthy backend servers.
Delete a server group
If a server group is not specified in the forwarding rules that listeners use, you can delete the server group. For more information about how to delete a forwarding rule, see Delete a forwarding rule.
After you delete a server group, the backend servers in the server group are not affected. If you no longer need an ECS instance, you can stop or release the ECS instance. For more information, see Stop an instance or Release an instance.
- Log on to the ALB console.
In the left-side navigation pane, choose .
On the Server Groups page, find the server group that you want to delete and choose in the Actions column.
In the message that appears, click OK.
References
CreateServerGroup: creates a server group.
AddServersToServerGroup: adds backend servers to a server group.
RemoveServersFromServerGroup: removes backend servers from a server group.
DeleteServerGroup: deletes a server group.