Share via


Azure: Load Balancing on Linux Virtual Machine


In this article, we will go step by step to create two Ubuntu 14.04 LTS servers using same cloud service. After two virtual machines, create one Azure Load Balancer so it will distribute an 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.

Prerequisites

  • PuTTY – free SSH or telnet client. Click here for setup

 

You will learn

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

Create Ubuntu Virtual Machine

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

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

Click "Create" button

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

Step 4: Choose “Pricing Tier” from the list

Step 5: Optional Configuration - leave with default options.

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

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

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

After all settings are complete, click "Create" button

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

Download PuTTY Client from

http://www.putty.org/

Run PuTTY Client and enter DNS Name or Host Name or IP Address

Step 10: Enter Linux VM username and password

Linux Virtual Machine 1 is running: Ex. Linuxvmcs1

Step 11: Change the permission to root

sudo su

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

apt-get install tasksel tasksel

Step 13: Package Configuration window will run

Select “LAMP Server”.

press TAB and hit ENTER

Enter MySQL password during installation.

Step 14: Navigate to main directory or folder

cd{space}/

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

cd{space}var/www/html

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 type following command

nano default.php

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

"Ctrl + x" then "y" and press "Enter"

Now close or exit the connection of first Linux VM.

Step 17: Create another Linux VM

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

Step 18: Enter second VM Host Name, Username and Password or SSH 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

Step 20: After selecting same DNS name automatic all values will set such as “Resource Group”, “Subscription”, “Location”

In Settings blade select “Properties” -> SSH value

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

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

      2nd VM –linuxvmcs1.cloudapp.net:63784

Step 21: Again run the PuTTY SSH Client and  enter values according to second VM

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

Step 22: Change the permission to root

sudo su

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

apt-get install tasksel tasksel

Step 24: Package Configuration window will run

Select “LAMP Server”. Press TAB & hit ENTER

Enter MySQL password during installation.

Step 25: Navigate to main directory or folder

cd{space}/

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

cd{space}var/www/html

Note: Apache default page 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 type following command

nano default.php

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

"Ctrl + x" then "y" and press "Enter"

Close or Exit second VM connection

Configure Load Balancer sets

Step 28: Select “Load balanced sets” option of second VM

Step 29: Load balanced sets blade will open.

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

When all values set of load balancer

After few seconds load balancer will generate

Step 30: Now select first VM

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

Step 31: First select load balanced set option and then load balanced set blade will open.

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

Automatic all values are set

After load balanced set to second VM

Now open the browser and type DNS name

Congratulations you have successfully configured Load Balancing workloads between two Linux Virtual Machine!