In this tutorial, we will show you how to setup a MariaDB Clustering using Galera on Ubuntu. In addition to these easy install instructions, we’ll explain what is MariaDB clustering, how does cluster work, and how to enable clustering in MariaDB on Ubuntu.
MariaDB is a popular open-source database management system that offers high performance, scalability, and reliability. One of the key features of MariaDB is its ability to support clustering, which allows you to distribute the database load across multiple servers, ensuring high availability and scalability.
Table of Contents
What is Clustering?
Before we dive into MariaDB’s capabilities, let’s first understand what database clustering is. Clustering, in the context of databases, refers to the use of multiple servers or instances that appear as a single database to the user. The primary goal of clustering is to improve the database’s availability and fault tolerance. If one node (server) in the cluster fails, another can take over, thereby maintaining the availability of the database.
Does MariaDB support clustering?
Yes! One of the ways to cluster MariaDB is by setting up a Galera Cluster. MariaDB Galera Cluster is a synchronous multi-master cluster for MariaDB. It is available on Linux only and supports MariaDB 10.1 and above. It uses a technology known as synchronous replication. This means that all changes (writes) are made to all servers in the cluster at the same time, or ‘in sync’.
The advantage of synchronous replication is that you can write to any node in the cluster and the data will always be in sync. This prevents data loss if one node fails. It also allows for load balancing of read queries across all nodes in the cluster, which can significantly improve performance for read-intensive workloads.
How does MariaDB Galera Cluster Work?
MariaDB Galera Cluster is a synchronous multi-master database cluster that uses a technology called synchronous replication for data consistency across nodes. In this setup, all changes to the database are made on all servers simultaneously. When a write operation occurs on any node, it’s replicated on all other nodes before it’s committed, ensuring data consistency across the cluster. This prevents data loss if a node fails and allows for load balancing of read queries, improving performance for read-intensive workloads. Importantly, Galera Cluster provides automatic node joining and failure detection, automated recovery, and supports read and write to any cluster node. This setup ensures high availability and fault tolerance, making it suitable for mission-critical applications.
Is MariaDB Galera Clustering Free?
Yes, MariaDB Galera Cluster is free to use. MariaDB, including its clustering capabilities, is an open-source software released under the GNU General Public License. This means you can use, modify, and distribute it for free. However, if you require enterprise-level support or additional features, MariaDB Corporation offers commercial versions in the form of MariaDB Enterprise Server and MariaDB SkySQL, which are available under a subscription model.
What is the difference between MariaDB Galera and MySQL cluster?
Similarities between MariaDB Galera and MySQL Cluster
Both MariaDB Galera and MySQL Cluster are solutions that enable clustering and high availability for database systems. They share some common characteristics:
- Clustering: Both MariaDB Galera and MySQL Cluster provide clustering capabilities, allowing the distribution of database load across multiple nodes. This helps improve performance, scalability, and fault tolerance.
- Replication: Both solutions support data replication to ensure data consistency and availability across the cluster. They employ synchronous replication mechanisms to ensure that data changes are propagated to all nodes before committing transactions.
Differences between MariaDB Galera and MySQL Cluster
- Architecture: MariaDB Galera is based on the InnoDB storage engine and utilizes the Galera replication plugin. It follows a multi-master architecture, where each node can accept write operations independently. In contrast, MySQL Cluster uses the NDB (MySQL Cluster) storage engine and employs a shared-nothing architecture, where data is partitioned across nodes, and each node is responsible for a specific subset of data.
- ACID Compliance: MariaDB Galera provides full ACID (Atomicity, Consistency, Isolation, Durability) compliance, ensuring transactional consistency and integrity across the cluster. MySQL Cluster also offers ACID compliance, but it introduces additional concepts like distributed transactions and distributed deadlock detection.
- Scaling: MariaDB Galera supports horizontal scaling by adding more nodes to the cluster, allowing it to handle increased database workloads. MySQL Cluster, on the other hand, supports both horizontal and vertical scaling. It can scale horizontally by adding more data nodes and also vertically by increasing the resources of individual nodes.
- Data Management: MariaDB Galera supports various storage engines, including InnoDB, MyISAM, and others. It allows you to choose the most suitable engine for different use cases. MySQL Cluster, on the other hand, exclusively uses the NDB storage engine, optimized for distributed data management and high availability.
The choice between the two depends on specific requirements, workload characteristics, and the desired level of flexibility and control over the database environment.
How to Setup a MariaDB Galera Cluster?
Step 1: Install MariaDB
The first step is to install MariaDB on your Ubuntu server. To do this, run the following commands:
sudo apt update sudo apt install mariadb-server
Once the installation is complete, you can start the MariaDB service using the following command:
sudo systemctl start mariadb
To check the status of the service, run:
sudo systemctl status mariadb
Step 2: Configure MariaDB for Clustering
Once MariaDB is installed, you need to configure it for clustering. To do this, you will need to edit the MariaDB configuration file.
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
Add the following lines to the bottom of the file:
[galera] wsrep_on=ON wsrep_provider=/usr/lib/galera/libgalera_smm.so wsrep_cluster_address="gcomm://"
Save the changes and exit the editor.
Step 3: Install Galera
Galera is a synchronous multi-master replication plug-in for MariaDB that enables clustering. To install Galera, run the following commands:
sudo apt install software-properties-common sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8 sudo add-apt-repository 'deb [arch=amd64] http://mirror.nodesdirect.com/mariadb/repo/10.5/ubuntu bionic main' sudo apt update sudo apt install galera-4 galera-arbitrator-4
Step 4: Start Galera
Once Galera is installed, you can start it by running the following command:
This will initialize a new cluster.
Step 5: Configure Firewall
You will need to allow traffic on port 3306, which is used by MariaDB. To do this, run the following command:
sudo ufw allow 3306/tcp
Step 6: Verify Clustering
To verify that clustering is working correctly, you can use the following command to check the status of the cluster:
sudo mysql -u root -p -e "SHOW STATUS LIKE 'wsrep_cluster_size'"
This should show you the number of nodes in the cluster. That’s all!
For more information, visit the official Galera Cluster documentation.
Enabling clustering in MariaDB/MySQL on Ubuntu can help you scale your database infrastructure and ensure high availability. By following the steps outlined in this tutorial, you can easily set up clustering and start reaping the benefits of a distributed database.