Layer-4 Load Balancing with HAProxy for MariaSQL

If you have a MariaSQL Galera Cluster (All master) deployed, you can use HAProxy L-4 load balancing proxy.

Configure HAProxy on Layer4 Mode.

On this example, configure MariaDB backend like the following environment.

Configure HAProxy.

root@dlp:~# vi /etc/haproxy/haproxy.cfg
# change defaults section like follows

defaults
log global
mode tcp
timeout connect 5000
timeout client 50000
timeout server 50000

# define MariaDB for frontend, backend
frontend mysql-in
bind *:3306
default_backend backend_servers

backend backend_servers
balance roundrobin
server node01 10.0.0.51:3306 check
server node02 10.0.0.52:3306 check
root@dlp:~# systemctl restart haproxy

Verify working normally to access to frontend HAproxy Server.

debian@client:~# mysql -u root -p -h 10.0.0.30 -e "show variables like 'hostname';"
Enter password:
+---------------+------------------+
| Variable_name | Value |
+---------------+------------------+
| hostname | node02.srv.world |
+---------------+------------------+
debian@client:~# mysql -u root -p -h 10.0.0.30 -e "show variables like 'hostname';"
Enter password:
+---------------+------------------+
| Variable_name | Value |
+---------------+------------------+
| hostname | node01.srv.world |
+---------------+------------------+
Share

Leave a Reply

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