- Two Raspberry-Pi
- Raspbian OS (Only CLI will also work, i.e
Raspbian Lite) installed on both Pis - Basic knowledge of terminal commands
nala is just a cover-up for apt. We will be using nala instead of apt for better readability.
sudo apt install nala -yOpen the terminal on both Raspberry Pis and update the package list:
sudo nala update && sudo nala upgrade -ysudo nala install apache2 -ysudo systemctl enable apache2
sudo systemctl start apache2Open your web browser and visit http://. You should see the Apache2 default page.
Install keepalived on both Raspberry Pis:
sudo nala install keepalived -yEdit the keepalived configuration file on both Pi:
sudo nano /etc/keepalived/keepalived.conf- For the Main Server (any one of the two Pi)
vrrp_instance VI_1 {
state MASTER
interface wlan0 # Change to your network interface (e.g., eth0 or wlan0)
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass secret # Change this to a secure password
}
virtual_ipaddress {
192.168.43.100 # Replace with your desired virtual IP
}
}Note
If you are using mobile hotspot as your local network, make sure that your virtual_ipaddress is withing the hotspot's IP Address's range.
- For the Backup Server (the other Pi)
vrrp_instance VI_1 {
state BACKUP
interface wlan0 # Change to your network interface (e.g., eth0 or wlan0)
virtual_router_id 51
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass secret # Use the same password as the MASTER
}
virtual_ipaddress {
192.168.43.100 # Use the same virtual IP as the MASTER
}
}Enable and start the keepalived service on both Pi:
sudo systemctl enable keepalived
sudo systemctl start keepalivedThis will show if the service is activated or deactivated
sudo systemctl status keepalived- Access the Virtual IP: Open a browser and go to http://192.168.43.100 (according to this eg.).
- Stop keepalived on the Master:
sudo systemctl stop keepalived
- Check Failover: Refresh the browser; the backup server should take over.
You now have a main and backup server setup with two Raspberry Pis using Apache2 and keepalived! Enjoy your high availability web server! 🌟