A Galera Cluster is a multi-master database solution using either MySQL or MariaDB databases.
This document will focus on using MariaDB (in most cases, MariaDB is a straight drop-in replacement for MySQL) due to the fact that it supports Galera out-of-the-box without extra extensions or patches (only true for versions 10.1 and above).
Note: Cluster sizes should be odd numbers to avoid split-brain situations. For even-numbered cluster sizes, you’ll need an arbitrator (non-database member of cluster) to participate in the voting.
MariaDB should be available in package managers, see link below to add repo to fetch specific versions.
[[https://downloads.mariadb.org/mariadb/repositories/ | Installing MariaDB from Linux repo]]
NOTE: When you get prompted to set a new password, don’t enter anything new, just press enter to continue, which should keep the old MySQL root password
If MySQL already exists on the system, MariaDB will remove it and replace it with itself. All shell commands to “mysql” will effectively be commands to MariaDB, so no need to change any existing scripts. All software client libraries for MySQL should also still work with MariaDB.
Galera 3 is included in all installations of MariaDB since version 10.1. Enabling it simply involves some extra configuration options.
cd
to the /etc/mysql/conf.d
directorygalera.cnf
[mysqld]
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
# Galera Provider Configuration
wsrep_on=ON
wsrep_provider="/usr/lib/galera/libgalera_smm.so"
# Galera Cluster Configuration
wsrep_cluster_name="galera cluster name"
wsrep_cluster_address="gcomm://192.168.0.10,192.168.0.20,192.168.0.30?pc.wait_prim=no"
# Galera Synchronization Configuration
wsrep_sst_method=rsync
wsrep_sst_receive_address="192.168.0.10:4444"
# Galera Node Configuration
wsrep_node_address="192.168.0.10:4567"
wsrep_node_incoming_address="192.168.0.10:3306"
wsrep_node_name="Node-1"
# If behind a NAT, uncomment the line below and specify the private address
#wsrep_provider_options="ist.recv_bind=172.17.0.2"
wsrep_debug=1
wsrep_sst_receive_address
has default port 4444wsrep_node_address
has default port 4567wsrep_node_incoming_address
has default port 3306wsrep_cluster_name
parameter must be the same in all nodes, otherwise a joining node with a different name will fail to startservice mysql start %%--%%wsrep-new-cluster
service mysql start
mysql -uroot -p -e "SHOW STATUS LIKE 'wsrep%';"
You may encounter the following message when using Linux service
to start/stop/restart or check the status of the database:
ERROR 1045 (28000): Access denied for user 'debian-sys-maint'@'localhost' (using password: YES)
This message indicates that the maintenance user’s password stored in /etc/mysql/debian.cnf
is out of sync with the password in the database itself. If you just added your database as a new node of a replicated cluster, then this is expected behaviour, as the password from the original bootstrap node has now been replicated and replaced your original maintenance password. To fix this, find the bootstrap node (or any node where you don’t see the error message when querying the database status), and copy the password from /etc/mysql/debian.cnf
from that node to the current node.
If your database is not part of a cluster, then you need to update the password in the database by doing the following:
cat /etc/mysql/debian.cnf | grep -i password
mysql -uroot -p
SET PASSWORD FOR 'debian-sys-maint'@'localhost' = PASSWORD('**PASSWORD-FROM-STEP-1**');
sudo service mysql restart
Getting Started with MariaDB Galera Cluster
Resetting quorum within the cluster
Galera firewall settings (ports to open)