How to connect load balancer with OS in Azure
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.
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
Here, I have named Resource group as mygrp1
Tags are useful to identify the resource groups when there are more than one created
Review and create a Resource group as the final step.
You can see the resource group created and listed below
2: Setup Virtual machine with desired OS
Now. Lets create VM instance inside resource group
Click compute
Search for the virtual machine and click on create
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 Username and password. You can also choose ssh to get the key to access VM.
We need the public to access our webserver via SSH or HTTP port 80.
Choose disk to connect VM behind. It depends on your requirement of speed.
Setup size of disk here I chose 4GB storage SSD
The networking: you can leave the default or create your own subnet for customer range of IP address.
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
Finally, display how much it costs per hour based on configuration
Deployment in progress
Repeat the above VM setup steps for OS2
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.
Connect OS1 from Windows Powershell
ssh -l <username> <IP address>
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
Create HTML page and store in respective folder
cd /var/www/html/
nano index.html
content inside index html file
Finally hosted webpage in public
Repeat the same above steps for OS2 and change content to ensure you can identify the difference between them
4)Setup Load Balancer
Put name for load balancer and rest leave the default as it is
choose existing IP address if you already have else create new one.
Keep zone redundant
Review finally before creating
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
Backendpool created and displayed in load balancer dashboard. Now choose health probe and load balancer rule and configure them respectively
Configure Health probe
Configure load balancing rule as shown below
Setup done!!! Copy the loadbalancer IP address and put in google.
Displaying os1 webpage by loadbalancer
Displaying the OS2 webpage after continuous refresh causing increase in traffic.
Don't forget to Stop both the os and click to save the IP addresses as static