Configuring a galera synchronous multi-master database cluster based on openSuSE Leap 15.6
First node
Add server:database
repository from OBS and install the necessary packages, this must be done for all the servers in
the cluster.
sudo zypper addrepo https://download.opensuse.org/repositories/server:database/openSUSE_Leap_15.0/server:database.repo
sudo zypper refresh
sudo zypper install mysql mariadb-galera galera-3
Start and securing mariadb installation
sudo systemctl start mariadb
sudo mysql_secure_installation
Once you have answered the prompt questions, you can turn off mariadb and edit the galera file configuration in
/etc/my.cnf.d/50-galera.cnf
changing this way:
# Whether or not wsrep replication is enabled
wsrep_on=ON
# Full path to wsrep provider library or 'none'
wsrep_provider=/usr/lib64/galera-3/libgalera_smm.so
# Logical cluster name. Should be the same for all nodes.
wsrep_cluster_name="my_cluster"
# Group communication system handle
wsrep_cluster_address="gcomm://"
# Human-readable node name (non-unique). Hostname by default.
wsrep_node_name="node1"
once finished editing the file, after saving it, start mariadb in this way:
sudo galera_new_cluster
Now you can log in into mariadb and verify that the cluster (with only one server enabled) is up and running:
MariaDB [(none)]> SHOW STATUS LIKE 'wsrep_cluster_size';
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| wsrep_cluster_size | 1 |
+--------------------+-------+
1 row in set (0.00 sec)
This variable tells you the number of nodes that are connected to the cluster. It’s time to open the ports on the firewall to allow other nodes to connect
sudo firewall-cmd --zone=public --add-service=mysql --permanent
sudo firewall-cmd --zone=public --add-port=3306/tcp --permanent
sudo firewall-cmd --zone=public --add-port=4567/tcp --permanent
sudo firewall-cmd --zone=public --add-port=4568/tcp --permanent
sudo firewall-cmd --zone=public --add-port=4444/tcp --permanent
sudo firewall-cmd --reload
Additional nodes
Repeat the same operations performed on node 1 until it is time to edit the /etc/my.cnf.d/50-galera.cnf
file.
# Whether or not wsrep replication is enabled
wsrep_on=ON
# Full path to wsrep provider library or 'none'
wsrep_provider=/usr/lib64/galera-3/libgalera_smm.so
# Logical cluster name. Should be the same for all nodes.
wsrep_cluster_name="my_cluster"
# Group communication system handle
wsrep_cluster_address="gcomm://<node1.ip.address>,<node2.io.address>"
# Human-readable node name (non-unique). Hostname by default.
wsrep_node_name="node2"
Set wsrep\_cluster\_address="gcomm://\<node1.ip.address\>,\<node2.ip.address\>"
with the correct ip addresses, open
firewall ports and start mariadb.
sudo firewall-cmd --zone=public --add-service=mysql --permanent
sudo firewall-cmd --zone=public --add-port=3306/tcp --permanent
sudo firewall-cmd --zone=public --add-port=4567/tcp --permanent
sudo firewall-cmd --zone=public --add-port=4568/tcp --permanent
sudo firewall-cmd --zone=public --add-port=4444/tcp --permanent
sudo firewall-cmd --reload
sudo systemctl start mariadb
You can check the entry of node2 in the cluster in the same way as before:
MariaDB [(none)]> SHOW STATUS LIKE 'wsrep_cluster_size';
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| wsrep_cluster_size | 2 |
+--------------------+-------+
1 row in set (0.00 sec)
Once the nodes are synchronized it is necessary to go back to the node1 to edit
wsrep\_cluster\_address="gcomm://\<node1.ip.address\>,\<node2.ip.address\>"
with the correct ip addresses.
Repeat the operations performed on node2 to add additional nodes.