MariaDB Galera Cluster Guide

MariaDB Galera Cluster quickstart guide

Quickstart Guide: MariaDB Galera Cluster

MariaDB Galera Cluster provides a multi-primary (active-active) cluster solution for MariaDB, enabling high availability, read/write scalability, and true synchronous replication. This means any node can handle read and write operations, with changes instantly replicated to all other nodes, ensuring no replica lag and no lost transactions. It's exclusively available on Linux.

1. Prerequisites

Before starting, ensure you have:

  • At least three nodes: For redundancy and avoiding split-brain scenarios (bare-metal or virtual machines).

  • Linux Operating System: A compatible Debian-based (e.g., Ubuntu, Debian) or RHEL-based (e.g., CentOS, Fedora) distribution.

  • Synchronized Clocks: All nodes should have NTP configured for time synchronization.

  • SSH Access: Root or sudo access to all nodes for installation and configuration.

  • Network Connectivity: All nodes must be able to communicate with each other over specific ports (see Firewall section). Low latency between nodes is ideal.

  • rsync: Install rsync on all nodes, as it's commonly used for State Snapshot Transfers (SST).

    • sudo apt install rsync (Debian/Ubuntu)

    • sudo yum install rsync (RHEL/CentOS)

2. Installation (on Each Node)

Install MariaDB Server and the Galera replication provider on all nodes of your cluster.

a. Add MariaDB Repository:

It's recommended to install from the official MariaDB repositories to get the latest stable versions. Use the MariaDB Repository Configuration Tool (search "MariaDB Repository Generator") to get specific instructions for your OS and MariaDB version.

Example for Debian/Ubuntu (MariaDB 10.11):

b. Install MariaDB Server and Galera:

c. Secure MariaDB Installation:

Run the security script on each node to set the root password and remove insecure defaults.

  • Set a strong root password.

  • Answer Y to remove anonymous users, disallow remote root login, remove test database, and reload privilege tables.

3. Firewall Configuration (on Each Node)

Open the necessary ports on each node's firewall to allow inter-node communication.

Adjust for your firewall system (e.g., firewalld for RHEL-based systems).

4. Configure Galera Cluster (galera.cnf on Each Node)

Create a configuration file (e.g., /etc/mysql/conf.d/galera.cnf) on each node. The content will be largely identical, with specific changes for each node's name and address.

Example galera.cnf content:

Important:

  • wsrep_cluster_address: List the IP addresses of all nodes in the cluster on every node.

  • wsrep_node_name: Must be unique for each node (e.g., node1, node2, node3).

  • wsrep_node_address: Set to the specific IP address of the node you are configuring.

5. Start the Cluster

a. Bootstrapping the First Node:

Start MariaDB on the first node with the --wsrep-new-cluster option. This tells it to form a new cluster. Do this only once for the initial node of a new cluster.

b. Starting Subsequent Nodes:

For the second and third nodes, start the MariaDB service normally. They will discover and join the existing cluster using the wsrep_cluster_address specified in their configuration.

6. Verify Cluster Operation

After all nodes are started, verify that they have joined the cluster.

a. Check Cluster Size (on any node):

Connect to MariaDB on any node and check the cluster status:

Inside the MariaDB shell:

The Value should match the number of nodes in your cluster (e.g., 3).

b. Test Replication:

  1. On node1, create a new database and a table:

  2. On node2 (or node3), connect to MariaDB and check for the new database and table:

  3. Insert data from node2:

  4. Verify on node1 that the new data is present:

This confirms synchronous replication is working.

Further Resources:

Last updated

Was this helpful?