High Availability (HA) – MySql using DRBD Part 7

Configuraing MySql on DRBD cluster: Till now we have learned that who we can connect two machines and use DRBD to replicate data on one device on 1st machine to another device on 2nd machine.

This replication can be used for backing-up any kind of data,files etc. We are here going to discuss about how we can use MySql with DRBD to ensure High Availability of Mysql service without loss of any data in case machine goes down.

It can be easily understood that by using DRBD we have a device which is replicated to other machine so we can use this device for data recovery in case one of the machine goes down. Below are some instructions for using the replicated device for Mysql:

1. Move data directory of Mysql to replicated device: Mysql data directory generally resides at /var/lib/mysql so we need to move it to replicated partition so that all the data which will be written on this mysql instance will be copied to other machine of DRBD cluster.

Your machine should be primary machine for doing this and after mounting your device on file system you can copy the data directory to replicated partition

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



2. Move Mysql configuration file to replicated device: MySql main configuration file ‘my.cnf’ which resides in /etc directory needs to be moved to replicated device too as it can be used by other machine in case of failure.

# cp /etc/my.cnf /mnt/drbd/mysql



To make it transparent it from mysqld service symbolic link from /etc/my.cnf to the new configuration file on the DRBD device file system. This step will be required on both the machines which will enable both machines to run mysqld service on replicated device file system.

# ln -s /drbd/mysql/my.cnf /etc/my.cnf



3. Restart Mysql: Restart mysqld service on primary of both the machines. Now all the data is on replicated device and in case primary goes down because of any reason, secondary can be used by immediately turning on mysql service on it.

There are some modules like Heartbeat which does it automatically and quite smoothly in case one machine or service goes down. I will cover it in a separate post.

Most Commented Posts

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

No comments yet.

Leave a comment

(required)

(required)