Configure HaProxy with MariaDb Cluster (Multi-active) — RHL7

Miguel Pazo Sánchez
2 min readMay 24, 2016

First, you need configure nodes to MariaDb Cluster, I configure the following:





I will be assumed that you already configured the cluster, and I will continue with the haproxy configuration:

1. Install haproxy

Haproxy package is into the ISO by default, then you only need to configure local repository with it. I use a VM with RedHat7 and I have followed the next steps:

  • Connect the ISO with CD-ROM unit in the VM.
  • cd /etc/yum.repos.d
  • vi local.repo:


  • mkdir /media/dvd
  • mount /dev/cdrom /media/dvd
  • yum install haproxy

2. Configure haproxy

First we need to configure the log file:

  • In: /etc/rsyslog.conf uncomment next lines:

# Provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514

  • Create haproxy.conf: vi /etc/rsyslog.d/haproxy.conf, with next content:

local2.* /var/log/haproxy.log

Now, we need to configure: /etc/haproxy/haproxy.cfg, with next content:

log local2
maxconn 4000
user haproxy
group haproxy

log global
mode http
option tcplog
option dontlognull
retries 3
option redispatch
maxconn 4000
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms

listen mariadb_cluster
mode tcp
balance leastconn
option httpchk
server node-1
server node-2
server node-3

listen stats
mode http
stats enable
stats uri / #URI to haproxy web monitoring
stats realm HAProxy\ Statistics
stats auth user:password #need to basic HTTP authentication
stats admin if TRUE

3. Start haproxy

First, we need to disable firewall and selinux with next commands:

  • systemctl stop firewalld
  • systemctl disable firewalld
  • In /etc/selinux/config, change SELINUX value to disabled:


Finish, we need to start the haproxy service with:

service haproxy start

You can connect to mysql server by haproxy with:

mysql -u user -p -h — port=3307

And view nodes estatus with haproxy web monitoring:

Next, we are happy.. :D



Miguel Pazo Sánchez

AWS Solutions Architect, independent cloud technologies consultant and pineapple pizza lover.