Our Blog

Stuff about the modern world…

MariaDB 10.1 Galera Cluster on Debian 8 Jessie

This is a Howto about installing MariaDB Galera Cluster on Debian 8 Jessie.

Installing MariaDB Galera Cluster is in fact quite easy and actually kind of boring in the end. This Howto is written for (and tested on) on Debian 8.3 (Jessie).

What we need

In our setup we assume 3 nodes (cluster01, cluster02, cluster03) with one interface each. We assume following IP addresses: 10.0.99.31, 10.0.99.32, and 10.0.99.33.

We need three packages installed on all nodes:

rsync

galera-3

mariadb-server

As Galera does not ship with the distribution repositories, go for the repo configurator and follow the instructions to include the repository fitting your system. Keep in mind to Choose „10.1“ in Step 3 (Choose a Version).

Install Packages

(Just another shortcut for the impatient)

apt-get install -y rsync galera-3 mariadb-server

After installing the packages you will have a running MariaDB server on each node. But none of them will be configured to run as a node in a MariaDB Galera Cluster.

Configuring Galera

So we have to do some configuration next. There is a MariaDB configuration part and one part to configure Galera (starting with wsrep_). As we do the most basic and simple installation in this Howto, it is sufficient you just change the IP’s (Remember: 10.0.99.31, 10.0.99.32, 10.0.99.33) with your IP’s. In our example, we have set hostnames on each node (cluster01, cluster02, cluster03) so we do not need the IP addresses of the hosts.
This will be needed to define the wsrep_cluster_address Variable (the list of nodes a starting mysqld contacts to join the cluster).

The following configuration file has to be distributed on all nodes. We use a separate configuration file (create a new file) /etc/mysql/conf.d/galera.cnf with the following settings:

FYI: The shared library for wsrep_provider is provided by the installed galera package.

We could also change the cluster name by changing the value of wserp_cluster_name to fit our style. This setting also works as a shared secret to control the access to the cluster.

With wsrep_cluster_address you see the hostnames of our setup. wsrep_cluster_address could also be gcomm://10.0.99.31,10.0.99.32,10.0.99.33. Multiple IP’s or hostnames have to be comma seperated.

The wsrep_sst_method tells what method to use to synchronise the nodes. While there are also mysqldump and xtrabackup available, I prefer rsync because it is easy to configure (i.e. it does not need any credentials set on the nodes). If you are considering using the xtrabackup method, don’t forget to install xtrabackup.

Debian/Ubuntu uses a special user (‚debian-sys-maint’@’localhost‘) in their init script and the credentials for that user are stored in /etc/mysql/debian.cnf. This user is used to make some checks starting MySQL. Checks I don’t think belong into a service script anyway. Because of the unique password for the user on each system, mysqld will throw some errors while starting and stopping.
We could simply ignore it, but the user is also used to shutdown mysqld. This is also not required, as a SIGTERM is sufficient to shutdown the mysqld :/
So we’ve got to fix it, by copying /etc/mysql/debian.cnf from the first node (cluster01) to all other nodes. So the data and configuration files have the same data.

Starting the Galera Cluster

The configuration file (galera.cnf) is already distributed to all nodes, so we next start the first mysqld on cluster01. This node initializes/starts the cluster (creates a GTID).

cluster01# galera_new_cluster

To have a look and see if everything really worked we’ll check the cluster size status variable.

fachamixAugust 18, 2016

Raymond BrennanOktober 21, 2016

The only thing I would add is the need for an extra line at the end of galera.cnf with wsrep-node-address= IP address of the local server. I found that without this, restarting the whole cluster failed because the database was marked as corrupt and wouldn’t start.