Linux Manju

January 16, 2009

High Availibility of Web Server Using UCarp

Filed under: Linux, Uncategorized — Tags: , , , , — admin @ 6:41 pm

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

11 Comments »

  1. Hello, I can’t understand how to add your blog ( linuxmanju.com ) in my rss reader
    ————————
    sponsor: http://qugor.ru

    Comment by lassannawer — February 7, 2009 @ 3:08 pm

  2. linuxmanju.com - cool sitename man)))
    ————————
    ad: http://youraudiovox.com/music33/map.html

    Comment by imibiaHog — February 7, 2009 @ 5:53 pm

  3. Hi

    Please use http://linuxmanju.com/blog/?feed=rss2

    Regards,
    Manjunath

    Comment by linuxmanju — February 9, 2009 @ 1:59 pm

  4. You should also introduce “sleep 0.5″ in the beginning of vip-up.sh to avoid racing conditions.

    Comment by Adam Ryczkowski — February 19, 2009 @ 12:52 am

  5. A good point..

    Thanks Adam,

    Comment by linuxmanju — February 19, 2009 @ 1:58 pm

  6. Article very interesting, I will necessarily add it in the selected works and I will visit this site

    Comment by nintendost — November 17, 2009 @ 8:49 pm

  7. Article very interesting, I will necessarily add it in the selected works and I will visit this site

    Comment by gigantplsa — November 21, 2009 @ 7:16 am

  8. Hi. This is a super post!

    Comment by levitra_online_buy — November 23, 2009 @ 2:19 am

  9. Hi. This is a super post!

    Comment by cialis_online_buy — November 23, 2009 @ 11:27 am

  10. Как нельзя кстати….

    Floating IP:-  192.168.0…..

    Trackback by Kylie Batt — April 16, 2010 @ 4:05 pm

  11. По моему мнению Вы допускаете ошибку. Могу это доказать. Пишите мне в PM, поговорим….

    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…..

    Trackback by Kylie Batt — May 20, 2010 @ 9:04 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress