How to Install MariaDB Galera Cluster: Step-by-Step Guide
The MariaDB Galera Cluster offers a reliable solution for achieving database high availability and synchronous replication. It is commonly used in production environments where fault tolerance and data consistency matter. This tutorial walks you through setting up a basic MariaDB Galera Cluster on Linux servers.
Prerequisites
- Three or more Linux servers (Ubuntu, CentOS, or similar) with static IPs.
- Root or sudo access on all servers.
- Basic knowledge of MariaDB/MySQL and Linux commands.
- Open ports: 3306 (MariaDB), 4567 (Galera Cluster replication), 4568 (IST), 4444 (SST).
- Firewall configured to allow above ports on all nodes.
Step 1: Setting Hostnames and Host File
Ensure all nodes can resolve each other’s hostnames. On each node, edit /etc/hosts to include:
192.168.1.101 node1 192.168.1.102 node2 192.168.1.103 node3
Replace IPs and hostnames with your server details.
Step 2: Install MariaDB with Galera Plugin
MariaDB versions 10.1 and above include Galera. Follow specific instructions depending on your Linux distribution.
For example, on Ubuntu:
sudo apt update
sudo apt install mariadb-server galera-4
On CentOS:
sudo yum install mariadb mariadb-server galera
Step 3: Configure MariaDB for Galera
Edit /etc/mysql/my.cnf or /etc/my.cnf.d/galera.cnf, add or modify the following:
[mysqld] # Galera settings wsrep_on=ON wsrep_provider=/usr/lib/galera/libgalera_smm.so wsrep_cluster_name="mariadb_galera_cluster" wsrep_cluster_address="gcomm://192.168.1.101,192.168.1.102,192.168.1.103" wsrep_node_address="192.168.1.101" # Change on each node wsrep_node_name="node1" # Change on each node wsrep_sst_method=rsync binlog_format=ROW default_storage_engine=InnoDB innodb_autoinc_lock_mode=2
Important: Change wsrep_node_address and wsrep_node_name for each node respectively.
Step 4: Initialize the Cluster
On the first node, start the cluster with bootstrap:
sudo systemctl stop mariadb
sudo galera_new_cluster
Then start MariaDB normally on the other nodes:
sudo systemctl start mariadb
Step 5: Verify Cluster Status
Log into MariaDB on each node:
mysql -u root -p
Run:
SHOW STATUS LIKE 'wsrep_cluster_size';
The output should reflect the total number of nodes in the cluster.
Step 6: Test Data Replication
- Create a test database and insert data on one node.
- Verify the data appears instantly on all other nodes.
Troubleshooting Tips
- Cluster does not start: Ensure the
wsrep_cluster_addressis correctly set and firewall ports are open. - Nodes do not join cluster: Check network connectivity and matching Galera versions.
- SST fails: Confirm
rsyncis installed as it’s used for State Snapshot Transfer. - Check logs: MariaDB logs are usually in
/var/log/mysql/or/var/log/mariadb/.
Summary Checklist
- Static IPs and hostname resolution set on all nodes.
- MariaDB and Galera plugin installed on all servers.
- Correct Galera configuration made with unique node names and addresses.
- Cluster initialized on first node and other nodes started normally.
- Verified cluster size and tested data replication.
- Ensured firewall and SELinux (if applicable) allow necessary traffic.
For more database installation tutorials, check our <a href="/
