Installing a MariaDB Galera cluster on Ubuntu 22.02
Linux Tutorials

Installing a MariaDB Galera cluster on Ubuntu 22.02

This guide will show you how to install a MariaDB Galera cluster on Ubuntu 22.02, providing high availability and scalability for your database workloads.

Harrison R
Harrison RJan 5, 2023

Installing a MariaDB Galera cluster on Ubuntu 22.02 is a straightforward process that allows you to set up a highly available and scalable database cluster. In this blog post, we will guide you through the steps to install and configure a MariaDB Galera cluster on three Ubuntu 22.02 machines. You will learn how to install the MariaDB Server and Galera Cluster packages, as well as how to configure the cluster and start the MariaDB service on each machine. By the end of this tutorial, you will have a fully functioning MariaDB Galera cluster that is ready to handle your database workload.

Step 1 - Installing MariaDB Server

First, you need to install the MariaDB Server on each of the three machines. To do this, open a terminal on each machine and enter the following commands:

sudo apt update
sudo apt install mariadb-server

This will install the latest version of the MariaDB Server on your machine.

Step 2- Installing MariaDB Galera Cluster

Next, you need to install the MariaDB Galera Cluster on each of the three machines. To do this, enter the following command in the terminal on each machine:

sudo apt install galera-3

This will install the necessary packages for the Galera Cluster on your machine.

Once the MariaDB Server and Galera Cluster have been installed, you need to configure the cluster. To do this, you will need to edit two configuration files:

/etc/mysql/mariadb.conf.d/50-server.cnf
/etc/mysql/conf.d/cluster.cnf

In the /etc/mysql/mariadb.conf.d/50-server.cnf file, you need to add the following lines under the [mysqld] section:

binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0

These lines configure the MariaDB Server to use the ROW-based binary log format, the InnoDB storage engine, and to listen for connections from other hosts.

In the /etc/mysql/conf.d/cluster.cnf file, you need to add the following lines:

[mysqld]
wsrep_on=ON
wsrep_provider=/usr/lib/galera/libgalera_smm.so
wsrep_cluster_name="my_cluster"
wsrep_cluster_address="gcomm://IP1,IP2,IP3"
wsrep_node_name="node1"
wsrep_node_address="IP1"
wsrep_sst_method=rsync

These lines configure the Galera Cluster with a name, address, and node name. Replace IP1, IP2, and IP3 with the respective IP addresses of the three Ubuntu 22.02 machines. Replace node1 with a unique name for the current machine.

Once the configuration files have been edited, you can start the MariaDB service on the first machine by running the following command:

sudo systemctl start mariadb

This will start the MariaDB Server on the first machine and initiate the Galera Cluster.

To start the MariaDB service on the remaining machines, run the following command on each machine:

sudo systemctl start mariadb --wsrep-new-cluster

This will start the MariaDB Server on the remaining machines and add them to the cluster.

Conclusion

That's it! You have successfully installed and configured a MariaDB Galera Cluster on three Ubuntu 22.02 machines.

Share
Harrison R

Editor-in-Chief

Harrison R

Whilst developing and maintaining various products at Letrix Labs, Harrison enjoys writing technical guides and news articles in his spare time on topics such as Linux, web hosting, and cloud computing. These are some of his favorite subjects to write about.

Next article

Changing the root password on a Linux Server (CLI)

Newsletter

Get the most talked about articles directly in your inbox

Every week we share the most relevant news in tech, culture and entertainment.

Your privacy is important to us. We promise to not send you spam!