Running MySQL or MariaDB in an active-active design keeps database access available when a node fails and supports spreading client connections across multiple hosts instead of a single primary.

In a Pacemaker and Corosync cluster, the pcs CLI defines resources that the cluster manager starts, stops, and monitors. A systemd resource that targets mariadb.service, mysql.service, or mysqld.service can be cloned so each cluster node runs the service while Pacemaker continuously checks health and performs recovery actions.

Active-active service management only works when the database layer is already multi-writer (for example, a Galera-based cluster), because cloning a standalone MySQL instance creates independent datasets. Quorum and fencing (STONITH) reduce split-brain risk, and client routing should avoid nodes that are not synced or not ready to accept writes.

Steps to set up MySQL or MariaDB active-active with PCS:

  1. Confirm the cluster is online and has quorum.
    $ sudo pcs status
    Cluster name: clustername
    Cluster Summary:
      * Stack: corosync (Pacemaker is running)
      * Current DC: node-02 (version 2.1.6-6fdc9deea29) - partition with quorum
      * 3 nodes configured
      * 5 resource instances configured
    
    Node List:
      * Online: [ node-01 node-02 node-03 ]
    ##### snipped #####
  2. Confirm the database replication layer reports a healthy multi-writer state on each node.
    $ sudo mysql -Nse "SHOW STATUS LIKE 'wsrep_cluster_status';"
    wsrep_cluster_status  Primary
    $ sudo mysql -Nse "SHOW STATUS LIKE 'wsrep_ready';"
    wsrep_ready ON
    $ sudo mysql -Nse "SHOW STATUS LIKE 'wsrep_cluster_size';"
    wsrep_cluster_size  3

    The wsrep_ checks apply to Galera-based clusters and should return Primary and ON before traffic distribution.

  3. Identify the MySQL or MariaDB service unit name.
    $ systemctl list-unit-files --type=service | grep -E '^(mysql|mysqld|mariadb)\.service'
    mariadb.service                              disabled        enabled
    mysql.service                                alias           -
    mysqld.service                               alias           -
  4. Create the MySQL or MariaDB service resource.
    $ sudo pcs resource create mysql_service systemd:mariadb op monitor interval=30s

    Use systemd:mysqld or systemd:mysql when that unit is present.

  5. Clone the MySQL or MariaDB service resource across nodes.
    $ sudo pcs resource clone mysql_service

    Cloning starts the service on every eligible node. Ensure multi-writer replication is healthy. Ensure client routing is not yet sending production writes to unsynced nodes.

  6. Verify the cloned resource status.
    $ sudo pcs status resources
    ##### snipped #####
      * Clone Set: mysql_service-clone [mysql_service]:
        * Started: [ node-01 node-02 node-03 ]
  7. Create a health check account for the load balancer address on one node.
    $ sudo mysql -e "CREATE USER 'haproxy_check'@'192.0.2.50';"

    192.0.2.50 stands for the load balancer address the nodes see. Galera replicates the account to every node. It has no password because HAProxy logs in without one, and it has no privileges.

  8. Append a TCP frontend and a backend listing every cluster node to /etc/haproxy/haproxy.cfg on the load balancer.
    frontend mariadb_front
        bind 192.0.2.50:3306
        mode tcp
        default_backend mariadb_nodes
    
    backend mariadb_nodes
        mode tcp
        balance leastconn
        option mysql-check user haproxy_check
        server node-01 192.0.2.11:3306 check
        server node-02 192.0.2.12:3306 check
        server node-03 192.0.2.13:3306 check

    option mysql-check only proves that a node accepts a login. A Galera node that loses quorum stays in rotation and fails table queries with ERROR 1047. When routing must follow Galera state, use MariaDB MaxScale or ProxySQL instead of HAProxy.

  9. Reload HAProxy to start accepting database connections.
    $ sudo systemctl reload haproxy
  10. Query through the load balancer to confirm a node answers.
    $ mysql -h 192.0.2.50 -u appuser -p -e "SELECT @@hostname;"
    Enter password:
    +------------+
    | @@hostname |
    +------------+
    | node-01    |
    +------------+

    Each new connection can reach a different node. The nodes see 192.0.2.50 as the client host, so an Access denied or not allowed to connect error means the account has no host entry matching that address.

  11. Change the application database host to 192.0.2.50.
  12. Run a failover test to confirm routing and writes survive a node outage.
Share this guide