MariaDB + Galera Cluster

Why MariaDB + Galera?

  • Active Master-to-Master Replication
  • Instant Replication on data commit
  • No slave lag
  • No lost transactions
  • Both read and write scalability
  • Smaller client latencies

Installation

What you need?

  • Minimum start with 3 Debian Servers.
  • Internet connectivity
  • Root access

Adding Repository

Run these on all servers

# apt-get install python-software-properties
# apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db
# add-apt-repository 'deb http://mirror3.layerjet.com/mariadb/repo/5.5/debian wheezy main'
# apt-get update

Install MariaDB + Galera

Run these on all servers

# apt-get install -y rsync galera mariadb-galera-server

Configuring Galera

The following configuration file has to be distributed on all nodes.

We use a separate configuration file /etc/mysql/conf.d/galera.cnf with the following settings:

[mysqld]
#mysql settings
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
query_cache_size=0
query_cache_type=0
bind-address=0.0.0.0
#galera settings
wsrep_provider=/usr/lib/galera/libgalera_smm.so
wsrep_cluster_name="my_wsrep_cluster"
wsrep_cluster_address="gcomm://192.168.3.19,192.168.3.20,192.168.3.21"
wsrep_sst_method=rsync

wsrep_node_address="192.168.3.21"
wsrep_node_name="galera3"

wsrep_cluster_address = list of all ip addresses in this cluster.

wsrep_node_address and wsrep_node_name is the local ip address and node name on each node.

Starting Galera Cluster

First, stop mysql service on all servers

node01# service mysql stop
node02# service mysql stop
node03# service mysql stop

Then, initialize the replication on node 1

node01# service mysql start --wsrep-new-cluster

Copy the /etc/mysql/debian.cnf on node1 to all nodes.

node01# scp /etc/mysql/debian.cnf root@node02:/etc/mysql/debian.cnf
node01# scp /etc/mysql/debian.cnf root@node03:/etc/mysql/debian.cnf

To have a look and see if everything really worked we’ll check the cluster size status query. Run on node1.

SELECT VARIABLE_VALUE as "cluster size" 
FROM INFORMATION_SCHEMA.GLOBAL_STATUS 
WHERE VARIABLE_NAME="wsrep_cluster_size"

Run the query using mysql cli. For now, the cluster size is 1.

Because currently only node1 active.

Go to node2 and node3, then fire up the mysql service

node2# service mysql start
node3# service mysql start

For now, the MariaDB + Galera is already set up and running.

re-run the query using mysql cli. Now the cluster size is 3, indicating

that all servers are successfully added into cluster

Read more:

  1. https://blog.mariadb.org/installing-mariadb-galera-cluster-on-debian-ubuntu/
  2. http://galeracluster.com/products/
  3. http://galeracluster.com/products/technology/

Thank you!

MariaDB

By Christian W Utomo