wesupport

Need help?

Our experts have had an average response time of 13.14 minutes in February 2024 to fix urgent issues.

We will keep your servers stable, secure, and fast at all times for one fixed price.

High Availability Hosting with DRBD

by | Jan 27, 2008

Some Useful DRBD Commands

drbdsetup

This is a low level configuration tool of DRBD. This is normally used to configure DRBD blocks.

Let us know see the usage of drbdsetup

For Master:

# drbdsetup /dev/nbx disk /dev/hdcx

# drbdsetup /dev/nbx net <slave’s_ip> <master’s_ip> <protocol> </protocol></master’s_ip></slave’s_ip>

For Slave:

# drbdsetup /dev/nby disk /dev/hdcy

# drbdsetup /dev/nby <master’s_ip> <slave’s_ip> <protocol> </protocol<</slave’s_ip></master’s_ip>

# drbdsetup /dev/nby primary

drbdadm

This is an administration tool of DRBD. There are numerous sub-commands for this. Here we will be discussing only the basic commands:

# drbdadm primary all -> sets the state of local device to be primary.

# drbdadm secondary all -> sets the state of local device to be secondary.

If you want to change the state of a resource or resources rather than all, you can specify the resource name:

In our sample configuration file, we had the DRBD resource as drbd0, so to change its state execute:

# drbdadm primary/secondary drbd0

# drbdadm disconnect all -> temporarily disconnects all the DRBD nodes.

# drbdadm connect all -> connects all the DRBD nodes.

Additional Notes

DRBD module can be combined with Linux Heartbeat service for automatic fail-over support.

Heartbeat is the first software which is developed for the Linux-HA project. It can be downloaded from http://www.linux-ha.org/download

Using DRBD, we can replicate any of the web applications like Apache, MySQL, NFS,… etc. All you need to do is to copy the data to be replicated to the DRBD block. I will explain the steps to configure MySQL with DRBD.

Configure MySQL for DRBD

Once the DRBD is set up as above, you can configure MySQL to use the DRBD block to store MySQL data.

Note: If you are going to install MySQL once the DRBD is set, you can configure the data directory of MySQL as the DRBD mount point. Also note that these configurations need to be done in the DRBD primary node.

Migrating an Existing MySQL Installation

To set up DRBD for an existing MySQL you need to follow the steps given below:

As already explained, we have our DRBD block mounted on /mnt/drbd.

Copy the Data Files (Say, MyISAM Files), Binary Log Files and MySQL Configuration File to the DRBD Block

a) Shut down MySQL Administrator.

$ mysqladmin shutdown

b) Copy the databases.

cp -R /var/lib/mysql /mnt/drbd/mysql

c) Copy the MySQL configuration file.

cp /etc/my.cnf /mnt/drbd

Configure my.cnf To Reflect the New Changes

a) Change the data directory.

datadir = /mnt/drbd/mysql

b) If you haven’t enabled binary log before, enable it now. This will be handy in checking the status.

log-bin = mysql-bin

c) Create a symbolic link from /etc/my.cnf to the new configuration file on the DRBD device file-system.

ln -s /mnt/drbd/my.cnf /etc/my.cnf

d) Now restart MySQL and check if the configuration is working.

/etc/init.d/mysql(d) restart

You are done. Now restart the DRBD service and monitor the /proc/drbd file to verify if the data is correctly replicated and synced.

References

http://www.drbd.org/drbd-article.html
http://www.drbd.org


Articles By AbnerAbout the author: Abner has been working in Bobcares for more than an year. His expertise is in data center administration with high end tools. One thing he is passionate about is, Linux. Apart from Linux, he loves Table Tennis too. 🙂

BOOST YOUR HOSTING BUSINESS!

Never again lose customers to server errors! Sign Up once. Enjoy Peace Of Mind For Ever!

CLICK HERE FOR WORLD-CLASS HOSTING SUPPORT

var google_conversion_label = "zWG9CLOojHIQ0aD71QM";

0 Comments

Categories

Tags