Setup DRBD for master/master

August 23, 2010    centos cluster drbd redhat

At my job at OpenSky we have a common NFS share that is failed over to a slave nfs node if the master dies. It was setup so that the slave would just rsync from the master. This was done to save time. Not that I have some time, I decided to finally setup drbd on the two nodes to keep the files always in sync.

So below are my nodes with hostnames/ips and drive information

Node1

host: nfs1.domain.com<br /> ip: 192.168.1.46<br /> partition: /dev/sdb1

Node2

host: nfs2.domain.com<br /> ip: 192.168.1.47<br /> partition: /dev/sdb1

So once drbd is installed setup the following file

/etc/drbd.conf

To look something like this. You will want to change a few things in red. Put this file on both nodes.

global {
  usage-count yes;
}
common {
  protocol C;
}
resource <span style="color: #ff0000;">nfs</span> {
  meta-disk internal;
  device     /dev/drbd1;
  syncer {
    verify-alg sha1;
  }
  net {
    allow-two-primaries;
  }
  on <span style="color: #ff0000;">nfs1.domain.com</span> {
    disk       <span style="color: #ff0000;">/dev/sdb1</span>;
    address    <span style="color: #ff0000;">192.168.1.46</span>:7789;
  }
  on <span style="color: #ff0000;">nfs2.domain.com</span> {
    disk       <span style="color: #ff0000;">/dev/sdb1</span>;
    address    <span style="color: #ff0000;">192.168.1.47</span>:7789;
  }
}

I choose to use protocol C. You can see the following protocols below. Also the on nfs1.domain.com has to match the output of a hostname command

<a href="http://www.drbd.org/users-guide/s-replication-protocols.html">http://www.drbd.org/users-guide/s-replication-protocols.html</a>

Now on both nodes you want to init the drbd partition. Make sure this is a blank partition. It will wipe out everything that is one it. I called my resource nfs. If you changed it the commands will be a bit different based on what name you gave your resource

drbdadm create-md nfs

You should get an output like

initializing activity log<br /> NOT initialized bitmap<br /> New drbd meta data block successfully created.<br /> success

Now make sure drbd can be run on startup and start it up now

chkconfig drbd on<br /> service drbd start

Once you start drbd on both nodes it will connect to both. If you just start one and not the other.. the other will wait for the second node to come alive.

You can now make a filesystem. Make sure it is a filesystem for clustering. I recommend ocfs2 but gfs2 also works.



comments powered by Disqus