Today we will setup a HAProxy Service for our 3 Node MySQL Galera Cluster
Our Setup:
- 3 Node Galera MySQL Cluster
- 3 HAProxy Services (Each HAProxy Service Running on the MySQL Nodes)
- MySQL Listens on Port 3307
- HAProxy Listens on Port 3306 and Proxies through to 3307
I have setup HAProxy on the same node as the MySQL Servers for my use case, but you can also setup HAProxy on a node outside the MySQL Host.
So essentially our MySQL Galera Cluster is a Multi Master Setup, but for now we will only accept connections from Node-A, and have Node-B and Node-C as Backup servers. Should Node-A go down, HAProxy will route connections to Node-B, and if Node-B also goes down, connections will be routed to Node-C.
If the Primary Node, which is Node-A recovers, connections will be restored to Node-A.
Security:
We use iptables to allow traffic between the nodes for port TCP/3307 and allow all traffic for Port TCP/3306, as HAProxy will allow the IP Based Access:
1 2 3 4 5 |
|
HAProxy:
Installing HAProxy on Ubuntu:
1 2 |
|
Configure HAProxy with a Port 3306 listener, specify your source addresses that you would like to be authorized to communicate with MySQL and then specify the servers to proxy the connections to our MySQL Galera Cluster, specifying 2 backup servers:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
Start HAProxy:
1 2 |
|
Authorize HAProxy Hostnames to Connect to MySQL:
In this case we need to allow the Hostnames to be able to connect to mysql:
1 2 |
|