1.8. Replicating MariaDB with Galera


You can replicate a MariaDB database using the Galera solution to create a synchronous multi-source cluster for high availability and data consistency.

주의

Replication itself is not a sufficient backup solution. Replication protects source servers against hardware failures, but it does not ensure protection against data loss.

1.8.1. Introduction to MariaDB Galera Cluster

MariaDB Galera Cluster provides synchronous multi-source replication that allows all nodes to be writable and ensures data consistency across the cluster.

The interface between Galera replication and a MariaDB database is defined by the write set replication API (wsrep API).

The main features of MariaDB Galera Cluster are:

  • Synchronous replication
  • Active-active multi-source topology
  • Read and write to any cluster node
  • Automatic membership control, failed nodes drop from the cluster
  • Automatic node joining
  • Parallel replication on row level
  • Direct client connections: users can log on to the cluster nodes, and work with the nodes directly while the replication runs

Synchronous replication means that a server replicates a transaction at commit time by broadcasting the write set associated with the transaction to every node in the cluster. The client (user application) connects directly to the Database Management System (DBMS), and experiences behavior that is similar to native MariaDB.

Synchronous replication guarantees that a change that happened on one node in the cluster happens on other nodes in the cluster at the same time.

Therefore, synchronous replication has the following advantages over asynchronous replication:

  • No delay in propagation of the changes between particular cluster nodes
  • All cluster nodes are always consistent
  • The latest changes are not lost if one of the cluster nodes crashes
  • Transactions on all cluster nodes are executed in parallel
  • Causality across the whole cluster

1.8.2. Components to build MariaDB Galera Cluster

Before deploying a functional, synchronously replicated MariaDB Galera Cluster, you must first install and understand the function of the core software components, specifically the MariaDB Server, the Galera Replication library, and the supporting Galera packages.

To build MariaDB Galera Cluster, you must install the following packages on your system:

  • mariadb-server-galera - contains support files and scripts for MariaDB Galera Cluster.
  • mariadb-server - is patched by MariaDB upstream to include the write set replication API (wsrep API). This API provides the interface between Galera replication and MariaDB.
  • galera - is patched by MariaDB upstream to add full support for MariaDB. The galera package contains the following:

    • Galera Replication Library provides the whole replication functionality.
    • The Galera Arbitrator utility can be used as a cluster member that participates in voting in split-brain scenarios. However, Galera Arbitrator cannot participate in the actual replication.
    • Galera Systemd service and Galera wrapper script which are used for deploying the Galera Arbitrator utility. RHEL 10 provides the upstream version of these files, located at /usr/lib/systemd/system/garbd.service and /usr/sbin/garb-systemd.

1.8.3. Deploying MariaDB Galera Cluster

You can deploy MariaDB Galera Cluster by installing the required packages, configuring cluster settings, and bootstrapping the first node to create a new cluster.

Prerequisites

  • All of the nodes in the cluster have TLS set up.
  • All certificates on all nodes must have the Extended Key Usage field set to:

    TLS Web Server Authentication, TLS Web Client Authentication

Procedure

  1. Install the MariaDB Galera Cluster packages:

    # dnf install mariadb-server-galera

    As a result, the following packages are installed together with their dependencies:

  2. Update the MariaDB server replication configuration before the system is added to a cluster for the first time. The default configuration is distributed in the /etc/my.cnf.d/galera.cnf file. Before deploying MariaDB Galera Cluster, set the wsrep_cluster_address option in the /etc/my.cnf.d/galera.cnf file on all nodes to start with the following string:

    gcomm://
    • For the initial node, it is possible to set wsrep_cluster_address as an empty list:

      wsrep_cluster_address="gcomm://"
    • For all other nodes, set wsrep_cluster_address to include an address to any node which is already a part of the running cluster. For example:

      wsrep_cluster_address="gcomm://10.0.0.10"

      For more information about how to set Galera Cluster address, see Galera Cluster Address.

  3. Enable the wsrep API on every node by setting the wsrep_on=1 option in the /etc/my.cnf.d/galera.cnf configuration file.
  4. Add the wsrep_provider_options variable to the Galera configuration file with the TLS keys and certificates. For example:

    wsrep_provider_options="socket.ssl_cert=/etc/pki/tls/certs/source.crt;socket.ssl_key=/etc/pki/tls/private/source.key;socket.ssl_ca=/etc/pki/tls/certs/ca.crt"
  5. Bootstrap a first node of a new cluster by running the following wrapper on that node:

    # galera_new_cluster

    This wrapper ensures that the MariaDB server daemon (mariadbd) runs with the --wsrep-new-cluster option. This option provides the information that there is no existing cluster to connect to. Therefore, the node creates a new UUID to identify the new cluster.

    참고

    The mariadb service supports a systemd method for interacting with multiple MariaDB server processes. Therefore, in cases with multiple running MariaDB servers, you can bootstrap a specific instance by specifying the instance name as a suffix:

    # galera_new_cluster mariadb@node1
  6. Connect other nodes to the cluster by running the following command on each of the nodes:

    # systemctl start mariadb

    As a result, the node connects to the cluster, and synchronizes itself with the state of the cluster.

1.8.4. Checking the status of a MariaDB Galera cluster

It is important to monitor and ensure the health, performance, and synchronization of a MariaDB Galera cluster. For that, you can query status variables on each node to monitor the node and the cluster.

