How to Setup MariaDB Galera Cluster on CentOS 7 – DebYum

share on:
Restart Galera cluster after reboot.

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.

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.

Features

  • Synchronous replication
  • Active-active multi-master topology
  • Read and write to any cluster node
  • Automatic membership control, failed nodes drop from the cluster
  • Automatic node joining
  • True parallel replication, on row level
  • Direct client connections, native MariaDB look & feel

Benefits

The above features yield several benefits for a DBMS clustering solution, including:

  • No slave lag
  • No lost transactions
  • Both read and write scalability
  • Smaller client latencies

 

Setting up MariaDb Galera in CentOS 7.

I am using three CentOS 7 minimal install DigitalOcean VPS. Private networking enabled on these servers for security.

galera-01.engy.remote will be the main node in this tutorial.

10.136.42.199       galera-01.engy.remote     galera-01
10.136.42.249       galera-02.engy.remote     galera-02
10.136.43.4           galera-03.engy.remote      galera-03

 

Setup Mariadb Galera in CentOS 7.

Install MariaDB in CentOS 7.

cat <<EOF>>/etc/yum.repos.d/mariadb.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.0/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF

 

Set SELinux in permissive mode.

setenforce 0

 

Install MariaDB Galera Cluster 10 on CentOS 7 server.

We will start by installing Epel-release package and updating the system.

shell> rpm --import /etc/pki/rpm-gpg/RPM-GPG*
shell> yum install -y epel-release
shell> yum update -y
shell> yum remove mariadb-libs -y
shell> yum install boost-devel.x86_64 socat MariaDB-Galera-server MariaDB-client MariaDB-compat galera socat jemalloc rsync galera -y

 

Start the MariaDB Galera cluster on all nodes.

shell> sudo service mysql start

 

Secure the MySQL installation on all nodes.

shell> mysql_secure_installation

 

Create users for Galera cluster on ALL NODES.

Login to MariaDB console as root and create a user for Galera Cluster.

DELETE FROM mysql.user WHERE user='';
GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY 'EnGy_17';
GRANT USAGE ON *.* to allow_engy@'%' IDENTIFIED BY 'EnGy_17';
GRANT ALL PRIVILEGES on *.* to allow_engy@'%';
FLUSH PRIVILEGES;
quit

 

Stop Mariadb galera instances on ALL NODES.

shell> systemctl stop mysql
shell> systemctl status mysql

 

Edit server.conf file (create one if not present).

shell> vi /etc/my.cnf.d/server.conf

 

GALERA-01

On node galera-01 ( ip address 10.136.42.199), Edit server.conf file as follows. (change ip and node name)

[galera]
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
innodb_locks_unsafe_for_binlog=1
query_cache_size=0
query_cache_type=0
bind-address=0.0.0.0
datadir=/var/lib/mysql
innodb_log_file_size=100M
innodb_file_per_table
innodb_flush_log_at_trx_commit=2
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address=”gcomm://10.136.42.199,10.136.42.249,10.136.43.4
wsrep_cluster_name=’galera_cluster
wsrep_node_address=’10.136.42.199
wsrep_node_name=’galera-01
wsrep_sst_method=rsync
wsrep_sst_auth=allow_engy:EnGy_17

 

GALERA-02

On node galera-02 ( ip address 10.136.42.249), Edit server.conf file as follows. (change ip and node name)

[galera]
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
innodb_locks_unsafe_for_binlog=1
query_cache_size=0
query_cache_type=0
bind-address=0.0.0.0
datadir=/var/lib/mysql
innodb_log_file_size=100M
innodb_file_per_table
innodb_flush_log_at_trx_commit=2
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address=”gcomm://10.136.42.199,10.136.42.249,10.136.43.4
wsrep_cluster_name=’galera_cluster
wsrep_node_address=’10.136.42.249
wsrep_node_name=’galera-02
wsrep_sst_method=rsync
wsrep_sst_auth=allow_engy:EnGy_17

 

GALERA-03

On node galera-03 ( ip address10.136.43.4), Edit server.conf file as follows. (change ip and node name)

[galera]
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
innodb_locks_unsafe_for_binlog=1
query_cache_size=0
query_cache_type=0
bind-address=0.0.0.0
datadir=/var/lib/mysql
innodb_log_file_size=100M
innodb_file_per_table
innodb_flush_log_at_trx_commit=2
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address=”gcomm://10.136.42.199,10.136.42.249,10.136.43.4
wsrep_cluster_name=’galera_cluster
wsrep_node_address=’10.136.43.4
wsrep_node_name=’galera-03
wsrep_sst_method=rsync
wsrep_sst_auth=allow_engy:EnGy_17

 

All done. Now, let’s start the MariaDB Galera cluster by starting MariaDB service on each node. Start with main node Galera-01.

(choose any node as main node and run this command /etc/init.d/mysql start –wserp-new-cluster).

ON main node (galera-01), start the MySQL service.

[root@galera-01 ~]# sudo /etc/init.d/mysql start --wsrep-new-cluster
Starting MySQL.170126 10:04:54 mysqld_safe Logging to '/var/lib/mysql/galera-01.engy.remote.err'.
170126 10:04:54 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
. SUCCESS!
[root@galera-01 ~]#

 

Check the Galera cluster size. 

[root@galera-01 ~]# mysql -uroot -p -e "show status like 'wsrep%'"

 


On Galera-02 start the mysql service.

[root@galera-02 ~]# sudo service mysql start
Starting MySQL.170126 10:06:16 mysqld_safe Logging to '/var/lib/mysql/galera-02.engy.remote.err'.
170126 10:06:16 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
.SST in progress, setting sleep higher. SUCCESS!
[root@galera-02 ~]#

 

Check the Galera cluster size.

[root@galera-02 ~]# mysql -uroot -p -e "show status like 'wsrep%'"

 

 

Similarly on the Third server. galera-03

[root@galera-03 ~]# sudo service mysql start
Starting MySQL.170126 10:06:16 mysqld_safe Logging to '/var/lib/mysql/galera-03.engy.remote.err'.
170126 10:06:16 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
.SST in progress, setting sleep higher. SUCCESS!
[root@galera-03 ~]#

 

Check the Galera cluster size.

[root@galera-03 ~]# mysql -uroot -p -e "show status like 'wsrep%'"

 

 

 

All three nodes are in now.

Finally, check the Cluster size on galera-01 to confirm.

 

Test the working of MariaDB Galera Cluster.

If you create or delete Databases or tables on anyone of the MariaDB Galera cluster nodes the same will automatically perform on the remaining nodes.

More like Create/delete on one node = Create/delete on all nodes.

 

On glaera-01 create a database named testing.

 

Check result on galera-02 server.

 

Sources: MariaDB Galera Cluster

 

Thanks for visiting this page and have a great day.  🙂

share on:
engy

engy

Hello there, My name is Rishi Guleria and I work as a Linux system administrator. I have created this blog to share what I have learned so far and to learn new things. Good Day. :)

2 Comments

  1. Hi,

    I have a little problem. when I try to /etc/init.d/mysql start –wserp-new-cluster my server got an ERROR in log file I see this:
    [Note] Plugin ‘FEEDBACK’ is disabled.
    170724 3:17:43 [ERROR] /usr/sbin/mysqld: unknown variable ‘wsrep_provider=/usr/lib/galera/libgalera_smm.so’
    170724 3:17:43 [ERROR] Aborting

    but if I search the file libgalera_smm.so it are under /usr/lib/galera/!!:

    # find / -name ‘*libgalera_smm.so*’
    /usr/lib64/galera/libgalera_smm.so

    have any idea?

Leave a Response

share on: