Load Balancing Between Starter Package ECS Instances: Part 2

Image for post
Image for post

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.

Image for post
Image for post

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

Image for post
Image for post

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

Image for post
Image for post

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

Image for post
Image for post
  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.

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.

Image for post
Image for post
Image for post
Image for post

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.

Image for post
Image for post

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

Image for post
Image for post

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.

Image for post
Image for post

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.

Image for post
Image for post

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.

Image for post
Image for post

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

Image for post
Image for post

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

Image for post
Image for post

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.

Image for post
Image for post

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.

Image for post
Image for post

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.

Image for post
Image for post

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.

Image for post
Image for post

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.

Image for post
Image for post

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

Image for post
Image for post

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.

Image for post
Image for post

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.

Original Source

Written by

Follow me to keep abreast with the latest technology news, industry insights, and developer trends.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store