Setup HAProxy Load Balancer for MariaDB Galera Cluster

If you check the above test scenario and try to create DBs on any of the nodes, you would see that the data would automatically sync between the nodes. Which means Availability is achieved. Now to achieve high availability we will use HaProxy as the loadbalancer.

Set up another VM for this and install HAProxy as follows.

sudo apt-get update
sudo apt-get install haproxy

Edit HA Proxy Config as follows.

sudo vim /etc/haproxy/haproxy.cfg

Add the following lines.

# MySQL Cluster FE configuration
frontend mysql_cluster_frontend
bind *:3306
mode tcp
option tcplog
default_backend galera_cluster_backend

# MySQL Cluster BE configuration
backend galera_cluster_backend
mode tcp
option tcpka
balance leastconn
server mysql-01 <node-1-ip>:3306 check weight 1
server mysql-02 <node-2-ip>:3306 check weight 1
server mysql-03 <node-3-ip>:3306 check weight 1

Make sure to update the ip addresses of each node in the config above.

systemctl restart haproxy

That’s it. Connect to Loadbalancer VM IP address : 3306 and you should now have a Highly Available MySQL/Mariadb Cluster with Galera.

Ref:
View story at Medium.com

Share

1 thought on “Setup HAProxy Load Balancer for MariaDB Galera Cluster”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.