MariaDB Galera is a multi-master cluster for MariaDB. Since MariaDB 10.1, the MariaDB Server and MariaDB Galera Server packages have been combined and Galera packages and their dependencies get installed automatically when installing MariaDB. Currently, MariaDB Galera Cluster only supports the InnoDB/XtraDB storage engine. In MariaDB 10.0 and 5.5, you will need to download it separately. MariaDB Galera adds redundancy for a site's database. In MariaDB Galera Cluster, multiple database servers interconnected with each other and keep synchronized.

MariaDB Galera provides lots of features, some of them are listed below:

Synchronous replication.

Automatic node joining.

Active-active multi-master topology.

True parallel replication, on row level.

Read and write scalability, Smaller client latencies.

Failed nodes, automatic drop from the cluster.

In this tutorial, we will explain how to setup MariaDB Galera Cluster 10.1 with 3 nodes running on Ubuntu 16.04 server. We will also test database replication between all the nodes.

Getting Started

First, you will need to update all the nodes with the latest version. You can update all of them with the following command:

sudo apt-get update -ysudo apt-get upgrade -y

Next, restart all the nodes to apply these changes. Then, log in with sudo user and proceed to the next step.

Install MariaDB Galera

MariaDB Server and MariaDB Galera Server packages are combined in the version MariaDB 10.1. By default, MariaDB 10.1 is not available in the default Ubuntu repositories, so you will need to add the MariaDB repository on all the nodes.

Once the repository is updated, install MariaDB with the following command:

sudo apt-get install mariadb-server rsync -y

The above command will install MariaDB with Galera and several dependencies. The Galera parts remain dormant until configured, like a plugin or storage engine. Once the MariaDB is installed on all the nodes, you can proceed to secure MariaDB.

By default MariaDB installation is not secured, so you will need to secure MariaDB installation. You can do this by running the mysql_secure_installation script:

sudo mysql_secure_installation

In this process, you will be asked to set root password, remove anonymous users, disallow root login remotely and remove test database. Answer all the questions as shown below:

Configure Firewall

Galera Cluster uses four ports 3306 for MySQL client connection, 4444 for State Snapshot Transfer, 4567 for Galera Cluster replication traffic and 4568 for Incremental State Transfer. So you will need to allow all these ports using the UFW firewall. You can do this by running the following command on all the nodes:

Conclusion

I hope you have now enough knowledge to install and configure MariaDB Galera Cluster on Ubuntu 16.04. You can now easily scaled up to several, or even dozens, of distinct nodes. If you have any doubt or more query, then refer the link Galera Cluster Doc