Search code examples
phpmariadbgalera

MariaDB Galera Cluster php driver



I want to setup a master-slave MariaDB Galera cluster like this:
I have 3 machines with LAMP and in front of them a load balancer.
Every machine have the same front-end to process php requests from users.
Every php request will either write or read from the database.
I want writes to be done on a single node to avoid deadlocks, so no multi master configuration, and reads can be done on any node.
My problem is how I know which node is the master, maybe the one I bootstrap the cluster from shut down and another is the master now, so I can connect to it to make a write.
I understood that MongoDB driver makes all the magic in this case, you just give him all the nodes addresses when connecting. Does this work for MariaDB too, cause I couldn't find any info on this, not even in PHP PDO.
I'm aware a HAProxy is able to manage that, knowing who is the master to send writes to, but I don't want to create a loop by sending the SQLs requests to a HAProxy that will loop back in one of the nodes.
This represents a problem even if I have a 3 layer configuration with the front-ends separated from the back-ends, how I connect from one front-end to the cluster master without HAProxy to help.
Is there any way around this, a PHP library or something, or do I need a cluster manager like a HAProxy?
Note: I setup my cluster initially using this guide.


Solution

  • I would suggest to use MaxScale, a proxy made for mariaDB which has been made for this purpose.

    https://mariadb.com/products/technology/maxscale

    I do not understand why you try to avoid a proxy??