Shared MariaDB 11.8 Galera Cluster Setup
All backend pods and edge proxy nodes in a multi-node hermEX deployment read and write shared directory metadata, server registries, ACME TLS certificates, centralized logs, and the outbound relay spool (SELECT ... FOR UPDATE SKIP LOCKED) in MariaDB 11.8. This guide configures a fault-tolerant 3-node MariaDB 11.8 Galera Cluster behind a virtual IP (10.0.0.5:3306) using either HAProxy + Keepalived or MariaDB MaxScale + Keepalived.
For how hermEX pods connect to this cluster, see Multi-Node Cluster Installation or Single-to-Multi Migration.
1. Topology and Node Layout
Never run a production Galera cluster with two database nodes alone. A 2-node cluster loses quorum if either node stops. Always deploy three database nodes (or two database nodes plus one garbd arbitrator node) on your private cluster network:
| Node | Role | Private IP | Purpose |
|---|---|---|---|
db-1 | MariaDB 11.8 + Galera | 10.0.0.21 | Database node 1 (wsrep_cluster member) |
db-2 | MariaDB 11.8 + Galera | 10.0.0.22 | Database node 2 (wsrep_cluster member) |
db-3 | MariaDB 11.8 + Galera | 10.0.0.23 | Database node 3 (wsrep_cluster member) |
db-vip | SQL VIP (haproxy or maxscale + keepalived) | 10.0.0.5:3306 | Single database_dsn endpoint used by all hermEX pods |
Bind MariaDB and VIP listeners only on private cluster IPs (10.0.0.0/24). Allow Galera replication ports (4567, 4568, 4444) strictly between db-1, db-2, and db-3, and allow SQL port 3306 strictly from your hermEX pods and database proxy nodes.
2. Firewall Ports and MariaDB 11.8 Installation
Run the commands below on all three database nodes (db-1, db-2, db-3).
Open Private Cluster Ports
| Port / Protocol | Service | Source Allowed |
|---|---|---|
3306/tcp | MariaDB client connections | hermEX pods + db-vip proxies (10.0.0.0/24) |
4567/tcp, 4567/udp | Galera group communication | db-1, db-2, db-3 only |
4568/tcp | Galera Incremental State Transfer (IST) | db-1, db-2, db-3 only |
4444/tcp | Galera State Snapshot Transfer (SST via mariabackup) | db-1, db-2, db-3 only |
protocol 112 (VRRP) | Keepalived failover heartbeats (if colocated) | db-1, db-2, db-3 / LB nodes only |
Example with firewalld (RHEL/AlmaLinux/Rocky 9) or ufw (Debian/Ubuntu):
# RHEL / AlmaLinux / Rocky 9 (firewalld)
sudo firewall-cmd --permanent --new-zone=hermex-db
sudo firewall-cmd --permanent --zone=hermex-db --add-source=10.0.0.0/24
for p in 3306/tcp 4567/tcp 4567/udp 4568/tcp 4444/tcp; do
sudo firewall-cmd --permanent --zone=hermex-db --add-port="$p"
done
sudo firewall-cmd --permanent --zone=hermex-db --add-rich-rule='rule protocol value="vrrp" accept'
sudo firewall-cmd --reload
# Debian / Ubuntu (ufw)
sudo ufw allow from 10.0.0.0/24 to any port 3306 proto tcp
for p in 4567/tcp 4567/udp 4568/tcp 4444/tcp; do
sudo ufw allow from 10.0.0.0/24 to any port "${p%/*}" proto "${p#*/}"
done
Install MariaDB 11.8 Server and mariabackup
On RHEL 9 / AlmaLinux 9 / Rocky 9:
curl -LsS https://r.mariadb.com/downloads/mariadb_repo_setup | sudo bash -s -- --mariadb-server-version="mariadb-11.8"
sudo dnf -y install MariaDB-server MariaDB-client MariaDB-backup galera-4 rsync socat
On Debian 12 / Ubuntu 22.04 LTS / Ubuntu 24.04 LTS:
sudo apt-get update
sudo apt-get install -y curl apt-transport-https ca-certificates
curl -LsS https://r.mariadb.com/downloads/mariadb_repo_setup | sudo bash -s -- --mariadb-server-version="mariadb-11.8"
sudo apt-get install -y mariadb-server mariadb-client mariadb-backup galera-4 rsync socat
Ensure time synchronization is active on every node:
sudo systemctl enable --now chronyd || sudo systemctl enable --now systemd-timesyncd
3. Configure Galera Cluster on Each Node
Stop MariaDB before writing the cluster configuration:
sudo systemctl stop mariadb
On RHEL-family systems, place the configuration in /etc/my.cnf.d/60-galera.cnf. On Debian/Ubuntu, place it in /etc/mysql/mariadb.conf.d/60-galera.cnf.
Replace THIS_NODE_IP and THIS_NODE_NAME on each host (10.0.0.21 / db-1, 10.0.0.22 / db-2, 10.0.0.23 / db-3), and replace REPLACE_SST_PASSWORD:
[mysqld]
# Network and character set
bind-address = 0.0.0.0
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
skip-name-resolve = ON
max_connections = 1000
max_allowed_packet = 128M
# InnoDB tuning for hermEX directory, relay spool, and logs
default_storage_engine = InnoDB
innodb_buffer_pool_size = 2G
innodb_log_file_size = 512M
innodb_flush_log_at_trx_commit = 1
innodb_doublewrite = 1
innodb_autoinc_lock_mode = 2
binlog_format = ROW
# Galera cluster settings
wsrep_on = ON
wsrep_provider = /usr/lib64/galera-4/libgalera_smm.so
wsrep_cluster_name = "hermex_galera"
wsrep_cluster_address = "gcomm://10.0.0.21,10.0.0.22,10.0.0.23"
wsrep_node_address = "THIS_NODE_IP"
wsrep_node_name = "THIS_NODE_NAME"
# State Snapshot Transfer using non-blocking mariabackup
wsrep_sst_method = mariabackup
wsrep_sst_auth = "sstuser:REPLACE_SST_PASSWORD"
# Increase flow-control tolerance for relay bursts and system_logs
wsrep_provider_options = "gcs.fc_limit=64;gcache.size=1G"
wsrep_provider library path by OSOn RHEL/AlmaLinux/Rocky 9, Galera installs to /usr/lib64/galera-4/libgalera_smm.so or /usr/lib64/galera/libgalera_smm.so. On Debian 12 and Ubuntu, it installs to /usr/lib/galera/libgalera_smm.so. Check with ls /usr/lib*/galera*/libgalera_smm.so and set wsrep_provider to the exact path present on your servers.
4. Bootstrap the Cluster and Create Databases
- Initialize the primary component only on
db-1(10.0.0.21):Wait untilsudo galera_new_clusterdb-1starts, then connect locally and create the SST user, hermEX cluster account, andemaildatabase (plus optionalemail_relayif you isolate outbound spool I/O):sudo mariadb <<'EOF'CREATE DATABASE IF NOT EXISTS emailCHARACTER SET utf8mb4COLLATE utf8mb4_unicode_ci;CREATE DATABASE IF NOT EXISTS email_relayCHARACTER SET utf8mb4COLLATE utf8mb4_unicode_ci;CREATE USER IF NOT EXISTS 'sstuser'@'localhost' IDENTIFIED BY 'REPLACE_SST_PASSWORD';CREATE USER IF NOT EXISTS 'sstuser'@'10.0.0.%' IDENTIFIED BY 'REPLACE_SST_PASSWORD';GRANT RELOAD, PROCESS, LOCK TABLES, BINLOG MONITOR, REPLICATION CLIENT ON *.* TO 'sstuser'@'localhost';GRANT RELOAD, PROCESS, LOCK TABLES, BINLOG MONITOR, REPLICATION CLIENT ON *.* TO 'sstuser'@'10.0.0.%';CREATE USER IF NOT EXISTS 'hermex'@'10.0.0.%' IDENTIFIED BY 'REPLACE_STRONG_DB_PASSWORD';GRANT ALL PRIVILEGES ON email.* TO 'hermex'@'10.0.0.%';GRANT ALL PRIVILEGES ON email_relay.* TO 'hermex'@'10.0.0.%';FLUSH PRIVILEGES;EOF - Start MariaDB on
db-2and then ondb-3so each node joins via SST and replicates theemailschema and users:# On db-2, wait until ready, then run on db-3sudo systemctl enable --now mariadb - Enable the
mariadbservice ondb-1as well (sudo systemctl enable mariadb) and verify cluster membership from any node:Confirmsudo mariadb -e "SHOW GLOBAL STATUS WHERE Variable_name IN ('wsrep_cluster_size','wsrep_cluster_status','wsrep_local_state_comment','wsrep_ready');"wsrep_cluster_size = 3,wsrep_cluster_status = Primary,wsrep_local_state_comment = Synced, andwsrep_ready = ON.
5. Expose the Single SQL VIP (10.0.0.5:3306)
Point every hermEX pod to a floating VIP (10.0.0.5:3306) rather than hardcoding a single database node IP. Choose Option A (HAProxy + Keepalived) or Option B (MariaDB MaxScale + Keepalived). Both options route active SQL writes to one primary node at a time to eliminate Galera certification deadlocks on concurrent SELECT ... FOR UPDATE SKIP LOCKED relay workers and schema locks.
Run the SQL proxy + Keepalived pair on two dedicated lightweight load balancers (lb-1 at 10.0.0.6 and lb-2 at 10.0.0.7), or colocate them on db-1 and db-2.
Allow binding to the floating VIP on both proxy hosts:
echo 'net.ipv4.ip_nonlocal_bind = 1' | sudo tee /etc/sysctl.d/90-vip-bind.conf
sudo sysctl -p /etc/sysctl.d/90-vip-bind.conf
Option A: HAProxy + Keepalived
- Install HAProxy and Keepalived on both proxy hosts:
# RHEL-familysudo dnf -y install haproxy keepalived# Debian / Ubuntusudo apt-get install -y haproxy keepalived
- Create a dedicated unauthenticated health-check user inside MariaDB (accessible only from your proxy hosts, or use
portchecks as shown below without extra users):CREATE USER IF NOT EXISTS 'haproxy_check'@'10.0.0.%';FLUSH PRIVILEGES; - Write
/etc/haproxy/haproxy.cfgon both proxy hosts. Noticedb-2anddb-3carrybackupso all active SQL writes hit one healthy primary (db-1) and automatically fail over cleanly ifdb-1goes down:globallog /dev/log local0user haproxygroup haproxydaemonmaxconn 4096defaultslog globalmode tcpoption tcplogoption dontlognullretries 3timeout connect 5stimeout client 10mtimeout server 10mtimeout check 3sfrontend mariadb_inbind 10.0.0.5:3306default_backend mariadb_galerabackend mariadb_galeramode tcpbalance firstoption mysql-check user haproxy_checkdefault-server inter 2s fall 3 rise 2 on-marked-down shutdown-sessionsserver db-1 10.0.0.21:3306 checkserver db-2 10.0.0.22:3306 check backupserver db-3 10.0.0.23:3306 check backup - Enable and start HAProxy:
(On SELinux systems:sudo haproxy -c -f /etc/haproxy/haproxy.cfgsudo systemctl enable --now haproxy
sudo setsebool -P haproxy_connect_any 1.)
Option B: MariaDB MaxScale + Keepalived
- Install MaxScale on both proxy hosts from the MariaDB repository:
# RHEL-familysudo dnf -y install maxscale keepalived# Debian / Ubuntusudo apt-get install -y maxscale keepalived
- Create the MaxScale monitor account in MariaDB (run once on
db-1):CREATE USER IF NOT EXISTS 'maxscale'@'10.0.0.%' IDENTIFIED BY 'REPLACE_MAXSCALE_PASSWORD';GRANT REPLICATION CLIENT, SUPER, RELOAD, PROCESS, SHOW DATABASES, EVENT ON *.* TO 'maxscale'@'10.0.0.%';GRANT SELECT ON mysql.* TO 'maxscale'@'10.0.0.%';FLUSH PRIVILEGES; - Write
/etc/maxscale.cnfon both proxy hosts (readconnroutewithrouter_options=masterguarantees strict single-writer routing with zero split-transaction surprises acrossdirectoryandrelay):[maxscale]threads=auto[db-1]type=serveraddress=10.0.0.21port=3306protocol=MariaDBBackend[db-2]type=serveraddress=10.0.0.22port=3306protocol=MariaDBBackend[db-3]type=serveraddress=10.0.0.23port=3306protocol=MariaDBBackend[Galera-Monitor]type=monitormodule=galeramonservers=db-1,db-2,db-3user=maxscalepassword=REPLACE_MAXSCALE_PASSWORDmonitor_interval=2000ms[hermEX-Write-Router]type=servicerouter=readconnrouterouter_options=masterservers=db-1,db-2,db-3user=maxscalepassword=REPLACE_MAXSCALE_PASSWORD[hermEX-Listener]type=listenerservice=hermEX-Write-Routerprotocol=MariaDBClientaddress=10.0.0.5port=3306 - Start MaxScale and confirm all three servers are
Synced:sudo systemctl enable --now maxscalesudo maxctrl list servers
Keepalived VRRP Configuration for 10.0.0.5
Create /usr/local/bin/check_sql_proxy.sh on both proxy hosts (adjust the process name to maxscale if using Option B):
#!/bin/bash
set -euo pipefail
pgrep -x haproxy >/dev/null
Make it executable (sudo chmod +x /usr/local/bin/check_sql_proxy.sh), and write /etc/keepalived/keepalived.conf:
On Primary Proxy (lb-1):
vrrp_script chk_sql_proxy {
script "/usr/local/bin/check_sql_proxy.sh"
interval 2
fall 2
rise 2
}
vrrp_instance VI_HERMEX_DB {
state MASTER
interface eth0
virtual_router_id 51
priority 150
advert_int 1
unicast_src_ip 10.0.0.6
unicast_peer {
10.0.0.7
}
authentication {
auth_type PASS
auth_pass REPLACE_VRRP_SECRET
}
virtual_ipaddress {
10.0.0.5/24 dev eth0
}
track_script {
chk_sql_proxy
}
}
On Backup Proxy (lb-2), set state BACKUP, priority 100, unicast_src_ip 10.0.0.7, and unicast_peer { 10.0.0.6 }, replace eth0 with your private interface name (ip -br link), and start Keepalived on both hosts:
sudo systemctl enable --now keepalived
6. Connect hermEX Pods and Verify
Set database_dsn in /etc/hermex/config.json on all hermEX pods and edge nodes (leave relay_database_dsn empty "" to share email, or point it to /email_relay):
{
"database_dsn": "hermex:REPLACE_STRONG_DB_PASSWORD@tcp(10.0.0.5:3306)/email?parseTime=true&multiStatements=true",
"relay_database_dsn": ""
}
Verify connectivity, schema initialization, and backups from Pod 0:
mariadb -h 10.0.0.5 -u hermex -p -e "SELECT VERSION(), @@wsrep_node_name;" email
sudo hermex-admin -config /etc/hermex/config.json ensure-schema
sudo hermex-admin -config /etc/hermex/config.json backup-db --output /tmp/cluster-db-test.sql.gz
If all three Galera nodes stop simultaneously, inspect /var/lib/mysql/grastate.dat on each node. Start galera_new_cluster on the node showing safe_to_bootstrap: 1 (or the highest seqno reported by sudo mariadbd --wsrep-recover if all three show 0, after setting safe_to_bootstrap: 1 on that one node only), then run systemctl start mariadb on the remaining two nodes.