August 27, 2014

Using keepalived for HA on top of Percona XtraDB Cluster

Percona XtraDB Cluster (PXC) itself manages quorum and node failure.  Minorities of nodes in a network partition situation will move themselves into a Non-primary state and not allow any DB activity.  Nodes in such a state will be easily detectable via SHOW GLOBAL STATUS variables.

It’s common to use HAproxy with PXC for load balancing purposes, but what if you are planning to just send traffic to a single node?  We would standardly use keepalived to HA HAproxy, and keepalived supports track_scripts that can monitor whatever we want, so why not just monitor PXC directly?

If we have clustercheck working on all hosts:

Then we can just install keepalived and the this config on all nodes:

And start the keepalived service. The virtual IP above will be brought up on an active node in the cluster and moved around if clustercheck fails.

If I shutdown PXC on node2:

We can see node2 moves to a FAULT state and the VIP moves to node1 instead.  This provides us with a very simple way to do Application to PXC high availability.

A few additional notes:

  • You can disqualify donors (i.e., make clustercheck fail on Donor/Desynced nodes) by setting the 3rd argument to clustercheck to 0.  Setting this to 1 means Donors can retain the VIP.
  • Each keepalived instance monitors its own state only, hence the @localhost GRANT.  This is much cleaner than exposing clustercheck as a web port via xinetd.
  • It’s possible to more complex things with keepalived like multiple vips, node weighting, etc.
  • Keepalived can track over multiple network interfaces (in this example, just eth1) for better reliability.
About Jay Janssen

Jay joined Percona in 2011 after 7 years at Yahoo working in a variety of fields including High Availability architectures, MySQL training, tool building, global server load balancing, multi-datacenter environments, operationalization, and monitoring. He holds a B.S. of Computer Science from Rochester Institute of Technology.

Comments

  1. Ashok Kumar says:

    Team,

    Please help me how can sync multiple extraDB cluster between two location.

    Thanks
    Ashok

  2. Hi again, Ashok,

    Once again our forums are the place to ask questions like this – however please try to include as much detail as possible. Here’s the url to the Percona XtraDB Cluster forums category: http://www.percona.com/forums/questions-discussions/percona-xtradb-cluster

  3. Marco Londero says:

    Hi guys,

    the conf is slightly bugged. If you don’t start slaves forcing “state BACKUP”, the IP will be configured on all interfaces.

    Marco

  4. CaptTofu says:

    Hi Jay!

    Trying to get this working on a Docker container – is this anything you’ve done?

  5. @CaptTofu — can’t say that I have.

Speak Your Mind

*