Replicate your data using DRBD (draft)

Some programs just don’t include replication as an option. DRBD is then a very good way to replicate your service/data transparently.

Just have your service and configuration files/data run on a disk, and deploy DRBD to replicate the disk on another server. You can use heartbeat or corosync along to assure high availability to your system.

What’s amazing is that DRBD is OPEN SOURCE.

To deploy DRBD, on both nodes simply follow:

– ReCompile and build your kernel with DRBD support:

I’ve tested DRBD on Gentoo distribution,

# cd /usr/src/linux-3.10.7-gentoo/
linux-3.10.7-gentoo # make menuconfig

scripts/kconfig/mconf Kconfig
#
# using defaults found in /boot/config-3.4.45-sdf134-core2-64
#

*** End of the configuration.
*** Execute 'make' to start the build or try 'make help'.

DRBD
Compile and build your binary kernel, then copy it and link it to where your boot-loader is configured to look
for the kernel.

 # cat /proc/cpuinfo
linux-3.10.7-gentoo # time make -j4
linux-3.10.7-gentoo # make modules_install
linux-3.10.7-gentoo # cp arch/x86/boot/linux-3.10.7 /boot/
#reboot

– Synhronize time with an NTP server:

</pre>
emerge -tav <a class="external text" href="http://packages.gentoo.org/package/net-misc/ntp" rel="nofollow">net-misc/ntp</a>

and follow Gentoo wiki.

– Configure network connectivity on both nodes.

I suggest using dedicated network interface for DRBD. Then use hosts file so both nodes could connect  to and identify each other.

# echo '192.168.1.10 node1' >> /etc/hosts

Chek if no service is using port 7788 and 7799, no firewall rule is blocking in/out tcp connection
between nodes.

– Install DRBD control tools

</pre>
# emerge -tav sys-cluster/drbd

* IMPORTANT: 8 news items need reading for repository 'gentoo'.
* Use eselect news to read news items.

These are the packages that would be merged, in reverse order:

Calculating dependencies... done!
[ebuild  N     ] sys-cluster/drbd-8.4.2  USE="udev -bash-completion -heartbeat -pacemaker -xen" 660 kB

Total: 1 package (1 new), Size of downloads: 660 kB

Would you like to merge these packages? [Yes/No]

– Prepare your disks:

Partition your disk  and hand it empty to DRBD without a filesystem.

</pre>
# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.21.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help):

– Configure your resources:

DRBD is configured through /etc/drbd.d/global_common.conf and use /etc/drbd.conf.

The resource is configured through the file /etc/drbd.d/res_name.res.

Refer to DRBD Doc for more details.

– Start DRBD and create metadata on your disk

</pre>
# /etc/init.d/drbd start

#drbdadm create-md res_name0

#drbdadm primary res_name0  #Only on the primary node

You can then write on your DRBD device, format it and mount it, but you can do it only on the primary node.

– Watch DRBD resource synhronization using the proc file:

# cat /proc/drbd*

Troubleshooting?

It’s simple and straightforward, there is still one more thing you should consider: performance.

Advertisements
Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s