How To Configure a Galera Cluster with MariaDB on Arch Linux

Posted in arch by aangelis on 05 April 2016

Assuming that we already have two machines (node1 and node2) running mariadb database server we can proceed with Galera installation.

Unfortunately galera package in aur is broken, so we will have to compile and install it manually.

# pacman -S git rsync lsof scons boost check openssl
# git clone https://github.com/codership/galera.git
# cd galera/
# scons 
# mkdir /usr/lib/galera
# cp libgalera_smm.so /usr/lib/galera/

We can copy libgalera_smm.so to second node. Once you have installed galera, we need to configure the cluster.

We will add the following configuration settings in mariadb my.cfg file in mysqld section in both machines.

default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
innodb_flush_log_at_trx_commit=0
innodb_doublewrite=1
query_cache_size=0
wsrep_on='ON'
wsrep_provider=/usr/lib/galera/libgalera_smm.so
binlog_format=ROW
wsrep_cluster_address='gcomm://{ node 1 IP },{ node 2 IP }'
wsrep_node_address='{ node IP }'
wsrep_node_name='node{1|2}'
wsrep_cluster_name='my_galera_cluster'
wsrep_sst_method=rsync

Only on first node we will comment out cluster address and insert a blank one.

wsrep_cluster_address='gcomm://'
#wsrep_cluster_address='gcomm://{ node 1 IP },{ node 2 IP }'

We can now start mariadb on first node

node1# systemctl start mysqld

We will verify that the cluster has been bootstrapped.

node1# mysql -u root 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 15
Server version: 10.1.13-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SHOW STATUS LIKE 'wsrep_cluster_s%';
+--------------------------+--------------------------------------+
| Variable_name            | Value                                |
+--------------------------+--------------------------------------+
| wsrep_cluster_size       | 1                                    |
| wsrep_cluster_state_uuid | 34e1355d-faa6-11e5-b7da-ca159a488a54 |
| wsrep_cluster_status     | Primary                              |
+--------------------------+--------------------------------------+
3 rows in set (0.00 sec)

We can now start the second node (without restarting the first) manually to avoid systemctl service timeout issues.

node2# sudo -u mysql mysqld --pid-file=/run/mysqld/mysqld.pid  &

After a while our second node will join and sync with the primary cluster server (node1).

node2# mysql -u root 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 15
Server version: 10.1.13-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SHOW STATUS LIKE 'wsrep_local_state_%';
+---------------------------+--------------------------------------+
| Variable_name             | Value                                |
+---------------------------+--------------------------------------+
| wsrep_local_state_comment | Synced                               |
| wsrep_local_state_uuid    | 34e1355d-faa6-11e5-b7da-ca159a488a54 |
+---------------------------+--------------------------------------+
2 rows in set (0.00 sec)

MariaDB [(none)]> SHOW STATUS LIKE 'wsrep_cluster_s%';
+--------------------------+--------------------------------------+
| Variable_name            | Value                                |
+--------------------------+--------------------------------------+
| wsrep_cluster_size       | 2                                    |
| wsrep_cluster_state_uuid | 34e1355d-faa6-11e5-b7da-ca159a488a54 |
| wsrep_cluster_status     | Primary                              |
+--------------------------+--------------------------------------+
3 rows in set (0.00 sec)

Our cluster is up and running.

We will delete the blank cluster address config line in node1 and uncomment the full address configuration line.

wsrep_cluster_address='gcomm://{ node 1 IP },{ node 2 IP }' 

Finally we will restart node2 mariadb and enable service on both machines.

node2# mysqladmin -u root shutdown
node2# systemctl start mysqld
node1# systemctl enable mysqld
node2# systemctl enable mysqld