Tuesday, March 8, 2011

How to : install and configure DRBD on two Centos Vms tutorial

DRBD is a Linux Kernel module that constitutes a distributed storage system. You can
use DRBD to share block devices between Linux servers and, in turn, share file systems and data.
   in a nutshell, Data change on Master Node will be synced to Slave node in the real time mostly. changes on master will be captured on the kernel level, then push the change to slave node and get network ack when nodes are connected. If network is broken, the data change will be queued locally and flush to remote node when it get online.

 image

Here , I will install and configure a two nodes cluster using two centos vm.  we need make sure both VM are network-reachable. then just install, make and config steps.

Let’s say I have two Nodes, they are Home and LA. I will start the setup from Home

On Both Nodes, expand the Disk to add more space and create a new partition hda4 with the same size (not required.)

image

expand the disk space , here i  will expend 1G more space.

image

then create the partition hda4
image

Also make sure each node has two NIC card for failover.

Now, we will use a GUI tool to install and config the drbd cluster, it’s called DRBD-MC which is a standard java application. It will call yum to install the drbd and push the change the those conf files when user click the gui.

Download the jar file from http://oss.linbit.com/drbd-mc/, drbc-mc.jar and run the jar file on master node.

java –jar ~/Desktop/drmc-*.jar
image

the main screen ,

image

Click the Host wizard and add one master node called Home and enter the root password.
here is the sweet set of the tool, it prerequisites component is missing, just click install to bring it in.

image
here is the generated script to install pacemaker

wget -N -nd -P /etc/yum.repos.d/ http://www.clusterlabs.org/rpm/epel-5/clusterlabs.repo && rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm ; yum -y -x resource-agents-3.* -x openais-1.* -x openais-O.9* -x heartbeat-2.1.* install pacemaker.x86_64 heartbeat.x86_64 && /sbin/chkconfig --add heartbeat

after install drbd and necessary dependency component like pacemaker, click Cluster wizard to create a cluster. I will name it helloworld

image

And select two available hosts

image

chose the default communication protocol.

image

Click to add two interfaces
image

Create the create config button to generate the conf file

image

after done, click the storge manu, chose the hda4 partition, click the action manu to select the LA mirror device

image

give it a resource name hda4

image

click next then you need to create a metadata, here we will keep the meta data into the device itself

image

then chose Home as the primary node, and create a ext3 filesystem

image

Now the device will be synced from home node to la node.

image

you can also run service drbd status. or just cat /porc/drbd
image

from the secondary node, you can tell its role is secondary.
image 
then wait for the sync to be done.

Now, we can mount the /dev/drbd0 device to a file system.
mkdir /mnt/drbd/hda4
mount /dev/drbd0 /mnt/drbd/hda4

then every change to /mnt/drbd/hda4 folder will be synced to secondary node.
Please note here the secondary is read-only mode, you can’t mount the system unless you switch the role to primary node.
image


let’s create some file on master first.
touch helloworld.master

then on the primary node, bring down it’s interface to simulate a network error.
ifdown eth0
ifdown eth1
and on the slave node, change its role to primary.

image

the cluster is in disconnected state, let’s switch secondary node to take over the primary role


drbdadm primary hda4, now secondary has the  primary role.
image
mount /dev/drbd0 /mnt/drbd/hda4
then we can mount the device and see the helloworld.master is there.
image

As I say, drbd is one low level service to enable block level replication. we can use this mechanism to replicate the DB binary log of mysql or wal log of postgres , then we can get some level of High availability.

If we want to switch back the role ( now LA is the primary node, Home is unknow. )

one LA Node. (invalidate the primary role.)
image

On Home Node , just turn on the network service, ifup eth0, ifup eth1. and run “drbdadm connect hda4”
all set, role switched back to initial setting. Home is Primary, La is secondary.
image

Hope it helps.

1 comment:

Anonymous said...

Great article. It was really helpful

I am still trying to get a hang of this set up.

What should be the recommended size of the lower-level storage partition?
thanks

 
Locations of visitors to this page