How Load Balancer Works

In this blog article we are going to look at the basic capability of a load balancer in Oracle Cloud Infrastructure (OCI). 

In my previous blog, I explained how to create VCN, instances and configure connectivity from the Internet. If you are not familiar with that, please refer to the blog here

The objective of this blog is to add load balancer to the environment and observe its basic capability.

Our intention is to showcase load balancer can consume the service from two (or multiple) servers. Therefore we are going to publish a web page with server name. So, after creating the load balancer, we should be able to see web service is coming from both the compute servers.

Activities 

We are going to carry out the following actions.

  1. Install and enable web server
  2. Create HTML file
  3. Configure security rules
  4. Create load balancer
  5. Test load balancing

Architecture

Figure below shows the architecture that we are going to achieve. Here, all focus components are in the public subnet. As this is a continuation of previous blog. Therefore, its assumed that computes and VCN are already created.

1. Install and enable web server

Login to ‘AppA’ server using putty session (or your preferred method)

  • Update yum package repositories (yum update -y)

  • Install Apache Web Service (yum install httpd -y)

  • Start Apache Service (systemctl start httpd) and Enable (systemctl enable httpd)

2. create html file

  • Navigate to te Apache web root directory

  • Create ‘index.html’ file

  • Paste the HTML code below. When applying to compute B, make sure to change the title and code to “Hello from Compute B”

3. configure security rules

We’ll need to allow port ‘80’ from the security list to access the service from outside.

Then we need to stop linux firewall on compute.

We can now test whether the website is up and running by copying public IP of the computes on browser.

4. create load balancer

In this section we discuss the steps to create a load balancer.

In this scenario, we are creating the load balancer as a ‘Public’ load balancer. It is require to select the correct VCN and public subnet also.

There are three methods available to balance the load. In this scenario we choose ‘weighted round robin’. Which means, every new request will direct to a new server.

Then we need to add our computes as ’backends’.

The listener will be use HTTP port in this example.

Once created, load balancer status should ‘Ok’ as below.

5. test load balancing

Let’s test whether the load balancer is actually working. We can get the public IP of load balancer from the OCI console and copy to a web browser. It should appear one of the compute name.

Then we can refresh and see to observer load is now the load is coming from the other compute node.