×
Community Blog Load Balancing Between Starter Package ECS Instances: Part 2

Load Balancing Between Starter Package ECS Instances: Part 2

This tutorial shows you how to configure a Server Load Balancer for ECS instances created by using Alibaba Cloud's Starter Package service.

By Abdulaziz Gebril, Alibaba Cloud Community Blog author

This tutorial is the second part of the two-part series on how to configure Load Balancer for ECS instances created by using Alibaba Cloud Starter Package. In this tutorial, we will show you how to set up the Server Load Balancer for the ECS instances launched while explaining the preceding part of this tutorial series.

What Is Server Load Balancer?

Server Load Balancer (SLB) service improves your applications' performance by forwarding traffic to multiple ECS instances. By distributing traffic, it extends the servicing capability of applications. SLB also helps in eliminating single points of failure (SPOFs) to improve the availability of applications.

To get started with the SLB services, you must understand the following three key components of SLB:

1.  SLB Instances: SLB instance distributes incoming traffic to backend servers. To use the Server Load Balancer service, you must create an SLB instance, and configure it with at least one listener and two backend servers.

The cost for an SLB instance is calculated using the Pay-As-You-Go billing method and is computed based on your actual traffic usage. For more detailed information, refer Server Load Balancer Pricing.

2.  Listeners: Once the SLB instance is created, you must configure one or more listeners for the same. A listener checks for connection requests and forwards the requests to backend servers.

- <strong>Listener Protocol</strong>: SLB supports HTTP, HTTPS, TCP, and UDP protocols.
- <strong>Listening Port</strong>: It is used to receive requests and forward it to backend servers.

3.  Backend Servers: After configuring the listener, you need to add some ECS instances as the backend servers for your SLB instance to respond to the distributed client requests.

- <strong>Port of Backend Servers</strong>: The port opened on the backend server to receive requests. It can be the same in an SLB instance.
- <strong>Weight of Backend Servers</strong>: An ECS instance with a higher weight value receives more requests. Setting the weight value to zero is equal to removing the ECS instance from Server Load Balancer.

In case, a listener is not associated with a custom server group, then by default, requests are forwarded to ECS instances in the default server group.

You can set the custom server groups in the listener via VServer group mode. VServer Groups also helps to meet the requirements of domain forwarding and URL redirections.

Create SLB Instance

Log in to your Alibaba Cloud Console and click on the menu icon beside the Alibaba Cloud's logo, to view all the Alibaba Cloud Products.

1

Under the Elastic Computing section, click on Server Load Balancer and in the top navigation bar, select the region of your ECS instance.

2

If you haven't created an SLB instance in this region, you will get the following message:

3

Click on Create Instance and proceed with providing specifications to create your SLB instance.

4

  • Region: Select the same region as your previously launched ECS instances. Since SLB service does not support cross-region deployment, make sure that the ECS instances and the SLB instances are in the same region.
  • Primary Zone: It carries traffic in normal conditions.
  • Instance Name: Enter a name for the SLB instance.
  • Backup Zone: If applicable, the secondary zone only takes over traffic when the primary zone is unavailable.
  • Instance Type: There are two types of instances. An Internet SLB instance provides a public IP address and can be accessed from the Internet. An intranet SLB instance provides a private IP address and can be only accessed from the intranet. In this tutorial, we will choose Internet Instance.
  • Instance Spec: Select a performance specification for your SLB instance. The performance varies by the specification. For a shared-performance instance, performance is not guaranteed and resources are shared by all instances. The other instances provide guaranteed performance metrics and are opposite to a shared-performance instance. There are three key performance metrics for guaranteed-performance SLB instances:

    1. Max Connection: The maximum number of connections to an SLB instance at a time.
    2. Connection Per Second (CPS): The maximum number of new connections that can be established per second.
    3. Query Per Second (QPS): The maximum number of HTTP/HTTPS requests that can be processed per second.

When any of these metrics reach the limit of the specification, new connection requests will be dropped.

  • Anti-DDoS: Alibaba Cloud Anti-DDoS Basic is enabled by default while creating Server Load Balance instances and provides a 5 Gbps mitigation capacity free of charge. This service defends against various DDoS attacks, including but not limited to ICMP flood, UDP flood, TCP flood, SYN flood, and ACK flood attacks.
  • Bandwidth: The communications between ECS instances and SLB instances are through an internal network, and do not incur any traffic fees. For more information, refer to Network Traffic Flow. Traffic fees for SLB instances that use the Internet apply to outgoing traffic (downstream traffic) and no fees are charged for incoming traffic (upstream traffic).

Now, review the fees of the service, and then click on the Buy Now button.

The next screen will show your chosen SLB ECS configuration. Review your choices, and confirm that you have read and agree to the Server Load Balancer Agreement of Service, then click on the Activate button to complete the order.

5

6

In the two subsequent sections, we will discuss how to configure the SLB instance to forward and distribute the HTTP/HTTPS Traffic to our previously launched ECS instances.

Please follow one of the following two configurations, either HTTP or HTTPS Traffic forwarding on SLB instance.

Configure HTTP Traffic Forwarding on SLB Instance

To configure HTTP Traffic Forwarding on your SLB Instance, create an HTTP Listener by following the steps below:

