×
Community Blog How to Set up a Web Server with High Availability Using Server Load Balancer

How to Set up a Web Server with High Availability Using Server Load Balancer

This article explains how to set up a web server with high availability using Alibaba Cloud Server Load Balancer.

By Alain Francois

All organizations use a variety of business-critical databases and applications, such as data warehouses, e-commerce applications, etc. There is an expectation that these systems are always working, and there will never be any downtime even if it is impossible to rule out entirely. However, the IT team is responsible for minimizing the risk of that happening. You need to eliminate single points of failure to achieve this. This way, if one element goes down, such as a server, the service is still available. That's why you need to implement high availability to prevent such disasters from happening. Cloud computing has been used by different types of clients because it has many advantages, and high availability has been one of the biggest challenges. Alibaba Cloud offers Server Load Balancer (SLB) to implement a high availability solution.

What Is Server Load Balancer?

Server Load Balancer is a traffic distribution and control service that automatically distributes inbound traffic across multiple web-based applications, microservices, or containers hosted on Alibaba ECS instances. You can use SLB to prevent service disruptions caused by single points of failure (SPOFs) and improve the availability of applications as the distribution traffic is done across groups of backend servers to improve the service capability and application availability.

Server Load Balancer Types

Alibaba Cloud provides two types of Server Load Balancer (SLB) instances:

  • Application Load Balancer (ALB) provides ultra-high Layer 7 processing capabilities such as HTTPS offloading. Each ALB instance supports up to one million queries per second (QPS). An ALB instance serves as a cloud-native gateway on Alibaba Cloud and provides advanced content-based routing features. ALB instances can forward, redirect, and rewrite messages based on user-defined HTTP headers, cookies, and query strings.
  • Classic Load Balancer (CLB) supports TCP, UDP, HTTP, and HTTPS. CLB provides robust processing capabilities at Layer 4 and basic processing capabilities at Layer 7.

The chart below shows some differences between ALB and CLB:

1

Server Load Balancer Benefits

  • Multiple Protocol Support: Layer 4 load balancing over TCP or UDP. Layer 7 loading balancing over HTTP or HTTPS, QUIC protocol, and Google Remote Procedure Call (gRPC)
  • Multi-Level Disaster Recovery: Multi-zone deployment in specific regions, cluster deployment and session synchronization, and the health status monitoring of backend servers on a regular basis
  • Higher Security and Reliability: Layer 4 security (DDoS, SYN flood, UDP flood, ACK flood, ICMP flood, and DNS flood attacks), Layer 7 security (Web Application Firewall), and certificate management
  • High Performance: Extra large-sized SLB instance
  • Flexible Scheduling: Weighted round-robin (WRR) and consistent hash (CH), Domain name-based forwarding, and URL-based forwarding
  • Flexible Management and Billing: Subscription and pay-as-you-go billing methods, pay-by-data-transfer and pay-by-bandwidth metering methods, management with console, OpenAPI Explorer, and Alibaba Cloud SDKs

Since an SLB is a group of servers, you need to create two ECS instances as our web server first.

Understanding the Key Points and Procedure

This guide will configure the high availability of web servers with SLB. If you want to do this, you need to:

  • Create two ECS instances (ex: Ubuntu 20.04) in the same region. They can be in different zones to increase service availability.
  • Deploy Nginx as a web server on the two ECS instances
  • Create an SLB instance in the same region as the two instances. Also, the SLB instance must be in the same VPC as the ECS. The ECS instances will help carry the traffic forwarded by the listener of Server Load Balancer.
  • Configure the two ECS instances for the SLB
  • SLB will set a virtual IP address to virtualize the ECS in the same region into an application poot featuring high performance and availability.
  • The concept of Server Load Balancer consists of an SLB instance and listeners that will distribute clients' requests to the backend servers according to the configurations done in listeners’ rules.

2

Creating ECS Instances

We need to create two ECS instances in which we will install Nginx as the web server for test purposes.

Log into your Alibaba Cloud account and go to the _Elastic Compute Service_:

3

On the left panel, scroll to Instances & Images and select Instances to create a new ECS instance:

4

We will create Pay-As-You-Go instances. We will create each instance in a different zone but with the same VPC:

5

Select the operating system and define the disk size:

6

Select the VPC that will be used for your instance:

7

Configure if you will access your ECS with a password or a public key:

8

In the next step, you can select the default resource group:

9

You will see a review of your ECS configuration and order:

10

Now, you can see your new instance. Make sure to take the public IP for the remote access later:

11

Access your server with SSH and update the system package manager to install Nginx. Those operations should be done on the two ECS instances:

$ sudo apt update && sudo apt install nginx

12

List the default application recognized by ufw to allow the appropriate protocol:

$ sudo ufw app list

13

We will authorize the profile Nginx Full to allow web access for the HTTP and HTTPS protocols:

$ sudo ufw allow 'Nginx Full'

You also need to authorize the SSH protocol if we don't want to lose our remote access:

$ sudo ufw allow 'OpenSSH'

Restart the firewall:

$ sudo ufw disable && sudo ufw enable

Start the Nginx service:

$ sudo systemctl start nginx

Enable it on the startup:

$ sudo enable nginx

We will edit the default page of our web page and indicate the web-server1 and the web-server2 to have a good view of the load balancer after setting it up. Edit the line listed below to achieve that:

