If you feel this tip has saved you time or effort, please consider buying us a cuppa coffee to keep things going!
Install 2 Fedora 13 systems as normal
update and upgrade both systems
Configure networking on both nodes
System -> Preferences -> Network Connections
webnode1 10.71.128.71
webnode2 10.71.128.72
Edit /etc/hosts
127.0.0.1 localhost
10.71.128.71 webhost1 webhost1.mps.sch
10.71.128.72 webhost2 webhost2.mps.sch
Update both nodes
System -> Administration -> Update Manager
Remove SELinux
Install NTP
install with synaptic
edit /etc/ntp.conf
change server to your ntp server
Install Distributed Block Device drbd and Heartbeat
drbd8-utils and heartbeat with synaptic
Set permissions on drbd files
chgrp haclient /sbin/drbdsetup
chmod o-x /sbin/drbdsetup
chmod u+s /sbin/drbdsetup
chgrp haclient /sbin/drbdmeta
chmod o-x /sbin/drbdmeta
chmod u+s /sbin/drbdmeta
fdisk -l to see name of second disk, in my case:
root@webnode2:~# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0002c932
Device Boot Start End Blocks Id System
/dev/sda1 * 1 2497 20051968 83 Linux
/dev/sda2 2497 2611 916481 5 Extended
/dev/sda5 2497 2611 916480 82 Linux swap / Solaris
Disk /dev/sdb: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/sdb doesn't contain a valid partition table
resource lamp {
protocol C;
handlers {
pri-on-incon-degr "echo o > /proc/sysrq-trigger ; halt -f";
pri-lost-after-sb "echo o > /proc/sysrq-trigger ; halt -f";
local-io-error "echo o > /proc/sysrq-trigger ; halt -f";
outdate-peer "/usr/lib/heartbeat/drbd-peer-outdater -t 5";
}
startup {
degr-wfc-timeout 120;
}
disk {
on-io-error detach;
}
net {
cram-hmac-alg sha1;
shared-secret "password";
after-sb-0pri disconnect;
after-sb-1pri disconnect;
after-sb-2pri disconnect;
rr-conflict disconnect;
}
syncer {
rate 100M;
verify-alg sha1;
al-extents 257;
}
on webnode1 {
device /dev/drbd0;
disk /dev/sdb;
address 10.71.128.71:7788;
meta-disk internal;
}
on webnode2 {
device /dev/drbd0;
disk /dev/sdb;
address 10.71.128.72:7788;
meta-disk internal;
}
}
Initialse meta data on disks
[node1]drbdadm create-md lamp
[node2]drbdadm create-md lamp
Start drbd on both servers
service drbd start
setup webnode1 as the primary and start the sync
[node1]drbdadm -- --overwrite-data-of-peer primary lamp
you can watch the sync progress with the cat command:
watch cat /proc/drbd
Format and Mount new disk
[node1] mkfs.ext4 /dev/drbd0
[node1] mkdir -p /srv/data
[node1] mount /dev/drbd0 /srv/data
Insatall lamp files on both servers
I used synaptic selecting apache2, mysql-server php5 and php5-mysql
Remove Apache2 startup scripts
[node1]update-rc.d -f apache2 remove
[node2]update-rc.d -f apache2 remove
Remove DRBD starup scripts
update-rc.d -f drbd remove on both nodes
Edit startup script to prevent mysql from running at boot
Open /etc/init/mysql.conf
change the start on section so that it reads: start on runlevel [!0123456]
This will prevent mysql from running at boot, but allow the service mysql start command to still work properly.
Reboot each server
Run mysql manually to create data
/etc/ini.d/mysql start
On node 1 set drbd as primary
drbdadm primary lamp
and mount on /srv/data
mount /dev/drbd0 /srv/data
# Create location to store files
[node1]mkdir -p /srv/data/etc
[node1]mkdir -p /srv/data/var/lib
[node1]mkdir -p /srv/data/var/log
Move Apache2 and php5 files
# Move files to new location
[node1]mv /etc/apache2 /srv/data/etc
[node1]mv /etc/php5 /srv/data/etc
[node1]mv /var/lib/php5 /srv/data/var/lib
[node1]mv /var/www /srv/data/var
[node1]mv /var/log/apache2 /srv/data/var/log
# Link to new location
[node1]ln -s /srv/data/etc/apache2 /etc/apache2
[node1]ln -s /srv/data/etc/php5 /etc/php5
[node1]ln -s /srv/data/var/lib/php5 /var/lib/php5
[node1]ln -s /srv/data/var/www /var/www
[node1]ln -s /srv/data/var/log/apache2 /var/log/apache2
At this point you could reboot the server, make node1 primary, mount /dev/drdb0 and start apache2
etc/ha.d/ha.cf
logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 45
bcast eth0
node webnode1
node webnode2
auto_failback on
respawn hacluster /usr/lib/heartbeat/ipfail
logfile /var/log/heartbeat.log
export EDITOR=/bin/nano
I highly suggest you add this line to your /etc/my.cnf config file. It will automatically fix MyISAM tables as soon as they become corrupt:
[mysqld]
myisam-recover=backup,force
References:
http://www.drbd.org/users-guide/s-heartbeat-r1.html
https://help.ubuntu.com/community/HighlyAvailableLAMP
http://it.toolbox.com/wiki/index.php/Debian_HA_MySQL_Servers_with_Heartbeat
http://www.linuxjournal.com/article/5862
http://www.linux-ha.org/doc/re-hacf.html
http://wildness.espix.org/index.php?post/2008/10/28/Debian-LAMP-Failover-cluster%3A-Implementation
http://shebangme.blogspot.com/search/label/Heartbeat
http://www.linuxforums.org/forum/linux-applications/51869-how-run-mysqld.html
http://ubuntuforums.org/showthread.php?p=9422111
|