Share on Social Media

In this configuration guide, you will learn, how to setup MariaDB Galera Cluster on CentOS 7 or other Redhat based Linux distros. #centlinux #linux #mysql

What is MariaDB Galera Cluster? :

MariaDB Galera Cluster is a synchronous multi-master cluster for MariaDB. It is a fork of Galera Cluster, the world’s most advanced, free and open source cluster engine. Currently, it only supports InnoDB storage engines.

MariaDB Galera Cluster is a true Multi-Master and Active-Active cluster. Due to it’s synchronous behaviour, there will be no data lost in case of a node crash because all nodes always hold the same state.

MariaDB Galera Cluster also provides Automatic node provisioning. It means we do not have to manually backup the database and restore it on new node before adding it to Galera cluster. This features gives the additional benefit of Cloud support due to simple scale-in and scale-out operations.

In this article, we will create a two-node MariaDB Galera Cluster of MariaDB 10.3 Database on CentOS 7. However, the same steps can be used to setup MariaDB Galera Cluster of larger size.

This article focuses on the installation of MariaDB Galera Cluster on CentOS 7 without diving into theory and definitions pertains to MariaDB. Therefore, it is recommended that you should read Getting Started with MariaDB – Second Edition (PAID LINK) by Packt Publishing to have basic understanding of MariaDB database.

Read Also: Install MariaDB Galera Cluster on Rocky Linux 9

System Specification:

For this article, we are using two CentOS 7 virtual machines as the Galera Cluster nodes.
IP Address: /24192.168.116.82/24
CPU:2.4 Ghz (2 cores)2.4 Ghz (2 cores)
Memory:2 GB2 GB
Operating System:CentOS 7.6CentOS 7.6
MariaDB Version:10.3.1210.3.12

Install MariaDB Database Server on CentOS 7:

Connect to using ssh as root user.

To setup MariaDB Galera Cluster, you need to install MariaDB and MaxScale yum repositories.

# curl -sS | bash
[info] Repository file successfully written to /etc/yum.repos.d/mariadb.repo.
[info] Adding trusted package signing keys...
[info] Succeessfully added trusted package signing keys.

Build yum cache for all repositories.

# yum makecache fast
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base:
 * extras:
 * updates:
base                                                     | 3.6 kB     00:00
extras                                                   | 3.4 kB     00:00
mariadb-main                                             | 2.9 kB     00:00
mariadb-maxscale                                         | 2.4 kB     00:00
mariadb-tools                                            | 2.9 kB     00:00
updates                                                  | 3.4 kB     00:00
(1/5): mariadb-maxscale/7/x86_64/primary_db                | 6.7 kB   00:02
(2/5): mariadb-tools/7/x86_64/primary_db                   |  11 kB   00:02
(3/5): mariadb-main/7/x86_64/primary_db                    |  50 kB   00:03
(4/5): extras/7/x86_64/primary_db                          | 156 kB   00:04
(5/5): updates/7/x86_64/primary_db                         | 1.4 MB   00:09
Metadata Cache Created

Install MariaDB Server and Galera using yum command.

# yum install -y mariadb-server galera

Repeat above steps on all other nodes.

Setup MariaDB Galera Cluster on CentOS 7:

Allow MariaDB and Galera service ports in Linux firewall.

# firewall-cmd --permanent --add-service=mysql
# firewall-cmd --permanent --add-port={4567,4568,4444}/tcp
# firewall-cmd --reload

Set SELinux to permissive mode for now, and we will enable the enforcing mode later, after creating an SELinux policy for MariaDB Galera cluster.

# setenforce 0

Now edit MariaDB configuration file.

# vi /etc/my.cnf.d/server.cnf

and configure galera section as follows:

# Mandatory settings

Perform above steps on each node.

Start Galera cluster on

# galera_new_cluster

Start MariaDB service on all other nodes.

# systemctl start mariadb.service

If the service started successfully then, it shows that we have successfully configured our Galera cluster.

Configure MariaDB database instance on each node.

# mysql_secure_installation


In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

Connect with MariaDB instance on any node and check wsrep_cluster_size.

# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 10
Server version: 10.3.12-MariaDB MariaDB Server

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

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

MariaDB [(none)]> show global status like 'wsrep_cluster_size';
| Variable_name      | Value |
| wsrep_cluster_size | 2     |
1 row in set (0.083 sec)

wsrep_cluster_size confirms that all of our nodes are now connected in Galera cluster.

Create SELinux Policy for MariaDB Galera cluster:

Since, we have configured SELinux in permissive mode. Therefore, all the violations by MariaDB and Galera has been recorded in /var/log/audit/audit.log. We can use it to create a concrete SELinux policy.

Use fgrep and audit2allow commands to extract policy violations log into a text file.

# fgrep "mysqld" /var/log/audit/audit.log | audit2allow -m MySQL_galera -o MySQL_galera.te

Compile these logs to a SELinux policy module.

# checkmodule -M -m MySQL_galera.te -o MySQL_galera.mod
checkmodule:  loading policy configuration from galera.te
checkmodule:  policy configuration loaded
checkmodule:  writing binary representation (version 19) to MySQL_galera.mod

Create a package of compiled policy module.

# semodule_package -m MySQL_galera.mod -o MySQL_galera.pp

Import this policy into SELinux.

# semodule -i MySQL_galera.pp

Set SELinux to run in enforcing mode.

# setenforce 1

Test SELinux is working fine by restart MariaDB service on each node.

Finally, enable the MariaDB service on all nodes.

# systemctl enable mariadb.service

We have successfully configured a MariaDB Galera Cluster on CentOS 7. Although we have configured a two node cluster, but the same steps are good enough for configuring a MariaDB Galera cluster of larger size.

