We regularly get questions about how to set up a Galera cluster with just 2 nodes. The documentation clearly states you should have at least 3 Galera nodes to avoid network partitioning. But there are some valid reasons for considering a 2 node deployment, e.g., if you want achieve database high availability but have limited budget to spend on a third database node. Or perhaps you are running Galera in a development/sandbox environment and prefer a minimal setup.
Galera implements a quorum-based algorithm to select a primary component through which it enforces consistency. The primary component needs to have a majority of votes, so in a 2 node system, there would be no majority resulting in split brain. Fortunately, it is possible to add a garbd (Galera Arbitrator Daemon), which is a lightweight stateless daemon that can act as the odd node. Arbitrator failure does not affect the cluster operations and a new instance can be reattached to the cluster at any time. There can be several arbitrators in the cluster.
- Create a Deployment Package for 3+1 setup and edit out the 3rd Galera node,
- Run the Deployment Package, it will deploy a 2+1 configuration,
- Add garbd on the ClusterControl node.
You should end up with the below setup:
Deploy the Galera Cluster
Go to our Galera Configurator to generate a Deployment Package. Choose a “3+1” setup and insert a dummy IP address for the third Galera node.
Log into the ClusterControl node and download and extract the deployment package:
$ wget http://www.severalnines.com/galera-configurator/tmp/ts9mtv61aram7s3rammfjhi7u2/s9s-galera-codership-2.4.0-rpm.tar.gz $ tar -xzf s9s-galera-codership-2.4.0-rpm.tar.gz
Remove the dummy IP address line on following files:
So both files will be like the following:
$ cat s9s-galera-codership-2.4.0-rpm/mysql/scripts/install/.s9s/hostnames ###THIS FILE IS AUTOGENERATED. DON'T MODIFY 192.168.197.121 192.168.197.122
$ cat s9s-galera-codership-2.4.0-rpm/mysql/config/cmon.cnf.controller | grep mysql_server
Start the deployment:
$ cd s9s-galera-codership-2.4.0-rpm/mysql/scripts/install/ $ bash ./deploy.sh 2>&1 | tee cc.log
Once deployment is complete, login to the ClusterControl UI and install garbd on the ClusterControl host. It will be under the Manage -> Load Balancer:
Installing garbd will trigger a ClusterControl job which can be monitored at Jobs page. Once completed, you can verify garbd is running with a green tick icon at the top bar:
That’s it. Our minimal two-node Galera cluster is now ready!