31.8 C
Senior Writer and partner

How to create a cluster with MariaDB Galera on Ubuntu 18.04?

The data that makes sense of the information must be safeguarded by system administrators around the world. Information management cannot be conceived without high technology that can lead to effective plans to achieve this goal.

One of the technologies available to perform this task is clustering. In short, cluster is a group of multiple computers linked by a high-speed network, so that the whole is seen as a single computer, more powerful than common desktop computers.

The advantages of having servers in clusters are many and range from processing speed to database scalability, allowing database replication.

MariaDB has within its products a software that allows us to do this in an efficient way on Ubuntu 18.04 and that utility is called MariaDB Galera Cluster. In this tutorial we will learn how to make one with two nodes.

Information about the nodes

- Advertisement -

For this article we will make a cluster with two nodes with the following data:

  • OS: Ubuntu Server 18.04
  • Hostnames: osradar1, osradar2
  • IP address:,
  • RAM Memory: 512mb both
  • Hard Drive: 20gb

It is vital to handle this information before we start our work because we will have to handle it well later on.

Installing MariaDB Galera Cluster

As the official documentation tells us, from version 10.1 the utility is self-contained, inside the mariadb-server package. Therefore we proceed to install it:

              sudo -i

1.- Root user
1.- Root user

When you enter the password, you will be a root user.

Now, we proceed to install the mariadb server and mariadb galera cluster.

             apt install mariadb-server mariadb-client

2.- Installing mariadbserver and mariadb galera cluster
2.- Installing mariadbserver and mariadb galera cluster

Then we proceed to install rsync which is a necessary utility for the cluster to work.

             apt install rsync

3.- Installing rsync
3.- Installing rsync

Note: these commands must be executed on each of the nodes

Configuring MariaDB cluster

In order for the cluster to achieve communication between the nodes, a common configuration file must be created in each of them. We create it with the following command:

              nano /etc/mysql/conf.d/cluster.cnf

And we put the following information in:


#Galera Provider Configuration

#Galera Cluster Configuration

#Galera Synchronization Congifuration

#Galera Node Configuration

Now we have to modify some parameters to adapt them to our tutorial. First the line:


We must add the ip addresses of our nodes, so that’s how it looks:


And in the segment: #Galera Node Configuration, we add our parameters


5.- configuration file
5.- configuration file

I remind you that this same file must be created in each of the nodes, modifying the ip address and computer name parameters.

Once this process is done, we must run the mysql_secure_installation script to define root password and other things:


We define the root password and answer the questions: Y,N,Y,Y.

6.- mysql_secure_installation
6.- mysql_secure_installation

7.- mysql_secure_installation
7.- mysql_secure_installation

For the cluster to work we must add rules in the firewall allowing access through certain ports.

            ufw enable
            ufw allow 3306/tcp
            ufw allow 4444/tcp
            ufw allow 4567/tcp
            ufw allow 4568/tcp
            ufw allow 4567/udp


Configuring Node 2

Previously we must run the mysql_secure_installation script to configure mariadb on this node:


We respond in the same way as in the first node.

As mentioned above, we must create the same configuration file but modifying the IP and hostname criteria.

                nano /etc/mysql/conf.d/cluster.cnf

cluster cnf
8.-cluster cnf

And we also opened the firewall ports:

            ufw enable
            ufw allow 3306/tcp
            ufw allow 4444/tcp
            ufw allow 4567/tcp
            ufw allow 4568/tcp
            ufw allow 4567/udp

opening ports
9.-opening ports


As ubuntu is a Debian derivative, we have to copy a configuration file to all nodes. It is important to note that only the file of the first node is useful and should not be modified in the rest of the nodes. That’s why the other nodes must have their own file but must be changed so that it is the same as the first one.

The file is located in /etc/mysql/debian.cfg

Initializing the cluster

Before initializing the cluster we must stop the Mariadb service on all nodes:

             sudo systemctl stop mysql

46.- Stoping the service
10.- Stoping the service

Now we must initialize the cluster in the first node, to do this:


47.- galera Cluster
11.- galera Cluster

With this, you should now start the cluster and the added node 1. To check, we proceed to write:

               mysql -u root -p -e “SHOW STATUS LIKE ‘wsrep_cluster_size'”

When entering the password, we should see something like this:


Showing size of cluster
12.-Showing size of cluster

Now we must go to the second node, and initialize the mariadb service.

              systemctl start mysql

And we return to the first node to verify that the second node has joined the cluster:

mysql -u root -p -e “SHOW STATUS LIKE ‘wsrep_cluster_size'”

Showing the second node added to cluster
13.-Showing the second node added to cluster

Testing the efficacy of the cluster

To prove that the cluster is working in practice is by demonstrating database replication. In the first node, we access mariadb console and create a database:

                mysql -u root -p


               CREATE DATABASE cluster;


              SHOW DATABASES;

And in the second node, we show the databases with Show Databases:

Testing the replication
14.-Testing the replication

This is a tool with great potential, it allows us many possibilities in the segment of database management.

Please share this article through your social networks.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
"The best Linux newsletter on the web"


  1. ” – is not the same as ” in your configs. I broke my head trying to understand why the cluster does not start after copying it in my system…


Please enter your comment!
Please enter your name here

Latest article