Configuring a Load Balancer on Azure [Exclusive Guide]
I propose to you today to discover and implement a Load swing in Azure. And the explanations are to be more concrete, let’s set up the scenario I schematized below:
the principle is simple, we have 2 web servers running under Ubuntu (nous aurions pu faire la même chose avec Windows Server & IIS) . On these 2 servers, we will of course install Apache 2 as a tool to view web pages.
Step 0 – Presentation of the scenario
If you look at the diagram more meadows, you will notice that we will need the following components:
- 1 Resource Group – AZRSG01 , which will contain the set of Azure resources that we created for our scenario,
- 1 public IP – AZPIP01, for us to access our web servers from the outside
- 1 Load Balancer – AZELB01 to spread the load on our 2 web servers (j’y reviendrai plus bas dans l’article) ,
- 1 Set Availability, AZAVS01,
- our 2 virtual machines: AZWEB01 and AZWEB02 .
- Without forgetting of course the components networks namely a VNet AZVNT01 and its subnet default AZSNT01 partner (tout deux en 10.0.0.0/24),
- Ainsi qu’un Network Security Group AZNSG01 avec pour règles autorisées: TCP/80 et TCP/22 en Inbound.)
Step 1 – Creation of the bricks Azure base
Let’s start so we not create our resource group . In my case, notice that I’ll create everything on location West Europe but free you to choose something else or appoint the components differently.
For the subscription, I lets you choose what suits you best and don’t forget that if you have not yet created your account of tests Azure you can receive a credit of test 170 euros! 🙂
once our Resource Group is created, Let’s now created our public IP – AZPIP01.
Then, we create our Load Balancer. choose a name, a type of Load swing AZELB01 for External Load swing . In the selection of the Public IP address , choose the IP address that we previously created AZPIP01 .
As with the other components, add this component to your resource group AZRSG01 . I will return to the detailed configuration of the Load Balancer in step 2 of the article.
Step 2 – Creating our first VM and network
need us more that created our first Ubuntu virtual machine. For my part, I chose a LTS of Ubuntu 16.04 version but there still, adapt based on what you want.
Choose the name and the size of your virtual machine so that a login and a password. Note that I choose SSD but you can stay on the HDD (pour limiter les coûts dele de test) .
About the configuration, I opted for a DS1_v2 which is more than enough for our test.
We have now to choose your virtual machine configuration.
I chose the following:
- use Managed Disks : Yes (comme cela nous n’avons pas à gérer les storage accounts)
- Virtual Network:
- private Creation of a new network with the following configuration:
- Name: AZVNT01
- Address space: 10.0.0.0/24
- Subnet Name : AZSNT01
- Subnet address range: [associatedrequiringIPaddress10.0.0.0/24
- Pas (we’ll use one associated with our Load Balancer).]
- private Creation of a new network with the following configuration:
Also remember to configure an NSG (Network Security Group) is what will allow us to allow the flow to our virtual machines. And we can use the same NSG for our VM 2: AZNSG01 with like rules inbound TCP/80 and TCP/22 to allow the web and SSH.
And finally ends with the creation of a Availability Set AZAVS01 .
This last step may not be necessary but it’s to make things right in the case load distribution and high availability. That’s what makes Azure does not create our 2 virtual machines on the same physical server or in the same Bay etc. Indeed, in case of incident, you wouldn’t want your VM 2 are connected on the same socket and on the same physical server… we set therefore also our second virtual machine with this Availability Set .
And finally, you can leave past options disabled.
- Boot diagnostics: Disabled
- Guest OS diagnostics: Disabled .
OK 2 times in a row and finally make your first virtual machine will generate themselves.
Step 3 – Creating our second virtual machine
we now have to create a second virtual machine on the same basis.
I chosen so:
- Name: AZWEB02,
- same login, password,
- same size DS1_v2 ,
- I attached the VM on the same network ( AZVNT01 ), the same subnet ( AZSNT01 ), no public IP partner,
- I chose the same NSG ( AZNSG01 ) as well as the Availability Set that we created earlier ( AZAVS01 ).
Step 4 – Setting up our Load swing
If you have generally followed the article, you should have the internal IP 10.0.0.4 for your first virtual machine AZWEB01 and 10.0.0.5 for the second AZWEB02 – as well as all the components that are visible on the screenshot below.
We will go to our Load Balancer configuration. Note that for the moment, I have not installed Apache 2 on our 2 servers Ubuntu and I have not either create a web page by default. We are in the next step.
Once in your Load swing Azure, you have several options that we can review:
- Frontend IP pool : this is the public IP address that you associate with your load swing. In our case, so it’s the IP that users will use to access one of our 2 web servers. We have already made to the configuration, you should see that IP address AZPIP01 is already associated. Nothing more to do. Note in passing that since little, you can associate several public IP with a same Load Balancer (before you had to add other PowerShell) .
- Backend pools : this section corresponds to the different virtual machines to which our Load Balancer will return users. This part is not yet configured, let’s do Add. you will then have the choice to involve either virtual machines either more simply a Availability Set that you have already prepared (ce qui est notre cas) . I therefore chose our Availability Set AZAVS01 and we will choose in the menus our 2 virtual machines as well as their IP address.
- Health probes : this is the option that will allow us to tell the Load Balancer which port or what process it must monitor to determine whether or not one of our virtual machine is available (or is not). For the record, he is not required to specifically use the same protocol or port for which you will use the Load Balancer. A you to adjust settings according to the tolerance of failure as the Load Balancer must have towards your thing.
- Load balancing rules : we have then to define our rule of Load Balancing. In our case, we want to spread the load of 2 web servers Apache that displays a simple HTML page. We therefore define a rule that uses our Frontend IP port 80 (nous pourrions à ce moment également mettre en place dele de NATing) and we combine our 2 virtual machines (backend pool) as well as our control (probe health) indicator.
- Inbound NAT rules : Finally, there more to give us access to 2 virtual machines in order to connect us in SSH and create our Apache Server and our web page test. Note that we create 2 different rules for access to our 2 virtual machines. I chose so to access SSH to the VM AZWEB01 on port 2222 and AZWEB02 on the port 2223 (chaque port est redirigé sur le port 22 de la VM concernée) .
The Setup is complete. We just what to test. 🙂
step 5 – Test
so we check in on our Public IP object ( AZPIP01 ) which is the associated IP address then we try to connect in SSH to the first virtual machine ( AZWEB01 ) by specifying the port 222 .
This works perfectly! 🙂 – Same test well by changing the port 2223 to AZWEB02 . It is good also.
There more to install Apache on 2 VM with the following command:
sudo apt - get install apache2
and then modify the index.html to the root in the directory / var/www/html to see the change when the load will be distributed.
For AZWEB01 , I displays the message Welcome to AZWEB01 and for AZWEB02, I displays the message welcome to AZWEB02 . There are more to test with our favorite browser…
Access to the page… and to check load balancing, simply stop the apache service or to turn off a machine or even of you picking on the F5 key until you generate enough load to be directed on the 2nd Server… 😉
in short, as you can see it’s pretty simple to implement and it can really allow you to do a lot of thing whenever you need of high available, load balancing or another.
If you have any questions, do not hesitate 🙂!