Configure HaProxy with MariaDb Cluster (Multi-active) — RHL7
First, you need configure nodes to MariaDb Cluster, I configure the following:
node-1: 192.168.1.11
node-2: 192.168.1.12
node-3: 192.168.1.13
haproxy: 192.168.1.21
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:
[local_repository]
baseurl=file:///media/dvd
gpgcheck=0
- 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:
global
log 127.0.0.1 local2
maxconn 4000
user haproxy
group haproxy
daemondefaults
log global
mode http
option tcplog
option dontlognull
retries 3
option redispatch
maxconn 4000
timeout connect 5000ms
timeout client 50000ms
timeout server 50000mslisten mariadb_cluster 0.0.0.0:3307
mode tcp
balance leastconn
option httpchk
server node-1 192.168.1.11:3306
server node-2 192.168.1.12:3306
server node-3 192.168.1.13:3306
listen stats 0.0.0.0:9000
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:
SELINUX=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 192.168.1.21 — port=3307
And view nodes estatus with haproxy web monitoring:
Next, we are happy.. :D