User Tools

Site Tools


linux:ubuntu_mariadb_galera_cluster_install_add_nodes

Ubuntu MariaDB Galera Cluster Install

In this guide we will add two nodes node 4 and 5 to an existing Galera Cluster consisting of 3 nodes as shown here.

And end up with a cluster consisting of 5 nodes as shown here.

Prerequisites

We will be adding two more nodes (node 4 and 5) simultaneously and a little preparation is needed on the existing Galera cluster.

On The Existing Cluster

On every node on the existing cluster add the new ip addresses of the new nodes we are adding.

vi /etc/mysql/conf.d/galera.cnf

Add the ips so the lhe line looks like this.

wsrep_cluster_address = "gcomm://node1_ip,node2_ip,node3_ip,node4_ip,node5_ip"

And then restart mariadb on all nodes on the existing cluster in order for the changes to take effect.

On The New Nodes

On the new nodes (node 4 and 5) that we are adding run the following using sudo or root.

apt update
apt install -y mariadb-server mariadb-client
systemctl start mariadb.service
systemctl enable mariadb.service
mysql_secure_installation

Apply the following when running mysql_secure_installation

Enter current password for root (enter for none): press enter
Switch to unix_socket authentication [Y/n]        press n
Change the root password? [Y/n]                   press y
New password:                                     enter new root password
Re-enter new password:                            enter new root password again
Remove anonymous users?                           press y
Disallow root login remotely?                     press y
Remove test database and access to it?            press y
Reload privilege tables now?                      press y

Configuring the new nodes

On node 4

vi /etc/mysql/conf.d/galera.cnf

Add the following lines.

[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"
wsrep_cluster_address = "gcomm://node1_ip,node2_ip,node3_ip,node4_ip,node5_ip"

# Galera Synchronization Configuration
wsrep_sst_method = rsync

# Galera Node Configuration
wsrep_node_address = "node4_ip"
wsrep_node_name = "node4"

wsrep_sst_donor = "node3"

On node 5

vi /etc/mysql/conf.d/galera.cnf

Add the following lines.

[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"
wsrep_cluster_address = "gcomm://node1_ip,node2_ip,node3_ip,node4_ip,node5_ip"

# Galera Synchronization Configuration
wsrep_sst_method = rsync

# Galera Node Configuration
wsrep_node_address = "node5_ip"
wsrep_node_name = "node5"

wsrep_sst_donor = "node3"

Important as you can see we are using a specific donor “node3” you need to use the name of the donor node and not the ip address. If we were not using a specific donor node the Galera cluster would select one as random as donor node. Donor nodes are beeing set to “Read Only” so it makes sense to specify a specifik donor node.

Once the configuration is in place restart mariadb on node 4 and node 5. They should start replicating using node 3 as donor.

Note it is also possible to use more than 1 donor node this can be done like this.

wsrep_sst_donor = "node3,node2"

Optional Once everything is up and running you can delete the “wsrep_sst_donor” line in /etc/mysql/conf.d/galera.cnf

Verify the cluster size

mysql -u root -p
SHOW STATUS LIKE 'wsrep_cluster_size';
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| wsrep_cluster_size | 5     |
+--------------------+-------+
linux/ubuntu_mariadb_galera_cluster_install_add_nodes.txt · Last modified: 25/09/2024 10:31 by Allan