Loadbalance MySQL/MariaDB with HAProxy

In your haproxy.cfg, you should do this:

global
    log /dev/log local0 notice
    user haproxy
    group haproxy
    stats socket /var/run/haproxy.sock mode 660 level admin
defaults
    log global
    retries 2
    timeout connect 3000
    timeout server 5000
    timeout client 5000
listen galera
    bind /var/run/mysqld/mysqld.sock mode 666
    option mysql-check user HAPROXY
    balance first
    server galera1 192.168.20.21:3306 check maxconn 64
    server galera2 192.168.20.22:3306 check maxconn 64
    server galera3 192.168.20.23:3306 check maxconn 64

And why do I listen on a socket? That is because an application will assume that mysql/mariadb are listening on a socket when you specify “localhost” by default.