To check the status of a MariaDB Galera cluster, you can use the following queries:

  • Display the number of nodes in the cluster:

    # mysql -u root -p -e 'show status like "wsrep_cluster_size";'
    +--------------------+-------+
    | Variable_name      | Value |
    +--------------------+-------+
    | wsrep_cluster_size | 4     |
    +--------------------+-------+
  • Display the node’s cluster component status:

    # mysql -u root -p -e 'show status like "wsrep_cluster_status";'
    +----------------------+---------+
    | Variable_name        | Value   |
    +----------------------+---------+
    | wsrep_cluster_status | Primary |
    +----------------------+---------+

    The value of the wsrep_cluster_status variable indicates the status of the cluster component the current node belongs to. Possible values are:

    • Primary: The cluster is functioning normally. A quorum is present. In a healthy cluster, all nodes report Primary.
    • Non-primary: The node has lost the connection to the primary component of the cluster and is no longer part of the active cluster. However, the node still can serve read queries but cannot process write operations.
    • Disconnected: The node is not connected to any cluster component. Consequently, it cannot accept queries and is not replicating any data.
  • Display the node’s status:

    # mysql -u root -p -e 'show status like "wsrep_local_state_comment";'
    +---------------------------+--------+
    | Variable_name             | Value  |
    +---------------------------+--------+
    | wsrep_local_state_comment | Synced |
    +---------------------------+--------+

    The following are frequent values of the wsrep_local_state_comment variable:

    • Synced: The node is fully synchronized within the cluster and actively participating in replication.
    • Desynced: The node is still part of the cluster but it is primarily busy with the state transfer.
    • Joining: The node is in the process of joining a cluster.
    • Joined: The node has successfully joined a cluster. It can receive and apply write sets from the cluster.
    • Donor: The node currently provides a State Snapshot Transfer (SST) to a joining node. When a new node joins and requires a full state transfer, the cluster selects an existing node to send the necessary data.
  • Check whether the node accepts write sets from the cluster:

    # mysql -u root -p -e 'show status like "wsrep_ready";'
    +---------------+-------+
    | Variable_name | Value |
    +---------------+-------+
    | wsrep_ready   | ON    |
    +---------------+-------+

    When the wsrep_ready variable is ON, the node has successfully initialized its components and is connected to a cluster. Additionally, the node is synchronized or has reached a state where it can serve queries.

  • Check whether the node has network connectivity with other hosts:

    # mysql -u root -p -e 'show status like "wsrep_connected";'
    +-----------------+-------+
    | Variable_name   | Value |
    +-----------------+-------+
    | wsrep_connected | ON    |
    +-----------------+-------+

    The ON value means that node has connectivity to at least one member in the cluster.

  • Display the average size of the local received queue for write sets since the last FLUSH STATUS command or since the server started:

    # mysql -u root -p -e 'show status like "wsrep_local_recv_queue_avg";'
    +----------------------------+-------+
    | Variable_name              | Value |
    +----------------------------+-------+
    | wsrep_local_recv_queue_avg | 0.012 |
    +----------------------------+-------+

    A value near 0 is the ideal state and indicates that the node continues applying write sets as they are received. A persistently high or growing value can be an indicator of performance bottlenecks, such as slow disk I/O.

  • Display the flow control status:

    # mysql -u root -p -e 'show status like "wsrep_flow_control_paused";'
    +---------------------------+-------+
    | Variable_name             | Value |
    +---------------------------+-------+
    | wsrep_flow_control_paused | 0     |
    +---------------------------+-------+

    This variable represents the fraction of time a node has been paused and is unable to process new incoming transactions because its local receive queue was too full, triggering flow control. A value close to 0 indicates the node continues with the replication workload efficiently. A value approaching 1.0 means that the node frequently or constantly encounters difficulty in applying write sets and can be a bottleneck for the cluster.

    If the node is frequently pausing, you can adjust the wsrep_slave_threads parameter in the /etc/my.cnf.d/galera.cnf file.

  • Display the average distance between the lowest and highest sequence numbers the node can apply in parallel:

    # mysql -u root -p -e 'show status like "wsrep_cert_deps_distance";'
    +--------------------------+-------+
    | Variable_name            | Value |
    +--------------------------+-------+
    | wsrep_cert_deps_distance | 1     |
    +--------------------------+-------+

    A higher value indicates a greater degree of parallelism. It is the optimal value you can use in the wsrep_slave_threads parameter in the /etc/my.cnf.d/galera.cnf file.

1.8.5. Adding a new node to MariaDB Galera Cluster

You can add a new node to your MariaDB Galera Cluster or reconnect an existing one by configuring the cluster address in the node’s configuration file.

Procedure

  • On the particular node, provide an address to one or more existing cluster members in the wsrep_cluster_address option within the [mariadb] section of the /etc/my.cnf.d/galera.cnf configuration file :

    [mariadb]
    wsrep_cluster_address="gcomm://192.168.0.1"

    When a new node connects to one of the existing cluster nodes, it is able to see all nodes in the cluster.

    However, preferably list all nodes of the cluster in wsrep_cluster_address.

    As a result, any node can join a cluster by connecting to any other cluster node, even if one or more cluster nodes are down. When all members agree on the membership, the cluster’s state is changed. If the new node’s state is different from the state of the cluster, the new node requests either an Incremental State Transfer (IST) or a State Snapshot Transfer (SST) to ensure consistency with the other nodes.

1.8.6. Restarting MariaDB Galera Cluster

If you shut down all nodes at the same time, you stop the cluster, and the running cluster no longer exists. However, the cluster’s data still exist.

To restart the cluster, bootstrap a first node as described in Deploying MariaDB Galera Cluster

주의

If the cluster is not bootstrapped, and mariadb on the first node is started with only the systemctl start mariadb command, the node tries to connect to at least one of the nodes listed in the wsrep_cluster_address option in the /etc/my.cnf.d/galera.cnf file. If no nodes are currently running, the restart fails.

Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2026 Red Hat
맨 위로 이동