High Availibility of Web Server Using UCarp
Easy way to to achieve 99.99999 with uCarp.
Example Setup:-
1) Server1 — IP Address 192.168.0.10
2) Server2 — IP Address 192.168.0.100
Floating IP:- 192.168.0.200 ( This is the Virtual IP Which will be owned by the master server )
Service provided:- Webserver ( My production env has three instances of Bugzilla and Wiki Pages. All bugzilla and Wiki’s are configured to use a Centralized Mysql Database host with different DBs ).
Step By Step:-
1) Login to Server1 and copy all /var/www to server2 /var/www
scp -rp /var/www root@server2-IP:/var/www
2) Make sure that the pages ( Web pages are accessible from server 1 and server 2’s ip http://server1 http://server2
3) Download ucarp from http://download.pureftpd.org/pub/ucarp/ ( Go with the latest version ) on both the servers
Both Servers:-
wget http://download.pureftpd.org/pub/ucarp/ucarp-1.5.tar.gz
tar zxvf ucarp-1.5.tar.gz
cd ucarp-1.5.
./configure && make && make install-strip
4) Once installed on both the servers ucarp should be available in /usr/local/sbin/ucarp
On Server 1 and Server2 Create two files Called vp-up.sh and vp-down.sh with the following contents
vi /etc/vp-up.sh
#!/bin/bash
### Add Floating IP
/sbin/ip addr add 192.168.0.200/24 dev eth0
#### My Switch / gateway is not smart does not flush the arp cache. So send a broadcast
/sbin/arping -c 5 -i eth2 -S 192.168.0.200 192.168.0.1
/sbin/arping -c 5 -i eth2 -S 192.168.0.200 192.168.0.14
echo “WebServer not reachable” | /usr/bin/mail -s “Master webserver down” server-admin@xxx.com
vi /etc/vip-down.sh
#!/bin/bash
/sbin/ip addr del 192.168.0.200/24 dev eth0
echo “Changing Roles of the Web server” | /usr/bin/mail -s “Changing role Reverting to Backup State..” server-admin@xxx.com
Put both Files in /etc/vip-up.sh and /etc/vip-down.sh in both the servers ( Feel free to modify the script according to your requirement.
chmod +x /etc/vip-*.sh
Ucarp Magic:-
In the master server:-
Run:-
/usr/local/sbin/ucarp -v 42 -P -p somepasswd -a 192.168.0.200 -s 192.168.0.10 –upscript=/etc/vip-up.sh –downscript=/etc/vip-down.sh &
In the Secondary Server:-
/usr/local/sbin/ucarp -v 42 -b 2 -k 1 -p somepwasswd -a 192.168.0.200 -s 192.168.0.100 –upscript=/etc/vip-up.sh –downscript=/etc/vip-down.sh &
( The difference between both is the -s < IP ADDR > and in the second server -b2 -k1 and no -P Which means advertisement frequency is 2 seconds and Skew is 1 Second Which is higher than the master’s default 1Sec. This will force Master to own the virtual IP whenever its online ).
Test:-
Open UP http://192.168.0.200 ( Or do a continuous ping )
Bring the master down. The Slave will automatically server the request. Bring back the master up. It will take over again. The HA is ready..
Note:- If your web server has alot of dynamic data.. please make sure to sync the server1:/var/www and server2:/var/www periodically
In case of a problem Please mail me to manjunath<at> linuxmanju.com
