Prerequisites
- Setup Minimal CentOS 5
- be sure that both nodes can resolve correctly names (either through dns or /etc/hosts)
- yum update (as usual ...
)
- yum install heartbeat drbd kmod-drbd (available in the extras repository) Current situation :
node1.yourdomain.org 172.29.156.20/24 , source disc /dev/sdb that will be replicated
DRBD Configuration
We'll
configure DRBD so that /dev/sdb will be replicated from one node to the
other (roles can be changed at any time though) The name of the drbd
resource will be "repdata" (you can of course use the name you want).
Here is the content of the /etc/drbd.conf file :
#
# please have a a look at the example configuration file in
# /usr/share/doc/drbd/drbd.conf
#
global { usage-count no; }
resource repdata {
protocol C;
startup { wfc-timeout 0; degr-wfc-timeout 120; }
disk { on-io-error detach; } # or panic, ...
net { cram-hmac-alg "sha1"; shared-secret "Cent0Sru!3z"; } # don't forget to choose a secret for auth !
syncer { rate 10M; }
on node1.yourdomain.org {
device /dev/drbd0;
disk /dev/sdb;
address 172.29.156.20:7788;
meta-disk internal;
}
on node2.yourdomain.org {
device /dev/drbd0;
disk /dev/sdb;
address 172.29.156.21:7788;
meta-disk internal;
}
}
- replicate this config file (/etc/drbd.conf) to the second node
scp /etc/drbd.conf root@node2:/etc/
- Initialize the meta-data area on disk before starting drbd (! on both nodes!)
[iyunv@node1 etc]# drbdadm create-md repdata
v08 Magic number not found
v07 Magic number not found
About to create a new drbd meta data block on /dev/sdb.
. ==> This might destroy existing data! <==
Do you want to proceed? [need to type 'yes' to confirm] yes
Creating meta data... initialising activity log NOT initialized bitmap (256 KB) New drbd meta data block sucessfully created.
As
you can see , both nodes are secondary, which is normal. we need to
decide which node will act as a primary now (node1) : that will
initiate the first 'full sync' between the two nodes :
- we can now format /dev/drbd0 and mount it on node1 : mkfs.ext3 /dev/drbd0 ; mkdir /repdata ; mount /dev/drbd0 /repdata
- create some fake data on node 1 :
[iyunv@node1 etc]# for i in {1..5};do dd if=/dev/zero of=/repdata/file$i bs=1M count=100;done
Great, data was replicated .... now let's delete/add some file :
[iyunv@node2 /]# rm /repdata/file2 ; dd if=/dev/zero of=/repdata/file6 bs=100M count=2
- Now switch back to the first node :
Note about the gui
: you can install heartbeat-gui (yum install heartbeat-gui) on a X
workstation and connect to the cluster but you'll need to change the
password of the hacluster user account on both nodes ! (or you can use
another account but put this one in the haclient group)
We'll
know create a resource group that contains an ip address
(172.29.156.200) , the drbd device (name repdata) and the filesystem
mount operation (mount /dev/drbd0 /repdata) Note : Using a group is
easier than using single resources : it will start all the resources
from a group in order (ordered=true) and on one node (collocated=true)
Here is the content of /var/lib/heartbeat/crb/cib.xml :
As you can see, we've created a rsc_location constraint so that the cluster resources will start on the prefered node.
You
can now move resources through cli (crm_resource) or by using the gui
(change the location constraint rule value - for example swithching
from node1.yourdomain.org to node2.yourdomain.org and click on apply) .
You'll be able to see all resources switching from one node to the
other (ip address, drbd and filesystem mount)
Firewall considerations
You will need to make sure that the nodes can talk on ports: