Hosts file active/passive load balancing test
- Sankalpa H.T.S
- Oct 15, 2023
- 2 min read

Here, the test setup will be as follows.
Provision 3 VMs.
Configure a simple web server on 2 of them. Let's name the domain as "abc.com".
Edit the client machine's (remaining server) host entry as below <IP of server web server 1> abc.com <IP of server web server 2> abc.com
Test 1
Run the web server on both of the web servers.
Try to retrieve the web page from client machine for below test scenarios.
When both web service 1 & 2 are up and running
When web service 1 down and web service 2 running
Bring up the web service 1 and down web service 2
Observe the outcome.
Test 2
Bring up the each webserver to serve in two different ports.
Stop the service only on one port on primary server.
Bring back the service on the port which was down on primary server.
Observe the outcome.
Results
VM1:
Hostname - san1.test.com
IP - 10.0.2.10
VM2:
Hostname - san2.test.com
IP - 10.0.2.20
VM3:
Hostname - san3.test.com
IP - 10.0.2.30
Python simple http server will be used to configure a simple webserver.
Let's name the domain as "abc.com".
Edit the client machine's (10.0.2.10) /etc/hosts entry as below 10.0.2.20 abc.com 10.0.2.30 abc.com
Test 1
When both web service 1 & 2 are up and running

We are able to retrieve the abc.com webpage from webserver 1 as below.

When web service 1 down and web service 2 running

We are able to retrieve the abc.com webpage from webserver 2 as below.

Bring up the web service 1 and down web service 2

We are able to retrieve the abc.com webpage back again from webserver 1 as below.

Apart from trying to retrieve the webpage from a search engine GUI (Eg, Firefox) we can get the expected results by executing a terminal command.
I have executed a while loop to execute every 2 seconds from the very beginning of the test.
Terminal output while executing above test sequence for your reference.

Test 2
Bring up the each webserver to serve in two different ports.
Here, each web server works on both 8000 and 9000 ports.

Webserver1 serves as primary active server for both services on port 8000 & 9000.

Stop the service only on one port on primary server.
Here, stopped the service on port 8000 in primary server.

Webserver 1 serves as primary active server only for service runs on port 9000 while secondary passive Webserver 2 now serves as primary active server for the service runs on port 8000.

Bring back the service on the port which was down on primary server.
Here, Brought back the service on port 8000 in primary server.

Webserver 1 serves as primary active server for services run on both port 8000 & 9000 while Webserver 2 being the secondary backup server again.

Conclusion:
Load will be automatically redirected to the secondary passive (web server 2) web service when primary active (web server 1) web service is not accessible.
Comments