Practice 3 - Load balancing
In this lab we will take a look at load balancing web applications running ontop of IaaS cloud instances. You will set up two instances. One with a simple PHP application and second one with a load balancer. You will define a load balancing group which will contain your own application server, together with other student servers.
We will use Apache web server with PHP for the application and nginx for the load balancer.
Exercise 3.1. Setting up an Application Server instance
- Start an instance either from your previous snapshot or create a new clean instance from
Ubuntu 16.04
image.- This time you will run multiple machines at the same time so for flavour please use
m1.xsmall
- For network you can use
provider_64_net
- Make sure you use a
security group
that hasport 80 open
, like the security group you made last practice session!!
- This time you will run multiple machines at the same time so for flavour please use
- Install the required software packages:
- Refresh the list of software packages:
sudo apt update
- Install the following ubuntu packages: apache2, php, libapache2-mod-php
- You might encounter an error stating that something is locked that is Ubuntu running some updates in background so please give it few minutes to complete and try again later, if still no luck ask help from lab instructor. (Use with caution! https://www.tecmint.com/fix-unable-to-lock-the-administration-directory-var-lib-dpkg-lock/)
- Refresh the list of software packages:
- Restart the apache web server:
sudo service apache2 restart
- Delete the default Apache HTTP web page file located at:
/var/www/html/index.html
- Download index.zip
- Unpack it and upload the containing
index.php
file to the instance usingscp
(or just copy its content) - Alternatively you can use
wget
to download the zip directly to the instance andunzip
to unpack it.
- Unpack it and upload the containing
- Copy the
index.php
file into the Apache HTTP application folder/var/www/html/index.php
(You will have to use sudo as your user does have required permissions in that folder) - Create an empty data file:
/var/www/html/data.txt
- This file is used to store the list and count of incoming user requests.
- Change the owner of the created file to 'www-data':
sudo chown www-data /var/www/html/data.txt
(Apache web server is running under this user)
- Access your instance through a web browser using its Public IP to check that the website is working as required
- Modify
/var/www/html/index.php
to make the web page more personal to you, so that others would recognize that this application server was set up by you when they visit the page.- How you decide to modify it up to you, but there should at least be your Full Name present.
- You may want to make it visually very recognizable to differentiate between your server and other students servers more easily.
- Take a screenshot of your application server web page
Exercise 3.2. Setting up load balancer instance and balancing multiple application servers
Load balancer distributed all user requests of the web page across multiple application servers. Load balancers are used to increase capacity (concurrent users) and reliability of applications.
(image taken from http://www.netdigix.com/linux-loadbalancing.php)
- We are using Nginx (http://nginx.org/en/) as a load balancer.
- Create a second instance (also Ubuntu 16.04) for the load balancer
- Install Nginx on the instance
- Refresh the list of software packages:
sudo apt update
- Install the following ubuntu package:
nginx-full
- Refresh the list of software packages:
- Modify Nginx configuration to add your application server IP into the list of managed services
- Download the example nginx configuration:
wget http://kodu.ut.ee/~jakovits/nginx.conf
- Modify the downloaded
nginx.conf
configuration file- Find the upstream lab_load_balancer block
- Modify the
server 172.17.64.200;
line in the configuration file and replace the existing IP (172.17.64.200) with the actual IP of your application server.
- Download the example nginx configuration:
- Overwrite the default nginx configuration on the instance with the modified configuration
sudo cp nginx.conf /etc/nginx/nginx.conf
- Reload Nginx service
sudo service nginx reload
- Visit the IP address of the load balancer using a web browser and verify that it displays your application server
- Now also add other student application servers under your load balancer to distribute user requests between multiple servers.
- Create a new
server IP_ADDRESS;
line inside the upstream lab_load_balancer block for each additional server
- Create a new
- Take a screenshot of visiting your application server web page through the load balancer (Browser is accessing load balancer IP address, but your application server content is shown)
Exercise 3.3. Monitoring user traffic
- Visit the load balancer multiple times. Do you recognize your own application sever?
- Ask other students to visit your load balancer or to add your application server into their load balancer
- Wait until you start seeing requests on your application server tracker from a number of other locations.
- You can check current incoming HTTP connections using the following command:
netstat | grep http
- Take a screenshot of the output of netstat command. Try to have it display more than 4 connections when other student`s requests are being redirected to your server.
Exercise 3.4. Generating additional user traffic for benchmarking
- Your task is to generate a large number of user requests to the load balancer and verify how many of those requests are sent to your application server by the load balancer.
- To generate a large number of user request, you can either use existing load generation tools, web applets or write a simple script to visit the load balancer page multiple times in a sequence.
- Note down how many of those requests end up on your application server. How large percent of your generated user requests ended up visiting your server?
- Take a screenshot of the tool or a script that you used for load generation.
Deliverables
- This time leave your instance running unless otherwise instructed so by the lab assistant
- Screenshot of your application server web page directly without load balancer
- Screenshot of visiting your application server web page through the load balancer (Browser is directed at the load balancer IP address)
- Screenshot taken of the netstat command in exercise 3.3
- Screenshot taken in exercise 3.4 of the load generation tool.
Solutions for this task can no longer be submitted.