How to install MariaDB Cluster in CentOS
In this tutorial, we will explain How to install MariaDB Cluster in CentOS.
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 (although there is experimental support for MyISAM – see the wsrep_replicate_myisam system variable). 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.
Prerequisites
You will need:
- VPS running CentOS
Step 1 – Add MariaDB repos
To add MariaDB repositories, open file /etc/yum.repos.d/mariadb.repo.
nano /etc/yum.repos.d/mariadb.repo
Now add lines below to mariadb.repo:
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.2.9/centos7-amd64/
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
Save and close by entering Ctrl+X+y.
Step 2 – Install MariaDB
Now MariaDB is ready to install. Run this command to install:
yum install mariadb-server mariadb-client galera rsync
To start MariaDB, run this command:
systemctl start mariadb
Run MySQL secure installation:
mysql_secure_installation
Enter for none because you don’t have current password.
If you want to set root password enter Y if you don’t want enter n.
To stop MariaDB, use this command:
systemctl stop mariadb
Step 3 – Configuration
Edit server.cnf following this command:
nano /etc/my.cnf.d/server.cnf
And add lines to that file.
[galera]
wsrep_on=ON
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
#add your node ips here
wsrep_cluster_address=”gcomm://192.168.0.11,192.168.0.12,192.168.0.13″
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
#Cluster name
wsrep_cluster_name=”clustername”
# Allow server to accept connections on all interfaces.
bind-address=0.0.0.0
# this server ip, change for each server
wsrep_node_address=”192.168.0.11″
# this server name, change for each server
wsrep_node_name=”node1″
wsrep_sst_method=rsync
Save and close it.
If you want to add other servers use this lines.
wsrep_node_address=”192.168.0.12″
wsrep_node_name=”node2″
After add service and ports to firewall:
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
firewall-cmd –zone=public –add-port=4567/udp –permanent
If firewall-cmd command is not working install firewalld :
yum install firewalld
And start firewalld
systemctl start firewalld
Step 4 – Testing
Now start node and MariaDB:
galera_new_cluster
systemctl start mariadb
And use this command to check status
mysql -u root -p -e “show status like ‘wsrep_cluster_size’;
You have successfully installed MariaDB Cluster in CentOS.
Enjoy it.