HAProxy for MySQL Master-Slave Replication -
We are setting up MySQL master-slave replication and everything is working fine.
Currently all loads (reads / writes) are going on the master server, our application reads 99% and writes 1%.
We have thought about loading (reads only) both Master and Slave so we both thought to use HAProxy to distribute the load to MySQL servers.
Our requirement only writes to be redirected to the master server and reads to distribute between master and slave servers.
I have applied the same for my project. I have two DB servers (DB 01, DB22) behind Hi-Proxy (LB01), I hit high-proxy by assuming DB as my application. In my application, I read the database query to read on 3307 and write it on 3306 port.
In haproxy.cfg (Configuration File HAPROXY) as two LISTENER:
listen mysql cluster bind *: 3306 mode TCP remaining roundrobin option mysql-check user mast_ha server DB01 10.xxx:3306 check maxconn 100000 mysql-cluster-replica bind *: 3307 mode tcp option mysql-check user mast_ha server db02 10.xxx: 3306 check maximum 100000 and Call mysql distrubuted from two jdbc templates, one to read and write another application.
Comments
Post a Comment