MySQL (Master-Master) cluster with High Availability – Part 2 of 2

In my previous post I described how to create a MySQL Replication (Master-Master) cluster. In this post we will build Cluster-IP address for our MySQL cluster. At the end of this post we will have a MySQL Cluster with High Availability.

Install & Configure Corosync and Pacemaker on server MYSQL01

First we need to add the repository to install Corosync and Pacemaker.

Update the repositry and install Corosync and Pacemaker.

Stop Pacemaker service .

Create a copy of the default Corosync config-file

Delete all the content of Corosync config-file

open the corosync.conf file for editing. I use nano

Replace the contents of corosync.conf with this configuration.
Note: This config-file may differ from you own environment. Replace the values that are specific to your configuration.

Restart Corosync to load the new configuration

Start Pacemaker

Install & Configure Corosync and Pacemaker on server MYSQL02

Repeat the exact same steps that we followed on MYSQL01.
Start once again by adding the repository

Update the repositry and install Corosync and Pacemaker.

Stop Pacemaker service .

Create a copy of the default Corosync config-file

Delete all the content of Corosync config-file

open the corosync.conf file for editing. I use nano

Replace the contents of corosync.conf with this configuration.
Note: This config-file may differ from you own environment. Replace the values that are specific to your configuration.

Restart Corosync to load the new configuration

Start Pacemaker

Now that Corosync and Pacemaker is installed and configured on both servers let’s check if our cluster works.

The output should look something like this (if not, wait for 30 seconds, then run the command again):

Configure Cluster Properties

Now we’re ready to configure the properties of Pacemaker.
Note: All Pacemaker (crm) commands can be run from either node server, as it automatically synchronizes all cluster-related changes across all member nodes.

First we want to disable STONITH (Shoot The Other Node In The Head).
Note: STONITH is the ability to remove faulty nodes if they no longer meets the cluster requirments.

Second we want to ignore the quorum policy.
Note: This setting only applies to 2-node clusters.

Thirth and last we want to configure weight-points.
Note: Weight-points are usefull when a node goes down and up, this configuration makes sure that the resources running on the other are kept there in case of flapping.

Create Cluster Resources

Now that we have configured the properties we’re ready to create resources.

Open a Pacemaker shell

Enter configuration mode

We start by monitoring pacemaker. If a node loses his network connection, we want to failover all resources to the other node.

Let’s create a Cluster-IP address for our MySQL cluster

Create a resource group for our MySQL cluster and add the Cluster-IP address

Create a location rule which will failover resources to another node.
Note: You can also use a resource instead of a group, but I find much easier because you can add/delete resources from a group. Otherwise you need to delete the location rule first and re-create

The configuration is now complete.
Let’s check if the config is done correctly

We shoud see the following output:
Note: This output may differ from you own environment.

If the config looks correctly you can commit the changes

Exit the Pacemaker shell and check if the Cluster-IP is up-and-running.

We shoud see the following output:
Note: This output may differ from you own environment.

As you can see the Cluster-IP is started on MYSQL01
Note: It could take a while before the Cluster-IP is started

We only have one final test left and that is the simulate a node failure.

On MYSQL02 we can monitoring our Pacemaker cluster with the command below.
Note: This command monitors realtime the status of our cluster

On MYSQL01 we’re going to unplug the networkcable. Let’s check what happening in the cluster.

Before 

After

As you can see Pacemaker has detected a failure on my MYSQL01 server and has migrated the Cluster-IP to MYSQL02.

Congratz! You have created a working MySQL replication (Master-Master) cluster with a Cluster-IP for High Availability.

Leave a Reply

Your email address will not be published. Required fields are marked *