Active Passive setup with heartbeat drbd and Apache

Heartbeat 2 + DRBD 8 + Apache

Step 1 : Configure DRBD -> Follow DRBD configuration steps

Step 2 : Give Virtual IP for HeartBeat
###At both machines
ifconfig eth0:1 192.168.91.95 netmask 255.255.255.0 (put at /etc/rc.d/rc.local)

Step 3 : Configure Apache
Edit /etc/httpd/conf/httpd.conf

Machine – 192.168.91.2
<VirtualHost 192.168.91.95>
DocumentRoot /web <-- DRBD
<Directory "/web">
allow from all
Options +Indexes
</Directory>
ServerName 192.168.91.2
</VirtualHost>

Machine – 192.168.91.3
<VirtualHost 192.168.91.95>
DocumentRoot /web <-- DRBD
<Directory "/web">
allow from all
Options +Indexes
</Directory>
ServerName 192.168.91.3
</VirtualHost>

Step 4: Installation and Configuration Heatbeat
###At Both machine
rpm -ivh lm_sensors-2.8.7-2.40.3.i386.rpm
rpm -ivh heartbeat-pils-2.0.8-2.el4.centos.i386.rpm
rpm -ivh heartbeat-stonith-2.0.8-2.el4.centos.i386.rpm
rpm -ivh heartbeat-2.0.8-2.el4.centos.i386.rpm

###Create 3 configuration files at /etc/ha.d/
All three files identical at both machines

File “authkeys”
auth 2
2 crc
Permission 600 for authkeys

File “haresources”
box1.lan drbddisk::r0 Filesystem::/dev/drbd0::/web::ext3 192.168.91.95 httpd

File “ha.cf”
bcast eth0
keepalive 2
warntime 10
deadtime 30
initdead 120
udpport 694
auto_failback off
ping 192.168.91.1
node box1.lan
node box2.lan
use_logd yes
logfile /var/log/hb.log
debugfile /var/log/heartbeat-debug.log

Start Heartbeat
Start Master first
# service heartbeat start

Start DRBD
At master
#modprobe drbd
#drbdadm adjust r0
#drbdsetup /dev/drbd0 primary --overwrite-data-of-peer r0
#mount -o rw /dev/drbd0 /web/

check
#cat /proc/drbd
It should see like



At Standby machine
# modprobe drbd
# drbdadm adjust r0

Check
#cat /proc/drbd
It should see like


Start Apache Server at Both Machines

# service httpd start
Try to simulate stop Master, Slave should take over the Apache.

###Troubleshooting
If “Split-Brain detected, dropping connection! ” error occur
Run drbdadm -- --discard-my-data connect whatever at Slave

You should see log like this.
Sep 17 16:48:01 box2 Filesystem[4768]: [4797]: INFO: Running start for /dev/drbd0 on /web
Sep 17 16:48:01 box2 kernel: kjournald starting. Commit interval 5 seconds
Sep 17 16:48:01 box2 kernel: EXT3 FS on drbd0, internal journal
Sep 17 16:48:01 box2 kernel: EXT3-fs: recovery complete.
Sep 17 16:48:01 box2 kernel: EXT3-fs: mounted filesystem with ordered data mode.
Sep 17 16:48:02 box2 Filesystem[4757]: [4813]: INFO: Success
Sep 17 16:48:03 box2 IPaddr[4826]: [4857]: INFO: Running OK
Sep 17 16:48:04 box2 mach_down[4620]: [4869]: info: /usr/share/heartbeat/mach_down: nice_failback: foreign resources acquired
Sep 17 16:48:04 box2 mach_down[4620]: [4873]: info: mach_down takeover complete for node box1.lan.
Sep 17 16:48:04 box2 heartbeat: [4165]: info: mach_down takeover complete.

###Make sure auto startup
chkconfig drbd on
chkconfig heartbeat on
chkconfig httpd off

Comments