Raja's Exocortex

Nginx Active/Passive Load Balancing of MySQL/MariaDB Galera Cluster

Use nginx to active/passive load balance MySQL/MariaDB Galera clusters.

Requires Nginx Plus, does not work with open source Nginx! Use HAProxy instead.

# Nginx sample standalone config for active/passive load balancing to
# a backend MySQL/MariaDB Galera cluster.

daemon off;

error_log  /dev/stderr;

events {}

tcp {

    upstream galera_backend {
        server galera1:3306 max_fails=3 fail_timeout=5s;
        server galear2:3306 max_fails=3 fail_timeout=5s backup;
        zone tcp_mem 64k;
    }

    # Match the 
    match mysql_handshake {
        send \x00;
        expect ~* \x00\x00;  # NullNull "filler" in handshake response
    }

    server {
        listen 127.0.0.1:3306;

        proxy_pass galera_backend;
        proxy_timeout = 5s;
        health_check match=mysql_handshake interval=20 fails=2 passes=2;
    }
}

References

  1. https://www.nginx.com/blog/scaling-mysql-tcp-load-balancing-nginx-plus-galera-cluster/