- 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 -y
Open the terminal on both Raspberry Pis and update the package list:
sudo nala update && sudo nala upgrade -y
sudo nala install apache2 -y
sudo systemctl enable apache2
sudo systemctl start apache2
Open your web browser and visit http://. You should see the Apache2 default page.
Install keepalived
on both Raspberry Pis:
sudo nala install keepalived -y
Edit 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 keepalived
This 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! 🌟