MariaDB Cluster Install notes

I don’t write blog posts anymore. I write notes. 🙂


Prebuilt packages of mainline MariaDB 10.1 are only available for x86 and x86_64 architectures. For other architectures, you need to build it from source.

Main repository contents, find the override file for your specific distro:

To check your distro, do this:

MariaDB 10.0 was added to the universe repository in Vivid (Ubuntu 15.04). It lacks Galera patches. No backport is available.

A broken Galera 3 was added to the universe repository in Wily (Ubuntu 15.10). FWIW there is also a Percona Server Galera-3 install, but this is specifically for Percona. There is however a working copy of Galera-3 in the Ubuntu 16.04 pre-release folders.

Building MariaDB and Galera Debian packages from source


If successful, the packages *can* be installed with this…

Unfortunately, that doesn’t help us when it comes to dependencies. It can be done with many “dpkg -i <package>” and “apt-get install -f” calls, but it’s ugly.

Instead, you should move the files to a folder, and set-up a Debian Packages repository.

A simple is just a folder with a Packages list. Here’s how we generate that list:

Now, add the repository to your sources.list:

Finally, do an update, and you can install the package as expected.

Reference: Building Galera:

Reference: Debian Repositories:

Configuring MariaDB

On Ubuntu, MariaDB settings go in /etc/mysql/my.cnf

By default, MariaDB only listens on Localhost ( To make it listen on all interfaces, comment-out the bind-address line. To explicitly listen to all, make it ““.

This is insecure, but it means the Firewall is now responsible for blocking unwanted traffic.

Reference: how-to-configure-mysql-and-mariadb-to-accept-remote-connections.html

Configuring Galera Cluster

Also inside /etc/mysql/my.cnf:

Starting the Primary Server in a Galera Cluster

Start the primary server like so:

You can permanently set it to restart by editing “/etc/init.d/mysql”.

Change the call to mysql_safe as follows:


The node that calls –wsrep-new-cluster is the master. The clients are started normally without it.

The clients will fail if there’s no server. Even the main server, if you don’t run –wsrep-new-cluster, it’ll think it’s a client.

The list of servers a client will attempt to connect to is the wsrep_cluster_address line in your config.

Allowing Clients of your Galera Server

You need to unblock some ports on the primary server’s firewall.

  • 3306 – MySQL port, TCP. Used for mysqldump SST (State Snapshot Transfer, i.e. Init via mysqldump)
  • 4567 – TCP & UDP. Used for Galera Cluster replication traffic (??)
  • 4568 – TCP. Used for IST (Incremental State Transfer)
  • 4444 – TCP. Used for SST (State Snapshot Transfer, everything but mysqldump)

SST is how a client node is fully initialized. IST is how clients get their incremental updates.

SST methods have varying degrees of blocking. RSYNC (default) blocks writes, MySQLDump blocks everything (ugh), XtraBackup is non-blocking (see below).

Port Reference:

SST Reference:

Starting Clients

Once you’ve correctly configured the clients, you can simply start mysql. No changes are required. It should just work.

All tables will by synchronized with the original.

Most importantly, that includes the user table. Login credentials will be the same no matter which node you connect to.

This can be a problem for Debian and Ubuntu installs, thanks to a worker user named debian-sys-maint. This is used by ‘service mysql’ (start, stop, etc). Its password is stored in /etc/mysql/debian.cnf

You’ll want to look at this file on the Primary server, and copy the passwords to all the clients. That seems to be the easiest way to handle this.


Viewing Galera Cluster Status



Further Galera Configuration


Listing Users


Creating Users

Prefer CREATE USER. Inserting directly in to the mysql.user table will not replicate correctly across a Galera cluster.


Resetting (and setting) MySQL Passwords

If you ever find yourself in a situation where you can’t log in, you can disable authentication and log in to the server locally.

NOTE: If this is a client node of a Galera cluster, your passwords were likely taken from the Primary node (both your users, and debian-sys-maint). See the Starting Clients section above.


Building XtraBackup Debian packages from source


Using XtraBackup



Configuration Optimization


I did some benchmarks. My read speed for small queries was around 4ms, and write speeds were around 80ms. That seemed a bit much.

Making the following changes improved it.

You can achieve better performance by setting [innodb_flush_log_at_trx_commit] different from 1, but then you can lose up to one second worth of transactions in a crash. With a value of 0, any mysqld process crash can erase the last second of transactions. With a value of 2, only an operating system crash or a power outage can erase the last second of transactions.


With these changes, my write speed dropped from ~80ms to ~5ms.