Operating System : Slackware 13.0
Kernel : 2.6.29.6-smp
mysql : Ver 14.12 Distrib 5.0.84
Apache : Apache/2.2.13 (Unix)
PHP : PHP 5.2.10

Server 01 : slack-ha01.example.org
IP eth0 : 192.168.2.201
IP eth1 (heartbeat) : 192.168.10.1

Server 02 : slack-ha02.example.org
IP eth0 : 192.168.2.202
IP eth1 (heartbeat) : 192.168.10.2

IP Virtual : 192.168.2.250

Setiap server dikonfigurasi mempunyai 4 partisi :

/dev/sda1 : swap
/dev/sda2 : /
/dev/sda4 : partisi yang akan kita gunakan untuk menempatkan data MySQL maupun data Apache.
/dev/sda3 : digunakan untuk menempatkan metadata disk DRBD (150MB)

Untuk konfigurasi Apache, PHP dan MySQL nya silahkan merujuk ke link tutorial berikut.
http://invaleed.wordpress.com/2009/11/22/membangun-webserver-menggunakan-slackware-13-0/

Langkah awal adalah stop service Apache & MySQL dikedua server (slack-ha01 & slack-ha02

# /etc/rc.d/rc.httpd stop
# /etc/rc.d/rc.mysqld stop

********** INSTALL HEARTBEAT **********
(dilakukan di slack-ha01 & slack-ha02)
***************************************

# wget http://hg.linux-ha.org/heartbeat-STABLE_3_0/archive/STABLE-3.0.3.tar.bz2
# tar -vxjf STABLE-3.0.3.tar.bz2
# cd STABLE-3.0.3
# ./configure
# make
# make install

# vi /etc.ha.d/ha.cf

keepalive 1 # Send one heartbeat each second
deadtime 10 # Declare nodes dead after 10 seconds
bcast eth1 # Broadcast heartbeats on eth1 interface
node slack-ha01 # List nodes
node slack-ha02 # List nodes
logfile /var/log/heartbeat.log # Log location for heartbeat log
auto_failback off # Don’t fail back to haserver1 automatically
logfacility local0 # Default log facility

#( echo -ne “auth 1\n1 sha1 “; \
dd if=/dev/urandom bs=512 count=1 | openssl md5 ) \
> /etc/ha.d/authkeys

# chmod 0600 /etc/ha.d/authkeys
# /etc/rc.d/rc.heartbeat start

************ INSTALL DRBD *************
(dilakukan di slack-ha01 & slack-ha02)
***************************************

# wget http://oss.linbit.com/drbd/8.3/drbd-8.3.6.tar.gz
# tar -xzvf drbd-8.3.6.tar.gz
# cd drbd-8.3.6
# ./configure –with-km
# make KDIR=/usr/src/linux/
# make install
# depmod -a
# modprobe drbd
# lsmod

# wget http://blog.tpa.me.uk/wp-content/uploads/2009/11/drbd.tar.gz
# tar -xzvf drbd.tar.gz
# cd drbd
# wget http://oss.linbit.com/drbd/8.3/drbd-8.3.6.tar.gz
# ./drbd.SlackBuild
# installpkg /tmp/drbd-8.3.6-x86_64-1_SBo.tgz

# vi /etc/drbd.conf

resource r0 {

protocol C;

on slack-ha01 {
device /dev/drbd0;
disk /dev/sda4;
address 192.168.2.201:7788;
meta-disk internal;
}

on slack-ha02 {
device /dev/drbd0;
disk /dev/sda4;
address 192.168.2.202:7788;
meta-disk internal;
}

disk {
on-io-error detach;
}

net {
max-buffers 2048;
ko-count 4;
}

syncer {
rate 10M;
al-extents 257;
}

startup {
wfc-timeout 0;
degr-wfc-timeout 120;
}
}

# drbdadm create-md r0
# drbdadm up all

Di slack-ha01
————-

# drbdsetup /dev/drbd0 primary -o
# cat /proc/drbd
# drbdadm primary all
# mkfs.ext3 /dev/drbd0
# mkdir -p /dbvol; mount /dev/drbd0 /dbvol

************** Konfigurasi ************
MySQL & Apache
***************************************

Di slack-ha01
————-

# mv /var/lib/mysql /dbvol
# ln -s /dbvol/mysql /var/lib/mysql
# mv /var/www /dbvol
# ln -s /dbvol/www /var/www

Di slack-ha02
————-

# mv /var/lib/mysql /home
# ln -s /dbvol/mysql /var/lib/mysql
# mv /var/www/ /home
# ln -s /dbvol/www /var/www

******** Konfigurasi Heartbeat ********
Apache + DRBD + Mysql
(slack-ha01 dan slack-ha02)
***************************************

# cd /usr/local/etc/ha.d/resource.d/
# cp -a drbddisk /etc/ha.d/resource.d/
# cd /etc/ha.d/resource.d/
# vi drbddisk

DEFAULTFILE=”/etc/drbd.conf”

# vi drbdupper

DEFAULTFILE=”/etc/drbd.conf”

# cd /usr/lib/ocf/resource.d/heartbeat/
# cp -a mysql /etc/ha.d/resource.d/

# cd /etc/ha.d/resource.d/
# echo “” > mysql
# vi mysql

#!/bin/bash
#
# This script is inteded to be used as resource script by heartbeat
#
# Mar 2006 by Monty Taylor
#
###

. /etc/ha.d/shellfuncs

case “$1” in
start)
res=`/etc/rc.d/rc.mysqld start`
ret=$?
ha_log $res
exit $ret
;;
stop)
res=`/etc/rc.d/rc.mysqld stop`
ret=$?
ha_log $res
exit $ret
;;
status)
if [[ `ps -ef | grep ‘[m]ysqld’` > 1 ]] ; then
echo “running”
else
echo “stopped”
fi
;;
*)
echo “Usage: mysql {start|stop|status}”
exit 1
;;
esac

exit 0

# vi/etc/ha.d/haresources (slack-ha01 & slack-ha02)

slack-ha01 192.168.2.250 \
drbddisk::r0 Filesystem::/dev/drbd0::/dbvol::ext3 \
apache::/etc/httpd/httpd.conf \
mysql

Note : jangan lupa edit /etc/httpd/httpd.conf agar Apache listen di IP 192.168.2.250

Konfigurasi agar service heartbeat & drbd dijalankan otomatis ketika server restart.

# vi /etc/rc.d/rc.local (slack-ha01 & slack-ha02)

/etc/rc.d/rc.heartbeat start
/sbin/modprobe drbd
/etc/rc.d/rc.drbd start

Note :

1. Log akan sangat membantu dalam proses troubleshooting:
– /var/log/heartbeat.log
– /var/log/messages
– /var/log/httpd/error_log

Iklan