$ sudo vim /var/www/html/index.nginx-debian.html 
.....
.....
    <h1>Welcome to nginx! demo web-server1</h1>
.....
.....

Open your browser and try to access Nginx with http://IP-SERVER:

14

Test the same on the second webserver:

15

Now that the job is done on the two servers, let's configure SLB.

Creating a Server Load Balancer Instance

As explained, there are two types of SLB. In our case, we will need the Alibaba Cloud Application Load Balancer (ALB) for HTTP High Availability because it supports HTTP and HTTPS protocols. So, we will create an ALB instance:

16

You will see the SLB homepage. Now go to the ALB instance to create one:

17

You will need to select some values that we will explain:

  • Region: The same region as the two ECS instances
  • Network Type: It is public-facing for Internet access, but you will be charged for Elastic IP later. If you select _internal_, the ALB instance will only be accessible over private networks.
  • VPC: Select the same VPC as the two ECS instances
  • Zone: You can select two zones to ensure high availability. There should be vSwitches available in the selected zones. If not, you will be asked to create one. Also, Elastic IP will be automatically assigned for each vSwitch of each zone. You will be charged for the EIP. If you already possess an EIP, you can select it if it's not a _Subscription EIP_, associated with other EIP bandwidth plans, or a Pay-as-you-go EIP that uses the pay-by-bandwidth metering method.
  • IP Mode: Dynamic can have more than one IP address available, so the ALB instance will automatically increase the number of IPs along with the workload. Only one IP address will be available in each zone in Static mode. Remember the ALB instance will support 100,000 queries per second (QPS) maximum. The Dynamic mode will create a virtual domain name for web access. You can create a CNAME record to bind the virtual domain name of the SLB instance to your domain name (the one used to access the website).
  • Edition: Basic supports basic routing features, such as forwarding requests based on domain names, URLs, and HTTP headers. If you also need support for custom TLS security policies, redirection, and rewriting, you should select the Standard edition.
  • Billing Method: The default billing method is Pay-By-Data-Transfer if you select a public-facing network type.

18

You will see a review of your order. Confirm it. You can go back to the SLB overview menu page:

19

You can see the detail of the instance if you go back to the ALB instances menu:

20

Configuring SLB Server Groups

SLB also consists of backend servers in our server group. It means we need to create a server group that will contain our two Nginx ECS instances. Go to the ALB server groups to create one:

21

Add the following parameters:

Server Group Type: Instance to manage our ECS

VPC: The same VPC as the ECS instances

Backend Server Protocol: HTTP for this case

Scheduling Algorithm: Weight Round Robin will help select how the requests will be forwarded to the backend servers. When adding backend servers, we will need to indicate the weight for each server. The default value is 100. The greater the weight of a server, the more requests are forwarded. It can help to define a main server.

Resource Group: Select one

Session Persistence: Let it be disabled. When it's enabled, ALB will forward all requests from a client to the same backend server meaning the backend servers may not be balanced.

Configure Health Check: We will enable it, and the default health check settings will be used.

Advanced Configurations: You can go there for more configurations:

  • Health check protocol (HTTP or TCP)
  • Health check method (HEAD or GET requests)
  • HTTP1.0 or HTTP1.1
  • The port to listen on the backend server, you have customized the port to use it (instead of the default 80 for HTTP)
  • The URI of the web page to check. The root folder is / by default.
  • Health Check Domain Name
  • HTTPS status codes are considered to be healthy (by default http_2xx like status 200)
  • The maximum amount of time to wait when receiving a health check response
  • The interval between individual health check
  • Healthy and unhealthy threshold values to consider if a server is healthy or not

22

When you select _Create_, you will be prompted to add the backend servers to the new server groups:

23

Alternatively, you can go through the new group servers we just created:

24

You can add the backend servers:

25

Make sure to indicate the weight of each server to forward the requests:

26

You can see your backend servers added to the SLB:

27

Creating a Listener for the ALB Instance

After creating the group and backend servers, we need to create a listener so the SLB instance can listen to the ECS instances. Go back to the ALB instance menu and click on our instance:

28

Select create a listener:

29

You will have to configure the listener by indicating the protocol and the port number on which it should listen:

30

You need to select the server group. It will automatically list the backend servers and the status of each server:

31

You will have to confirm the configuration:

32

You will receive a confirmation prompt:

33

Once your listener is created, you need to find the virtual IP address or the virtual domain name of the Server Load Balancer that was automatically created. You can see if the requests will be forwarded to the backend server. Go to the instance details menu. You will see the virtual domain name that has been mapped to the virtual Elastic IP assigned on the vSwitches when creating our SLB instance.

34

Enter the virtual domain name to the browser to see if your SLB configuration works http://virtual-SLB-domain-name. If you refresh the page continuously, you will see that the requests are forwarded to each server of the server group. You can decrease the weight of one server to have a different result.

35
36

Since the generated virtual domain is too complicated, if you can use your clients to access your website, you can set up the domain name for the website by creating a CNAME record that will be bound to the virtual domain created for the SLB instance.

37
38

Conclusion

High availability on the cloud is achieved by creating clusters and being a group of servers that act as a single server to provide continuous uptime. Alibaba Cloud has added increased hardware and platform stability for applications, developers, and enterprise users with the solution provided.

0 0 0
Share on

Alibaba Cloud Community

1,042 posts | 256 followers

You may also like

Comments