How to Install Galera on CentOS 7
Galera is a shortened name for Galera Cluster, which is a multi-master database cluster that provides synchronous replication for MySQL or MariaDB. With Galera in use, the read and write requests can be directed to different nodes based on need; this allows a node to be compromised or lost without experiencing an interruption in normal operation. Galera provides improvements for high levels of availability in MySQL and MariaDB; Galera manages to offer robust data integrity and performance in ways that previous solutions have failed to accomplish.
Getting Started
To get started installing Galera on CentOS 7, you will need to have three nodes that already have Linux CentOS 7 installed, up to date, and running with root access. The nodes you choose can be on a cloud server or a dedicated server, whichever you prefer.
How to Install Galera on CentOS 7
Mentioned previously, the first thing to do is to ensure that you have root access to your node and the CentOS 7 operating system.
First, you will need to disable SELinux on each of the three CentOS 7 nodes you have running:
Local IP :
node1 : 10.0.0.7
node2 : 10.0.0.8
node3 : 10.0.0.9
Once the nodes have SELinux disabled, it’s time to create the MariaDB repository to install Galera on each of the three nodes:
nano /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
After the repository has been created, it’s time to install Galera and any software requirements on each of the three nodes:
yum install MariaDB-Galera-server MariaDB-client rsync galera socat -y
Now you can start MySQL and secure MySQL on each node:
systemctl start mysql
mysql_secure_installation
systemctl stop mysql
When MySQL is secured, you can add the Galera configuration to each node:
nano /etc/my.cnf.d/server.cnf
[mariadb-10.0]
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
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.0.0.7,10.0.0.8,10.0.0.9"
wsrep_cluster_name='galera_cluster'
wsrep_node_address='10.0.0.7'
wsrep_node_name='node1'
wsrep_sst_method=rsync
wsrep_sst_auth=db_user:admin
There are changes that need to be made to the second and third node.
The change to node 2:
wsrep_node_address='10.0.0.8'
wsrep_node_name='node2'
The change to node 3:
wsrep_node_address='10.0.0.9'
wsrep_node_name='node3'
After completing the changes, start the cluster on node 1 only:
/etc/init.d/mysql start --wsrep-new-cluster
When complete, it’s time to log into MySQL on each node to verify the cluster is functioning correctly:
systemctl start mysql
Now you can create a database to test the cluster on node 1:
mysql -u root -p
MariaDB [(none)]> show status like 'wsrep%';
| wsrep_local_state_comment | Synced |
| wsrep_incoming_addresses | 10.0.0.7:3306,10.0.0.8:3306,10.0.0.9:3306 |
| wsrep_cluster_size | 3 |
It’s time to log into node 2 and node 3, checking if the database created in node 1 exists:
MariaDB [(none)]> create database globotech;
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| globotech |
| information_schema |
| mysql |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)
Conclusion
Congratulations, you’ve successfully completed the installation of Galera on your nodes running CentOS 7. Now you can move your database cluster into production. If you found this tutorial helpful, please share it with other users setting up Galera on CentOS as well.