User Tools

Site Tools


linux:ubuntu_mariadb_galera_cluster_install

Ubuntu MariaDB Galera Cluster Install

We are going to set up a Galera Cluster with 3 nodes as shown here. Be aware 3 nodes is the minimum. If you are unsure if you need a Galera cluster or a just Primary Replica setup click [Here]

Install MariaDB

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

Configure Galera Cluster

Now we need to create the Galera configuration so that the nodes can communicate with each other.

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

Add the following lines.

Note At the present time only Binlog Format ROW is supported.

On Node 1

[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"

# Galera Synchronization Configuration
wsrep_sst_method = rsync

# Galera Node Configuration
wsrep_node_address = "node1_ip"
wsrep_node_name = "node1"

On Node 2

Same as node 1 except for these 2 lines.

wsrep_node_address = "node2_ip"
wsrep_node_name = "node2"

On Node 3

Same as node 1 except for these 2 lines.

wsrep_node_address = "node3_ip"
wsrep_node_name = "node3"

Initialize The Galera Cluster

Stop MariaDB on all nodes.

systemctl stop mariadb.service

On the first node, initialize the MariaDB Galera cluster with the following command.

galera_new_cluster

Check the status of the cluster.

mysql -u root -p
SHOW STATUS LIKE 'wsrep_cluster_size';

You should get an output similar to this one.

+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| wsrep_cluster_size | 1     |
+--------------------+-------+

On the second node start MariaDB.

systemctl start mariadb.service

And again check the status.

mysql -u root -p
SHOW STATUS LIKE 'wsrep_cluster_size';

You should get an output similar to this one. Indicating we have 2 nodes running.

+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| wsrep_cluster_size | 2     |
+--------------------+-------+

Do the same for the rest of the nodes in the cluster.

Verify Cluster Replication

On the first node create some databases with the following command.

mysql -u root -p
CREATE DATABASE testdb1;
CREATE DATABASE testdb2;
exit

Now lets check if the databases are present on the rest of the nodes. On each node you can check like this.

mysql -u root -p
SHOW DATABASES;

You should see the databases we created on node 1 being replicated on the rest of the nodes.

+--------------------+
| Database           |
+--------------------+
| testdb1            |
| testdb1            |
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
linux/ubuntu_mariadb_galera_cluster_install.txt · Last modified: 25/09/2024 10:22 by Allan