Public Load Balancer in Azure Step By Step
Public Load Balancers in this blog I am going to show you how to set up a public load balancer in Azure. Distribute the incoming traffic over multiple servers. Here, it will divide up the load over two Virtual Machines.
Create Virtual Machines
Create VMs in each virtual network (VNet) so that we can communicate between them.
1st VM
1- On the Azure portal menu tab, select Virtual machines
2- Select the + Add button to create virtual machine.
3- Resource group select create new.
4- Type resource group name (rg-web) and then click OK.
5- Instance details
Enter a virtual machine name (web1)
Region select (East US)
Availability options – select Availability set.
Availability set select to create new.
6- Enter a Availability set name (loadbalanceset) and then click OK.
7- Image select Windows Server 2019 Datacenter.
You can select a various operating system, but the remaining steps assume you selected Windows Server 2019 Datacenter.
8- Administrator account
Enter a username (jamil), Password.
Public inbound ports choose to allow selected ports.
Select inbound ports (HTTP, HTTPS, RDP) and then click on Review + create >
9- Select create
Create the second VM
10- Complete steps 2-9 again, with the following changes:
Name | Value |
Resource group | rg-web |
Virtual machine name | web2 |
Region | (US) West US |
Availability options | Availability set |
Availability set | loadbalanceset |
Image | Windows Server 2019 Datacenter |
Administrator account | username password |
Public inbound port | allow selected ports |
Select inbound ports | HTTP, HTTPS, RDP |
Create |
11- The VMs take a few minutes to create. Now the both VMs (web1, web2) successfully created.
Create Network Load Balancer
1- Select Microsoft Azure menu bat and then select Load Balancers
2- Select create load balancer.
3- Select resource group (rg-web)
4- Enter the name of Load Balancer, select Region (East US), keep it Public and SKU Basic. Set the Public Address. Create new, enter a name (lbpublicip) keep it dynamic and then select Review + create >.
5- Click on Create.
6- Now you can see load balancer successfully created, click on (lbweb)
First, I am going to configure Health Probes for our Load Balancer. So, we want to specify how many servers we want to make the Load Balancer.
In the Backend Pools, we specify the servers which we are going to use in the Load Balancer.
Backend Pools
7- Click on Backend Pools and then click on + Add.
8- Add backend pool wizard, Type a name
Virtual network (rg-web)
Associate to select virtual machines and then click the add button under a virtual machine.
9- Add virtual machine to backend pool wizard; Select the VMs and then click add.
10- After selecting the VMs, then click on Add.
11- The backend pool has been configured successfully. Inside Load Balancer, go to Health Probes
12- Click on Add.
13- Enter a name to the Health Probe.
Protocol (HTTP)
The interval shows that it is going to make a probing attempt at 5-second intervals. The unhealthy threshold shows that after 2 attempts failed probe, it is going to declare it as an unhealthy server. Click ok
14- Health probe successfully created, click on Load Balancing Rules.
15- Click on + Add button
16- Add load balancing rule wizard, The IP version is IPv4
Select frontend IP Address
The protocol is TCP, the port number is 80
Backend port is 80, the backend pool is the one that we have just created and the health probe is the one that we have created.
Session persistence is by default – None
Idle timeout is by default – 4 minutes.
Floating IP disabled. Click on OK.
17- Load Balancing Rule has been created.
Now we need to install Web Server IIS roles on both the VMs (web1, web2)
How to install web server IIS.
Test Network Load Balancer
After installing web server IIS roles on both VMs.
1- Open directory C:\inetpub\wwwroot\ on each VM and then delete these files.
2- Right-click, select new and then click text documents.
3- Open the text file.
4- Type this is windows server web1
Select file and then save as.
5- Type index.html Save as type (All Files) and click save.
6- Select Azure menu and then load balancers.
7- Click on load balancer (lbweb)
8- In the Load Balancer, I have my Public IP address (lbpublicip). Copy it and paste it in the explorer address bar.
9- On the first hit, it has taken me to web1 server.
10- Wait for 4 minutes then hit enter again, it is take you to web2 server.