Load Balancing On Linux Virtual Machine

In this article, we will go, step by step, and create two Ubuntu Servers 14.04 LTS using the same cloud service. After two virtual machines, we will create one Azure Load Balancer. So, it will distribute incoming traffic on two or more virtual machines. With the help of Load Balancer, you can distribute the load or traffic across multiple servers. Azure can also load balance within a cloud service or virtual network. This is known as internal load balancing. In this example, deployment model is Classic. So, it will create Cloud Service.

service

Prerequisites

You will learn

  • How to Create Ubuntu Server
  • Deployment Models: Classic
  • How to establish connection with Ubuntu Server
  • How to Configure Azure Load Balancer on Ubuntu Virtual Machine
Create Ubuntu Virtual Machine

Step 1: Navigate to Azure Portal (http://portal.azure.com/) & sign in with Azure credentials

Step 2:
Click on New -> Virtual Machine-> Ubuntu Server 14.04 LTS -> Classic (deployment model)

Click on "Create" button.

Create

Step 3:
Enter Host Name, Username & Password or SSH public key.

public key

Step 4:
Choose “Pricing Tier” from the list.

Tier

Step 5:
Optional Configuration - leave with default options.

Configuration

Step 6:
Resource Group – Create New Resource or use existing group.

Group

Step 7:
Subscription – Select subscription if multiple subscription is available.

Step 8: Location – different locations are available. Select a location from the list.

location

After all these settings, click on "Create" button.

Create

Step 9:
Now, Linux VM is ready but we need to configure LAMP stack inside Linux VM.

Download PuTTY Client.

Run PuTTY Client & enter DNS Name or Host Name or IP Address.

IP Address

Step 10:
Enter Linux VM username & password.

Linux Virtual Machine 1 is running: Ex. Linuxvmcs1 

Linux

Step 11:
Change the permission to root.

sudo su

Linux

Step 12: To install LAMP stack inside VM, run the following commands:

apt-get install tasksel

tasksel

commands

commands

Step 13:
Package Configuration window will appear.

Select “LAMP Server”.

Press TAB & hit ENTER,

windows

Enter the MySQL password during installation.

windows

Step 14:
Navigate to main directory or folder.

cd{space}/

commands

Step 15: Again, navigate to LAMP stack installation directory by running the following commands:

cd{space}var/www/html

commands

Note:
 Apache default page is available inside html folder but if VM is Ubuntu 12.04 html directory is not available.

Linux 12.04 LTS - cd var/www

Linux 14.04 LTS - cd var/www/html

Step 16: Start the nano editor and type the following command:

nano default.php

commands

commands

<?php echo "<h1>Linux VM 1</h1>" ?>

Hit "Ctrl + x"; then, "y" and press "Enter".

Now, close or exit the connection of first Linux VM.

Step 17: Now, create the other Linux VM.

New -> Virtual Machine -> Ubuntu Server 14.04 LTS -> Classic (deployment model).



Step 18:
Enter second VM Host Name, Username & Password or SSH public key.

public key

Step 19:
Select “Optional Configuration” -> “Network” -> “Domain Name” -> Choose an existing domain name option with existing cloud domain name.

Choose first VM domain name ex. linuxvmcs1.cloudapp.net

domain

Step 20:
After selecting the same dns name,  all values, such as “Resource Group”, “Subscription”, “Location” will set, automatically.

values

Settings

In Settings blade, select “Properties” -> SSH value.

For second VM, DNS Name will be the same but port number is different.

Ex. 1st VM – linuxvmcs1.cloudapp.net:22

2nd VM –linuxvmcs1.cloudapp.net:63784

port number

Step 21:
Again, run the PuTTY SSH Client & Enter values according to second VM.

values

values

DNS name is the same but virtual machine is different ex. linuxvmcs2.

Step 22: Change the permission to root.

sudo su

commands

Step 23:
To install LAMP stack inside VM, run the following commands:

apt-get install tasksel

tasksel

commands

commands

Step 24:
Package Configuration window will appear.

Select “LAMP Server”. Press TAB & hit ENTER.

windows

Enter the MySQL password during installation.

windows

Step 25:
Navigate to main directory or folder.

cd{space}/

commands

Step 26: Again, navigate to LAMP stack installation directory by running the following commands:

cd{space}var/www/html

commands

Note: apache default page is available inside html folder but if VM is Ubuntu 12.04 html directory is not available.

Linux 12.04 LTS - cd var/www

Linux 14.04 LTS - cd var/www/html

Step 27: Start the nano editor and type the following command:

nano default.php

commands

commands

<?php echo "<h1>Linux VM 2</h1>" ?>

Press "Ctrl + x" and then, "y". Press "Enter".

Close or Exit second VM connection.

Configure Load Balancer sets

Step 28: Select “Load balanced sets” option on 2nd VM.

commands

Step 29: Load balanced sets blade will open.

Click on “Join” option -> Load balanced set -> Create a load balanced set -> enter name, port, etc.

Configure

All the values are set for the load balancer.

value

After a few seconds, load balancer will be generated.

value

Step 30: Now, select 1st VM.

Settings blade -> “Load balanced sets” -> “Join” option

Join

Step 31: First, select Load balanced set option. The load balanced set blade will open.

Select “Use existing load balanced set” option, ex. linuxvmlb

existing

Automatically, all the values will set.

values

After that, set the load balance for 2nd VM.

load

load

Now, open the browser & type dns name.

browser


Congratulations! You have successfully configured Load Balancing workloads between two Linux Virtual Machines.

Up Next
    Ebook Download
    View all
    Learn
    View all