Two web servers will be load-balanced using HAProxy.
Prerequisites
- Two web servers with static IPs.
- HAProxy installed on a load balancer server.
Step-by-Step Guide
Step 1: Install Apache or Nginx on Web Servers
1. Install Apache or Nginx:
sudo apt install apache2 -yStep 2: Install and Configure HAProxy on the Load Balancer
1. Install HAProxy:
sudo apt install haproxy -y2. Configure HAProxy:
sudo nano /etc/haproxy/haproxy.cfgHAProxy Configuration:
frontend http_front
bind *:80
default_backend web_servers
backend web_servers
balance roundrobin
server web1 :80 check
server web2 :80 check backup3. Restart HAProxy:
sudo systemctl restart haproxyStep 3: Verify HAProxy Load Balancing and Failover
1. Shut down one of the web servers to confirm that traffic fails over to the other.
