Andrew Mercer
on this page

Galera Cluster: Bare Metal Deployment

Traditional install on CentOS/RHEL-family hosts, managed via systemd. Reference: Getting Started with MariaDB Galera Cluster. See Overview for the concepts referenced below.

Ansible Role

If rolling this out to more than one environment, wrap the steps below in a role rather than running them by hand:

ansible-playbook -i ~/cluster_hosts --become --extra-vars="target=cluster" ~/ansible/galera.yml

1. Install the MariaDB Repository

# /etc/yum.repos.d/mariadb.repo

# MariaDB 10.2 CentOS repository list - created 2017-07-13 23:37 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.2/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

Adjust the version/baseurl to whatever release you're targeting — this pin is old and shown for format reference.

2. Install MariaDB Packages

sudo yum -y install MariaDB-server MariaDB-client

3. Firewall Configuration

Open the four Galera-relevant ports (see Overview for what each is for):

firewall-cmd --permanent --zone=public --add-port=4567/tcp
firewall-cmd --permanent --zone=public --add-port=4568/tcp
firewall-cmd --permanent --zone=public --add-port=4444/tcp
firewall-cmd --permanent --zone=public --add-port=3306/tcp
firewall-cmd --complete-reload

4. SELinux Configuration

semanage port -a -t mysqld_port_t -p tcp 4567
semanage port -a -t mysqld_port_t -p tcp 4568
semanage port -a -t mysqld_port_t -p tcp 4444
semanage permissive -a mysqld_t

SELinux denials on the recovery temp file are common enough to have their own entry in Troubleshooting.

5. Configure the Galera Cluster

Install this file on all three instances, adjusting wsrep_node_address and wsrep_node_name per host:

# /etc/my.cnf.d/galera.cnf

[galera]

wsrep_on=ON
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_name="[ cluster_name ]"
wsrep_cluster_address="gcomm://x.x.x.x,x.x.x.x,x.x.x.x"
wsrep_sst_method=rsync
wsrep_node_address="[ local_ip ]"
wsrep_node_name="[ local_hostname ]"
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
# Optional settings
#wsrep_slave_threads=1
#innodb_flush_log_at_trx_commit=0

# this is only for embedded server

6. Stop MariaDB on All Three Instances First

sudo systemctl stop mariadb
sudo systemctl status mariadb

Confirm it's actually stopped on every node before proceeding — starting a bootstrap against a node that still has a live mysqld running underneath is a common source of confusing failures.

7. Bring Up the First Node

sudo galera_new_cluster
sudo systemctl status mariadb
mysql -u root -p -e "SHOW STATUS LIKE 'wsrep_cluster_size'"
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| wsrep_cluster_size | 1     |
+--------------------+-------+

galera_new_cluster is the systemd-integrated equivalent of starting a container with GALERA_NEW_CLUSTER=1 — it sets wsrep_new_cluster for this start only, so unlike the Docker config file there's no manual "undo the bootstrap flag" step afterward.

8. Bring Up the Second Node

sudo systemctl start mariadb
mysql -e "SHOW STATUS LIKE 'wsrep_cluster_size'"
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| wsrep_cluster_size | 2     |
+--------------------+-------+

9. Bring Up the Third Node

sudo systemctl start mariadb
mysql -e "SHOW STATUS LIKE 'wsrep_cluster_size'"
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| wsrep_cluster_size | 3     |
+--------------------+-------+

Next Steps