Friday, January 22, 2010

Heartbeat - DRBD - MYSQL - APACHE - TYPO3

SkyHi @ Friday, January 22, 2010
With two ubuntu (8.04) machine: ubuntu-five and ubuntu-six.
On both boxes exists two pure partitions: /dev/sdb and /dev/sdc
Install these packages on both:

apt-get install heartbeat-2 drbd8-utils stonith mysql-server apache2
apt-get install typo3-base typo3-env
apt-get install php5 php5-cgi php5-mysql typo3-site-installer

Here is my /etc/drbd.conf:

resource testing { # name of resources for mysql database
protocol C;

on ubuntu-five { # first server hostname
device /dev/drbd0; # Name of DRBD device
disk /dev/sdb1; # Partition to use, which was created using fdisk
address 10.66.66.22:7788; # IP addres and port number used by drbd
meta-disk internal; # where to store metadata meta-data
}

on ubuntu-six { # second server hostname
device /dev/drbd0;
disk /dev/sdb1;
address 10.66.66.26: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; # 2 minutos.
}
}

resource typo3 { # name of resources apache2 and typo3

protocol C;

on ubuntu-five { # first server hostname
device /dev/drbd1; # Name of DRBD device
disk /dev/sdc1; # Partition to use, which was created using fdisk
address 10.66.66.22:7789; # IP addres and port number used by drbd
meta-disk internal; # where to store metadata meta-data
}

on ubuntu-six { # second server hostname
device /dev/drbd1;
disk /dev/sdc1;
address 10.66.66.26:7789;
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; # 2 minutos.
}
}

Here is my /etc/ha.d/ha.cf:

logfile /var/log/ha-log
keepalive 2
deadtime 30
udpport 695
bcast eth0
auto_failback off
stonith_host ubuntu-five meatware ubuntu-six
stonith_host ubuntu-six meatware ubuntu-five
node ubuntu-six ubuntu-five

and the /etc/ha.d/haresources:

ubuntu-five IPaddr::10.66.66.74/24/eth0\
drbddisk::testing Filesystem::/dev/drbd0::/var/lib/mysql::ext3\
drbddisk::typo3 Filesystem::/dev/drbd1::/data::ext3 mysql apache2


First make new Partitions on sdb and sdc on both boxes:
fdsik /dev/sdb
> n
> p
> 1
> enter
> enter
> w

fdsik /dev/sdc
> n
> p
> 1
> enter
> enter
> w

make drbd with these commands on both boxes:

drbdadm create-md testing
#mkfs.ext3 /dev/drbd0

drbdadm create-md typo3
(#mkfs.ext3 /dev/drbd1)

On ubuntu-five run:
drbdadm -- --overwrite-data-of-peer primary all
drbdadm connect all


On ubuntu-six run:
drbdadm -- --overwrite-data-of-peer secondary all
drbdadm connect all


Wait until new DRBD drive to syncing.
Move the mysql data files and test mounting on ubuntu-five:
/etc/init.d/mysql stop
mv /var/lib/mysql /var/lib/mysql.org
mkdir /var/lib/mysql
mount /dev/drbd0 /var/lib/mysql
mv /var/lib/mysql.org/* /var/lib/mysql/
chown -R mysql:mysql /var/lib/mysql

/etc/init.d/mysql start

On ubuntu-six do:
/etc/init.d/mysql stop
mv /var/lib/mysql /var/lib/mysql.org
Shutdown ubuntu-six and restart ubuntu-five.
Now start ubutnu-six after the ubuntu-five completely came up.
Reference: http://mtehrani30.blogspot.com/2008/08/heartbeat-drbd-mysql-apache-typo3.html