How to connect load balancer with OS in Azure

deepak kapse
6 min readJun 9, 2021

Do you know how Flipkart or Amazon websites hosted in multiple OS are managed during Big Billion Days when huge users start login into the website?

Well, thanks to Loadbalancer for automatically distribute incoming traffic across multiple targets reducing the burden on single servers.

Load Balancer

Let us learn how to set up a load balancer for multiple os servers hosting a simple website on Azure cloud

plan:
1)Create a Resource group
2)Create 2 OS Servers
3)Create and host a simple HTML page
4)Create Loadbalancer
5)Connect OS to Load Balancer

First, log in to the Azure portal

1: Create a Resource group

Click on Create on Resource group
Click on +Add to create a new Resource Group

Here, I have named Resource group as mygrp1

Name the resource group

Tags are useful to identify the resource groups when there are more than one created

Name the Tags(optional)

Review and create a Resource group as the final step.

Review+create

You can see the resource group created and listed below

Dashboard

2: Setup Virtual machine with desired OS
Now. Lets create VM instance inside resource group

Create Resources

Click compute

Compute

Search for the virtual machine and click on create

Create Virtual Machine

Now, name the VM [Virtual machine] instance and setup other configurations
Here I name it as os1, region: US east us, Availability: No redundant as we are doing the demo. I chose Redhat Image

Setup and config

Setup Username and password. You can also choose ssh to get the key to access VM.

Username and password

We need the public to access our webserver via SSH or HTTP port 80.

Select Inbound ports

Choose disk to connect VM behind. It depends on your requirement of speed.

OS disk type

Setup size of disk here I chose 4GB storage SSD

Size of disk

The networking: you can leave the default or create your own subnet for customer range of IP address.

Networking

Write a bash script to do post creation of VM. Here I setup httpd apache server to host the HTML page.
#!bin/bash
yum install httpd -y
systemctl enable httpd — now

Custom data

Finally, display how much it costs per hour based on configuration

Cost

Deployment in progress

deployment

Repeat the above VM setup steps for OS2

OS2 setup

3)Create and host HTML page inside OS
Here note down the Public IP address of OS to connect from Windows Powershell. The red color box shown has Private IP needed to set up for the load balancer.

OS1 IP addresses
OS2 IP addresses

Connect OS1 from Windows Powershell
ssh -l <username> <IP address>

Windows PowerShell

Change to Root user and list and add HTTP for firewall access
firewall-cmd — list-services
firewall-cmd — add-service=http
you can make this firewall setup permanent by below command
firewall-cmd — add-service=http — permanent

firewall setup

Create HTML page and store in respective folder
cd /var/www/html/
nano index.html

create index html file

content inside index html file

content

Finally hosted webpage in public

os2 webpage

Repeat the same above steps for OS2 and change content to ensure you can identify the difference between them

os2 content
os2 webpage

4)Setup Load Balancer

Loadbalancer

Put name for load balancer and rest leave the default as it is

Config

choose existing IP address if you already have else create new one.
Keep zone redundant

Review finally before creating

Review+Create

5)Setup
Backendpool to connect with OS
choose Configuration as IPv4 and version as IPv4. Insert Private IP addresses of both os in IP address column. Here

Config

Backendpool created and displayed in load balancer dashboard. Now choose health probe and load balancer rule and configure them respectively

dashboard

Configure Health probe

Health probe

Configure load balancing rule as shown below

Loadbalancing rule

Setup done!!! Copy the loadbalancer IP address and put in google.

Loadbalancer IP address

Displaying os1 webpage by loadbalancer

OS1 webpage

Displaying the OS2 webpage after continuous refresh causing increase in traffic.

OS2 webpage

Don't forget to Stop both the os and click to save the IP addresses as static

Stop OS

--

--