Click here to Skip to main content
12,953,700 members (44,352 online)
Click here to Skip to main content
Add your own
alternative version


5 bookmarked
Posted 10 Jun 2014

MariaDB Galera Replication Cluster

, 10 Jun 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
A very simple replication cluster with MariaDB


High availability is crucial for E-business, web services and others. With this simple replication cluster, we do a very useful DB server.

Installing MariaDB and Galera

A MariaDB replication cluster needs two or more nodes/servers, we'll work with Ubuntu server 12.04 as operating system for the nodes. In this case, I'll setup the replication cluster with 3 nodes (Server1, Server2 and Server3), each one has one network interface with the following IP address respectively:,, and

Ubuntu 12.04 doesn't contains the MariaDB repositories so we have to add them manually and import the key for the repository.

apt-get install python-software-properties
apt-key adv --recv-keys --keyserver 0xcbcb082a1bb943db
add-apt-repository ’deb precise main’
apt-get update

Then, install the following packages:

  • rsync
  • galera
  • mariadb-galera-server
sudo apt-get install rsync mariadb-galera-server galera

Configuring Galera

Create a configuration file for galera cluster is needed. It contains configuration for both MariaDB and Galera (Galera configuration variables start with wsrep_). In this file, the wsrep_cluster_address variable will store the IP addresses of each node allowed to join to the cluster.

The file should be created at /etc/mysql/conf.d/ and should be named as galera.cnf. Copy this file to all nodes in the cluster.

#mysql settings
#galera settings

wsrep_sst_method variable sets the synchronization method between all the nodes, rsync is the most simple method and dosen't need credentials.

Choose one node and open the file in /etc/mysql/debian.cnf, the file should be like this:

host = localhost
user = debian-sys-maint
password = 03P8rdlknkXr1upf
socket = /var/run/mysqld/mysqld.sock
host = localhost
user = debian-sys-maint
password = 03P8rdlknkXr1upf
socket = /var/run/mysqld/mysqld.sock
basedir = /usr

Copy it (in the same location) to all nodes in the cluster, after that stop mysql service in each node.

Server1#: sudo service mysql stop
Server2#: sudo service mysql stop
Server3#: sudo service mysql stop

Running Galera

Start the mysql service in one node and add the arg for a new cluster:

Server1#: service mysql start --wsrep-new-cluster

The new cluster should be running with one node in it, check the wsrep_cluster_size variable with the following query:

Server1#: mysql -u root -e ’SELECT VARIABLE_VALUE as "cluster size" 

| cluster size |
| 1            |

In the other nodes, just start normally the mysql service:

Server2#: service mysql start
Server3#: service mysql start

You can check the size of the cluster on any node with the SQL query mentioned a few lines above.

Points of Interest

MariaDB galera cluster it is currently available on Linux only.

The library in wsrep_provider is installed by the package galera.

More information is available at


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Alain Peralta
Mexico Mexico
Great things come from rare ideas. Wink | ;)

You may also be interested in...

Comments and Discussions

GeneralMy vote of 4 Pin
xfzheng19-Jun-14 16:09
memberxfzheng19-Jun-14 16:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170525.1 | Last Updated 10 Jun 2014
Article Copyright 2014 by Alain Peralta
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid