Bobby's Blog

Install And Configure Galera MySQL Cluster On CentOS 7 Server

How To Install And Configure Galera MySQL Cluster On CentOS 7

Some overall info about the Galera Cluster solution. Galera Cluster for MySQL is a true Multimaster Cluster based on synchronous replication. Galera Cluster is an easy-to-use, high-availability solution, which provides high system uptime, no data loss and scalability for future growth. ( Source )

For more information, you could take a look at this official Galera Cluster for MySQL introduction video:

 


Note! With MariaDB 10.1, the wsrep API for Galera Cluster is included by default. This is available as a separate download for MariaDB 10.0 and MariaDB 5.5. If you need to do that for older version you can follow the steps here. If you want to do this for 10.1+ you can follow the steps at: Galera Cluster & MariaDB 10.1+ On CentOS 7 Server

After a few hours of research I’ve came to the conclusion that there are more Ubuntu guides on how to set install and configure a Galera Cluster, so I’ve decided to write a step by step guide on how to do that on a CentOS 7 server.

Here’s a step by step guide on how to setup Galera Cluster on a new CentOS 7 server.

Very important! Before you proceed please do the following or your setup might not work at all:

1) Disable the Selinux service. Configure SELINUX=disabled in the /etc/selinux/config file:

Reboot your system. After reboot, confirm that the getenforce command returns Disabled:

2) Disable and Stop Firewalld. To disable firewalld, run the following command as root:

Check the Status of Firewalld

Alright, now we are ready to begin!

In my case the IP addresses of my 3 machines are:

Make sure to change the IP addresses to the IP addresses of your machines.

As a side note, according to many sources, a good practice and also to keep a healthy Quorum, it’s very important to always keep an odd numbers of Galera nodes.

Installation
– Remove the default MariaDB library files for all the three servers

– Once the default MariaDB library files have been removed, create the MariaDB repository file for all three servers:

– Then install the socat dependency package in all the 3 servers:

– Now to install MariaDB Galera cluster 10.0 and its dependencies on all the servers run:

– Once it is installed, start the MariaDB service for all the servers:

Note! If you get the following error:

Then please use this command here:

– Complete the secure MariaDB installation by running the following command (Please set a root password!):

– Then you can create a MySQL user that you would use for the replication, you can use these commands here:

– Now you can stop the MariaDB service by running the following command. Do the same for all servers:

Note! If you get the following error:

Then please use this command here:

Configuration

We can now start with the Galera cluster configuration by adding the cluster address, cluster name, node address, etc. We need to do that for all servers:

For completing the cluster configuration on server2 and server3 do not forget to adjust the wsrep_node_address and wsrep_node_name variables. Before doing that you need to stop the MySQL service on both servers.

Server2:

Server3:

Once all the nodes are configured, you can start first cluster server.

NOTE This command should be executed only on server1:

After that, start MySQL on both server2 and serevr3 as well. Run the following command on both the remaining servers:

Note! If you get the following error:

; then please use this command here:

/etc/init.d/mysql start

Now check the status of configured Galera cluster on server1. Repeat this command on server2 and server3 to check the status:

This is pretty much it! Now you can play a little bit by creating databases on all servers and etc. Here is an example:

On server1:

After that login MySQL in server2 and check the replication process there too:

Login to MySQL on server3 and check the replication process in it as well:

You can create some tables or import some data to fully test the replication. Here is a short example:

You can insert some values from all servers just as a test:

Hope that this helps!

On a side note if you need to add a new server to the pool, please keep the following in mind. If you’re using rsync or mysqldump for SST transfer, bringing up the new nodes will lock the databases on the donor nodes. This could bring down heavily used setups. It would be strongly recommended to add those nodes when the setup is less solicited. Additionally, you may want to set the load balancer to only redirect requests on 2 nodes instead of 3. You would now be able to set the third node as a donor, which means it would be the only node with its DB getting locked and providing the new nodes with the data.

To set a SST donor, add the following line in the mysql configuration on the two new nodes:

( Source 1 )
( Source 2 )


About the author

Bobby

Linux System Administrator