DEV Community

Cover image for How to Set Up a 3-Node MariaDB Galera Cluster on Bare Metal
olivia Millie for eServers

Posted on Originally published at eservers.uk

How to Set Up a 3-Node MariaDB Galera Cluster on Bare Metal

When a single database server goes down, everything built on top of it goes down too. MariaDB Galera Cluster solves this by offering synchronous multi-master replication — every node can accept reads and writes, and every transaction is certified across all nodes before committing.

Because synchronous replication relies heavily on network speed and disk throughput, running Galera on dedicated Bare Metal Servers ensures write certification stays fast and predictable.

Firewall Requirements

Galera requires 4 ports open between cluster members:

  • 3306: MariaDB client connections.
  • 4567: Galera cluster replication traffic.
  • 4568: Incremental State Transfer (IST).
  • 4444: State Snapshot Transfer (SST).
sudo ufw allow from 10.0.0.11 to any port 3306,4567,4568,4444 proto tcp
sudo ufw allow from 10.0.0.12 to any port 3306,4567,4568,4444 proto tcp
sudo ufw allow from 10.0.0.13 to any port 3306,4567,4568,4444 proto tcp


Configuration (/etc/mysql/mariadb.conf.d/60-galera.cnf)
On all three nodes, define the wsrep parameters:

Ini, TOML
[galera]
wsrep_on = ON
wsrep_provider = /usr/lib/galera/libgalera_smm.so
wsrep_cluster_name = "production_cluster"
wsrep_cluster_address = "gcomm://10.0.0.11,10.0.0.12,10.0.0.13"

binlog_format = ROW
default_storage_engine = InnoDB
innodb_autoinc_lock_mode = 2

wsrep_sst_method = rsync
wsrep_node_address = "THIS_NODE_IP"
wsrep_node_name = "node1"
Bootstrapping Node 1
On Node 1 only, initialize the new cluster:

Bash
sudo galera_new_cluster
sudo mysql -u root -e "SHOW STATUS LIKE 'wsrep_cluster_size';"
On Node 2 and Node 3, simply start MariaDB normally (sudo systemctl start mariadb), and they will automatically sync data from Node 1 via rsync.

Read the full tutorial to learn about testing multi-master writes and monitoring cluster health: https://www.eservers.uk/tutorials/howto/mariadb-galera-cluster-setup-bare-metal/


---

### 12. Hashnode (Technical Focus - Commercial Content Removed)

Enter fullscreen mode Exit fullscreen mode


markdown

Database Architecture: Deploying a 3-Node MariaDB Galera Cluster

Standalone database nodes represent a critical single point of failure (SPOF). While standard MySQL/MariaDB master-slave replication provides read scalability, its asynchronous nature introduces replication lag and potential data loss during failover events.

MariaDB Galera Cluster implements synchronous, certification-based multi-master replication. Transactions written to any node are synchronously broadcast and certified across all nodes using the Write Set Replication (wsrep) API before committing.

Here is the technical blueprint for deploying a 3-node Galera cluster on Ubuntu 22.04 LTS.


Infrastructure Topology

  • Node 1 (Bootstrap): 10.0.0.11
  • Node 2 (Member): 10.0.0.12
  • Node 3 (Member): 10.0.0.13

Step 1: Package Installation & Preparation

Run the following on all 3 nodes to install the database engine, Galera provider library, and rsync (used for State Snapshot Transfer):


bash
sudo apt update
sudo apt install -y mariadb-server mariadb-client galera-4 rsync
sudo systemctl stop mariadb
Step 2: Firewall Rule Definition
Galera relies on four distinct TCP ports for inter-node communication:

3306: MySQL Client Connections

4567: Cluster Replication Traffic (UDP/TCP)

4568: Incremental State Transfer (IST)

4444: State Snapshot Transfer (SST)

Apply strict UFW rules on all nodes, allowing traffic exclusively from peer cluster IPs:

Bash
sudo ufw allow from 10.0.0.11 to any port 3306,4567,4568,4444 proto tcp
sudo ufw allow from 10.0.0.12 to any port 3306,4567,4568,4444 proto tcp
sudo ufw allow from 10.0.0.13 to any port 3306,4567,4568,4444 proto tcp
sudo ufw enable
Step 3: Galera Configuration
On each server, create /etc/mysql/mariadb.conf.d/60-galera.cnf:

Ini, TOML
[galera]
wsrep_on = ON
wsrep_provider = /usr/lib/galera/libgalera_smm.so
wsrep_cluster_name = "production_cluster"
wsrep_cluster_address = "gcomm://10.0.0.11,10.0.0.12,10.0.0.13"

binlog_format = ROW
default_storage_engine = InnoDB
innodb_autoinc_lock_mode = 2

wsrep_sst_method = rsync
wsrep_node_address = "THIS_NODE_IP"
wsrep_node_name = "node1"
(Replace THIS_NODE_IP and wsrep_node_name appropriately per server).

Step 4: Cluster Initialisation (Bootstrapping)
Initialize the cluster from Node 1 only:

Bash
sudo galera_new_cluster
Verify cluster status on Node 1:

Bash
sudo mysql -u root -e "SHOW STATUS LIKE 'wsrep_cluster_size';"
# Output: wsrep_cluster_size | 1
Join Node 2 and Node 3 by starting their MariaDB services normally:

Bash
sudo systemctl start mariadb
Re-query wsrep_cluster_size on any node. The value must equal 3.

Step 5: Health Verification
Monitor cluster health via MySQL CLI:

SQL
SHOW STATUS LIKE 'wsrep_cluster_status';      -- Must return 'Primary'
SHOW STATUS LIKE 'wsrep_ready';               -- Must return 'ON'
SHOW STATUS LIKE 'wsrep_local_state_comment';-- Must return 'Synced'
Enter fullscreen mode Exit fullscreen mode

Top comments (0)