In this tutorial, we will explain How to install MariaDB Cluster in Ubuntu.

MariaDB Galera Cluster is a synchronous multi-master cluster for MariaDB. It is available on Linux only, and only supports the XtraDB/InnoDB storage engines (although there is experimental support for MyISAM – see the wsrep_replicate_myisam system variable). Starting 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.

Prerequisites

You will need:

  • VPS running Ubuntu

Step 1 – Add MariaDB repos

First, install python software into your system.

apt-get -y install software-properties-common python-software-properties

After, add key server from ubuntu:

apt-key adv –recv-keys –keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db

Now, add the repository:

add-apt-repository ‘deb http://mirror3.layerjet.com/mariadb/repo/5.5/ubuntu precise main’

And update the server system:

apt-get update

Step 2 – Install MariaDB

Now MariaDB is ready to install. Run this command to install:

apt-get -y install mariadb-server rsync

To start MariaDB, run this command:

systemctl start mariadb

Run MySQL secure installation:

mysql_secure_installation

Enter for none because you don’t have current password.

If you want to set root password enter Y if you don’t want enter n.

To stop MariaDB, use this command:

systemctl stop mariadb

Step 3 – Configuration

Edit galera-cluster.cnf following this command:

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

And add lines to that file.

[mysqld]
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0

# Galera Provider Configuration
wsrep_on=ON
wsrep_provider=/usr/lib/galera/libgalera_smm.so

# Galera Cluster Configuration
wsrep_cluster_name=”galera_cluster”
wsrep_cluster_address=”gcomm://10.20.30.1,10.20.30.2,10.20.30.3″

# Galera Synchronization Configuration
wsrep_sst_method=rsync
# Galera Node Configuration
wsrep_node_address=”10.20.30.1″
wsrep_node_name=”Galera_Node1″

Save and close it.

If you want to add other servers use this lines.

wsrep_node_address=”10.20.30.1″

wsrep_node_name=”node2″

After add service and ports to firewall:

firewall-cmd –zone=public –add-port=3306/tcp –permanent

firewall-cmd –zone=public –add-port=4567/tcp –permanent

firewall-cmd –zone=public –add-port=4568/tcp –permanent

firewall-cmd –zone=public –add-port=4444/tcp –permanent

firewall-cmd –zone=public –add-port=4567/udp –permanent

If firewall-cmd command is not working install firewalld :

apt-get install firewalld

And start firewalld

systemctl start firewalld

Step 4 – Testing

Now start node and MariaDB:

galera_new_cluster

systemctl start mariadb

And use this command to check the status:

mysql -u root -p -e “show status like ‘wsrep_cluster_size’;

You have successfully installed MariaDB Cluster in Ubuntu.

Enjoy it.