After configuring a MariaDB Galera Cluster, you should be looking next for a database proxy to perform load balancing and routing for our cluster. Therefore, it is highly recommended that you should read our next post to Setup MariaDB MaxScale on CentOS 7.

Conclusion – Setup MariaDB Galera Cluster:

In this configuration guide, you have learned, how to setup MariaDB Galera Cluster on CentOS 7 or other Redhat based Linux OS.

10 thoughts on “How to setup MariaDB Galera Cluster on CentOS 7”
  1. at restart all nodes, all nodes sendme this error. While not restart this problem not appear

    ● mariadb.service – MariaDB 10.3.13 database server
    Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
    Drop-In: /etc/systemd/system/mariadb.service.d
    Active: failed (Result: exit-code) since dom 2019-02-24 23:35:16 CST; 1min 14s ago
    Docs: man:mysqld(8)
    Process: 7308 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION (code=exited, status=1/FAILURE)
    Process: 7134 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= || VAR=`/usr/bin/galera_recovery`; [ $? -eq 0 ] && systemctl set-environment _WSREP_START_POSITION=$VAR || exit 1 (code=exited, status=0/SUCCESS)
    Process: 7120 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Main PID: 7308 (code=exited, status=1/FAILURE)
    Status: "MariaDB server is down"

    feb 24 23:35:15 dbs01 mysqld[7308]: at gcomm/src/pc.cpp:connect():158
    feb 24 23:35:15 dbs01 mysqld[7308]: 2019-02-24 23:35:15 0 [ERROR] WSREP: gcs/src/gcs_core.cpp:gcs_core_open():209: Failed to open backend connection: -110 (Connection timed out)
    feb 24 23:35:15 dbs01 mysqld[7308]: 2019-02-24 23:35:15 0 [ERROR] WSREP: gcs/src/gcs.cpp:gcs_open():1458: Failed to open channel 'my_wsrep_cluster' at 'gcomm://dbs01,dbs02,dbs03': -110 (Connection timed out)
    feb 24 23:35:15 dbs01 mysqld[7308]: 2019-02-24 23:35:15 0 [ERROR] WSREP: gcs connect failed: Connection timed out
    feb 24 23:35:15 dbs01 mysqld[7308]: 2019-02-24 23:35:15 0 [ERROR] WSREP: wsrep::connect(gcomm://dbs01,dbs02,dbs03) failed: 7
    feb 24 23:35:15 dbs01 mysqld[7308]: 2019-02-24 23:35:15 0 [ERROR] Aborting
    feb 24 23:35:16 dbs01 systemd[1]: mariadb.service: main process exited, code=exited, status=1/FAILURE
    feb 24 23:35:16 dbs01 systemd[1]: Failed to start MariaDB 10.3.13 database server.
    feb 24 23:35:16 dbs01 systemd[1]: Unit mariadb.service entered failed state.
    feb 24 23:35:16 dbs01 systemd[1]: mariadb.service failed.

  2. Go to the node that was shutdown in the last during last clean shutdown.
    Then start that node using galera_new_cluster
    Start the remaining nodes using systemctl start mariadb.

    Hopefully this will resolve your problem.
    Please let us know about the result.

  3. Never mind , I was able to get past that step, but the cluster will not start.
    I do not get any errors when I run

    root@db-mmr101:/var/lib/mysql$ /usr/bin/mysqld_safe –wsrep-new-cluster
    190709 15:01:24 mysqld_safe Logging to '/var/lib/mysql/db-mmr101.err'.
    190709 15:01:25 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

    Or start the mariadb service. Nothing in the error logs as well?

    90709 15:01:30 mysqld_safe mysqld from pid file /var/lib/mysql/ ended
    190709 15:01:38 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
    190709 15:01:38 [Note] /usr/libexec/mysqld (mysqld 5.5.60-MariaDB) starting as process 19920 …
    190709 15:01:38 InnoDB: The InnoDB memory heap is disabled
    190709 15:01:38 InnoDB: Mutexes and rw_locks use GCC atomic builtins
    190709 15:01:38 InnoDB: Compressed tables use zlib 1.2.7
    190709 15:01:38 InnoDB: Using Linux native AIO
    190709 15:01:38 InnoDB: Initializing buffer pool, size = 128.0M
    190709 15:01:38 InnoDB: Completed initialization of buffer pool
    190709 15:01:38 InnoDB: highest supported file format is Barracuda.
    190709 15:01:38 InnoDB: Waiting for the background threads to start
    190709 15:01:39 Percona XtraDB ( 5.5.59-MariaDB-38.11 started; log sequence number 1597945
    190709 15:01:39 [Note] Plugin 'FEEDBACK' is disabled.
    190709 15:01:39 [Note] Server socket created on IP: ''.
    190709 15:01:39 [Note] Event Scheduler: Loaded 0 events
    190709 15:01:39 [Note] /usr/libexec/mysqld: ready for connections.
    Version: '5.5.60-MariaDB' socket: '/var/lib/mysql/mysql.sock' port: 3306 MariaDB Server

    MariaDB [(none)]> SHOW STATUS LIKE 'wsrep%';
    Empty set (0.00 sec)

  4. i get this error
    [root@ip-172-31-87-6 centos]# galera_new_cluster
    Job for mariadb.service failed because the control process exited with error code. See "systemctl status mariadb.service" and "journalctl -xe" for details.

  5. The provided error is too generic and isn't enough for troubleshoot the problem.
    Please look into the mariadb.service log using journalctl command.

Leave a Reply

Your email address will not be published. Required fields are marked *