[Day 5] 7. Squid as a Load Balancer
Setup Overview
We are configuring SQUID to act as a load balancer for two Apache Servers on separate machines.
Network Configuration:
- 192.168.80.128: SQUID server (load balancer).
- 192.168.80.129: Apache Server 1.
- 192.168.80.130: Apache Server 2.
Objective:
Distribute traffic between the two Apache servers using SQUID in a round-robin manner.
Steps to Set Up SQUID as a Load Balancer
1. Install and Configure SQUID on Machine 192.168.80.128
-
Make sure you have already configured squid before, if not then visit Day 4 and configure it accordingly. After configuring Squid, follow the steps written below:
-
Change the Default Port to 80:
-
Open the squid.conf file:
bashsudo nano /etc/squid/squid.conf -
Search for
and replace it with3128:80plaintexthttp_port 80 vhost
-
-
Configure Load Balancing:
-
Add the following lines to the
file:squid.confplaintextcache_peer 192.168.80.129 parent 80 0 no-query originserver round-robin weight=1 name=one cache_peer 192.168.80.130 parent 80 0 no-query originserver round-robin weight=1 name=two -
Explanation:
- cache_peer: Defines backend servers.
- parent: Indicates that these servers will handle HTTP traffic.
- round-robin: Distributes traffic equally.
- weight=1: Ensures equal load distribution.
-
-
Restart SQUID:
-
Restart the service to apply changes:
bashsudo systemctl restart squid sudo systemctl status squid
-
2. Configure Apache Servers
-
Setup Apache Server 1 on 192.168.80.129:
-
Install Apache (if not already installed):
bashsudo apt-get install apache2 -
Create a unique webpage:
bashecho "Welcome to Apache Server 1" | sudo tee /var/www/html/index.html -
Restart Apache:
bashsudo systemctl restart apache2
-
-
Setup Apache Server 2 on 192.168.80.130:
-
Install Apache:
bashsudo apt-get install apache2 -
Create a different webpage:
bashecho "Welcome to Apache Server 2" | sudo tee /var/www/html/index.html -
Restart Apache:
bashsudo systemctl restart apache2
-
3. Test Load Balancing
-
Open a browser and enter the IP address of the SQUID server:
plaintexthttp://192.168.80.128 -
Verify Round-Robin Behavior:
- Refresh the browser multiple times.
- You should see outputs alternating between:
- "Welcome to Apache Server 1"
- "Welcome to Apache Server 2"
Notes
-
The vhost option in
enables virtual hosting, allowing SQUID to handle traffic destined for multiple backends.http_port 80 vhost -
Ensure the Apache servers are accessible on port 80.
-
If SQUID doesn’t load balance properly, check the logs for debugging:
bashsudo tail -f /var/log/squid/access.log
Read Next
[Day 5] 8. Monitoring a Remote Linux Machine using Nagios
### **Overview** **Goal:** Set up Nagios to monitor a remote Linux machine using **NCPA** (Nagios Cross-Platform Agent). **Setup:** 1. **N...
[Day 5] 9. Extra
#### **1. What is an Application Proxy?** An **Application Proxy** acts as an intermediary between the client and the server, facilitating secure c...