How To Create a Galera Cluster with MariaDB 10.2 on CentOS Servers

How To Create a Galera Cluster with MariaDB 10.2 on CentOS Servers

1) Install MariaDB 10.2 on Each Node:

First of all you need to install MariaDB 10.2 on each of the node.  Follow below instructions

i)- Check the Linux Version:

Check the Linux version by using below command before we download MariaDB.
# cat /etc/redhat-release

 ii)- Create or Edit MariaDB.repo :

Create MariaDB.repo file in /etc/yum.repos.d/
# vi /etc/yum.repos.d/MariaDB.repo
name = MariaDB
baseurl =
Save the file by :wq!

iii) Install MariaDB Server and MariaDB Client

# sudo yum install MariaDB-server MariaDB-client

iv) Start MariaDB Service

# sudo systemctl start mysql

v) Run Secure Installation

Run the secure installation by using below statment to configure root password and other features.
# sudo mysql_secure_installation

vi) Log in to MariaDB by using Root

# mysql -uroot -p

vii) Stop MariaDB Service 

# sudo service mysql stop

2) Disable Firewall or Open required ports

You can disable the firewall for now  and enable it later and open the required ports or You can open the required ports.
i) if you decieded to total disable firewall for now , use below statement
# systemctl stop firewalld
# systemctl disable firewalld

ii) If you have decieded to keep the firewall enabled , then you have to run belos commands to open required ports
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --zone=public --add-port=4567/tcp --permanent
firewall-cmd --zone=public --add-port=4568/tcp --permanent
firewall-cmd --zone=public --add-port=4444/tcp --permanent

3) Disable SELINUX  on all Nodes

SELINUX prevents Galera cluster from starting. Disable it by using below commands.
# sed -i.bak 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
# setenforce 0

4) Make changes to /etc/my.cnf.d/server.cnf file

On each node you have to make changes to /etc/my.cnf.d/server.cnf file. Overwrite the file with below text. 
wsrep_cluster_address = Provide the list of IPs of all nodes such as,
wsrep_node_address= Provide the IP of current node where you are making changes to server.cnf
wsrep_node_incoming_address=  Provide the IP of current node where you are making changes to server.cnf
# Mandatory settings
first Node IP,2nd Node IP,...
wsrep_node_address=This Node IP
wsrep_node_incoming_address=This Node IP
# wsrep_sst_donor =


# Allow server to accept connections on all interfaces.
# Optional setting

# this is only for embedded server

# This group is only read by MariaDB servers, not by MySQL.
# If you use the same .cnf file for MySQL and MariaDB,
# you can put MariaDB-only options here

5) Start Service on First Node:

To start the mariadb service on first Node, you will be using below command. Don't use systemctl start mysql or service mysql start
#sudo galera_new_cluster

Service should start successfully. Once the mariadb service is started on first node, you can change the cluster information by connecting to mariadb.
# mysql -uroot -p

provide the password and you will be connected to MaraiaDB prompt. Run below statement.
 MariaDB > show status like '%wsrep_cluster_size%';

you should see the output as shown below.
| Variable_name      | Value |
| wsrep_cluster_size | 1     |

6) Join 2nd and More Nodes
You are all set to join other nodes to Galera Cluster. Connect to second node and then start MariaDB service by using below statment.

# sudo service mysql start 

Repeat this on all the nodes. Once the MariaDB service is started on all the Nodes, you can check Galera cluster size again to make sure all the nodes are part of cluster by running below statment.
# mysql -u root -p -e "SHOW STATUS LIKE 'wsrep_cluster_size'"

You should see the Value= Total Nodes in cluster. Check out our video demo to see how I have created the MariaDB Galera Cluster by using all above steps.