A while back I wrote about setting up DRBD on Ubuntu.
It is considerably simpler now: you don’t need to build the module anymore, a reasonably recent version is already in the box. You should still read the full directions at the DRBD web site, but to get it going, you only need to configure it and start it; don’t download anything, don’t compile any modules kernels, etc.
Rather, the module is already there; you could load it manually like this:
modprobe drbd
But you really want the utils package:
apt-get install drbd8-utils
… which sets things up the rest of the way. Simply proceed with the configuration file, /etc/drbd.conf. If you want a nice clean config file, remove all the existing resource sections in the drbd.conf installed by the Ub package, and put in something like so:
resource kylesdrbd {
protocol C;
startup { wfc-timeout 60; degr-wfc-timeout 120; }
disk { on-io-error detach; }
syncer {
}
on x1.kylecordes.com {
device /dev/drbd4;
disk /dev/sdb5;
address 192.168.17.61:7791;
meta-disk /dev/sdb1[0];
}
on x2.kylecordes.com {
device /dev/drbd4;
disk /dev/sda5;
address 192.168.17.62:7791;
meta-disk /dev/sda3[0];
}
}
The hostnames here need to match the full, actual hostnames. I show my example disk configuration, you’ll need to do somethign locally appropriate, based on understanding the DRBD docs.
Also adjust the syncer section:
syncer {
rate 40M; # the rate is in BYTES per second
}
If there was already a filesystem on the metadata partitions you’re trying to put under DRBD, you may need to clear it out:
dd if=/dev/zero of=/dev/sdb1 bs=1M count=1
Now you’re ready to fire it up; on both machines:
drbdadm create-md mwm
drbdadm attach mwm
drbdadm connect mwm
# see status:
cat /proc/drbd
You now are ready to make one primary; do this on only one machine of course:
drbdadm -- --overwrite-data-of-peer primary all
or
drbdadm -- --overwrite-data-of-peer primary kylesdrbd
In my case, I now see a resync starting in the /proc/drbd output.
You don’t need to wait for that to finish; go ahead and create a filesystem on /dev/drbd0.
It’s best to have a dedicated Gigabit-ethernet connection between the nodes; or for busy systems, a pair of bonded GigE. For testing though, running over your existing network is fine.
I found that an adjustment in the inittimeout setting helps to avoid long boot delays, if one of the two systems is down.
Of course I only covered DRBD here; typically in production you’d use it in conjuction with a failover/heartbeat mechanism, so that whatever resource you serve on the DRBD volume (database, NFS, etc.) cuts over to the other machine without intervention; there is plenty to read online about Linux high availability.