Step1: In the left-side navigation menu, choose Instances > Server Load Balancer. Once you are on the Server Load Balancer page, click Configure Listener in the Actions column.

7

Step 2 - Protocol and Listener: Select HTTP as the listener protocol and set the listening port to 80, then click on Next.

8

Step 3 - Backend Servers: Select VServer Groups, and then click Create VServer Group under the Select Server Group section. Enter a name for the VServer Group to be created and click on the Add button under the Servers Added section.

9

Step 3.a: In the Available Servers window, you will see a list of your ECS instances in a particular SLB instance region. Select your ECS instances to add, and click on the Next: Set Weight and Port button.

10

Step 3.b: Set the Weight and Port for each added ECS instance, and click on the Next button.

Step 4: By default, Enable Health Check options are checked, and it is recommended to keep it in that way. Click on the Next button.

Step 5: Review your configuration details, and make changes if needed, and then click Submit. I the end, click OK to close the dialogue box to return to the management console.

Configure HTTPS Traffic Forwarding on SLB Instance

Follow the steps below to configure HTTPS traffic forwarding on your SLB instance:

Step1 - Upload Your SSL Certificate: Firstly, upload a server certificate by clicking on Certificates in the left-side navigation menu. SLB supports the certificates from Alibaba Cloud SSL Certificates Service or a third-party server certificate.

Click on Create Certificate and select a certificate from Alibaba Cloud SSL Certificates Service or Upload a Third-party Certificate

Step 2 - Create an HTTPS Listener: In the left-side navigation menu, choose Instances > Server Load Balancer. Next, on the Server Load Balancer page, find the SLB instance, and click Configure Listener in the Actions column.

11

Step 3 - Protocol and Listener: Select HTTPS as the listener protocol and set the listening port to 443, then click on Next.

12

Step 4 - SSL Certificates: Select the Server Certificate you have uploaded and click on Next.

13

Step 5 - Backend Servers: Select VServer Groups and click Create VServer Group under the Select Server Group section. Enter a name for the VServer Group to be created and click on Add under the Servers Added section.

14

Step 5.a: In the Available Servers window, you will get a list of your ECS instances in the selected SLB instance region. Select your ECS instances to add, and click on Next: Set Weight and Port button.

15

Step 5.b: Set the Weight and Port for each added ECS instance, and click on the Next button.

Step 6 - Health Check: By default, Enable Health Check options are checked, and it is recommended to keep it in that way. Click on the Next button.

Step 7 - Submit: Review your configuration details, and make changes if needed, and then click Submit. I the end, click OK to close the dialogue box to return to the management console.

Redirect HTTP to HTTPS

For redirecting HTTP to HTTPS, you need to create an HTTP Listener by clicking Configure Listener in the Actions column on the Server Load Balancer page and following the below steps:

Step 1 - Protocol and Listener: Select HTTP as the listener protocol, set the listening port to 80, and click on Modify in the Advanced section. Enable Redirection and select HTTPS:443 as the target port, then click on Next.

16

Step 2 - Submit: Confirm and click Submit to redirect all the HTTP requests to the HTTPS listener and distribute them according to the listener configurations of the HTTPS listener.

17

Traffic Forwarding Based on Domain Names or URLs

Server Load Balancer supports domain name-based and URL-based forwarding rules to forward requests with different domain names or URLs to various backend servers. It helps to process the client's requests for your service using your domain names instead of the public IP address of your SLB instance.

To add a domain name-based or URL-based forwarding rule, Click the ID of the SLB instance.

18

Now click the Listeners tab to find the HTTP/HTTPS listener and then click the Routing Method in the Actions column.

19

In the Add Forwarding Rules window, enter the Domain Name/URL of the requests to be forwarded, select the VServer Group, and then click Add Forwarding Rules. After adding the respective rules, click OK.

20

To resolve a domain name to the public IP address of an SLB instance, you must point it by setting a DNS A record for your domain to the public IP address of the SLB instance.

The DNS record would look like:

yourdomain.com. IN A SLB_PUBLIC_IP
www.yourdomain.com. IN A SLB_PUBLIC_IP

That's it! You have successfully configured Server Load Balancer for your ECS instances. To test your configuration, open your browser and hit the instance.html page that we have previously created for each ECS instance, using the domain name or the public IP address of your SLB instance as follows:

http://SLB_PUBLIC_IP/instance.html
http://SLB_DOMAIN_NAME/instance.html

Since the load balancer is distributing the traffic to your ECS instances, you will get different instance names while hitting the instance.html page several times.

1 0 0
Share on

Alibaba Clouder

2,599 posts | 758 followers

You may also like

Comments

5372730780198632 January 2, 2020 at 9:20 am

Dear Alibaba, After I success uploading SSL Certificate (both CA Certificate and Server Certificate) and set up http listener on load balancer, I end up getting this message on my browser, please help400 Bad RequestNo required SSL certificate was sentnginx

Alibaba Clouder April 20, 2020 at 5:53 am

Hi, there. You can create a ticket in your Alibaba Cloud console and our postsales team will help you with that. You can refer to the link below for the instruction of creating ticket: https://www.alibabacloud.com/help/doc-detail/47605.htm