blog
How to Deploy a MariaDB Cluster for High Availability
MariaDB Cluster is a multi-primary replication system built from MariaDB Server, MySQL wsrep patch and Galera wsrep provider.
Galera is based on synchronous (or ‘virtually synchronous’) replication method, which ensures the data applied to other nodes before it is committed.
Having the same data on all nodes means that node failures can be easily tolerated, and no data is lost. It is also easier to failover to another node, since all the nodes are up to date with the same data.
MariaDB Cluster is a high availability solution that can achieve high uptime for organizations with strict database Service Level Agreements.
Besides managing high availability, it also can be used to scale the database service and expand the service to multi regions.
Let’s take a look at how you can deploy a MariaDB cluster for high availability using ClusterControl, with Maxscale and Keepalived to support it.
MariaDB Cluster Deployment
MariaDB cluster deployment in ClusterControl is really straightforward, and available in the free to use Community Edition.
You can go through “Deploy”, choose MySQL Galera as shown below:
Fill in SSH user and credential information, Cluster Name that you want to use and then Continue.
Choose MariaDB as the Vendor of the database you want to install.
Server Data Directory, Server Port can use the default configuration, unless you define specific configuration.
Fill the Admin/Root database password and finally Add Node to add the target IP Addresses of database nodes.
Galera Nodes require at least 3 nodes or you can use 2 database nodes and galera arbiter configured on a separate host.
After all fields are filled in, just Deploy the cluster. It will trigger a new job to Create Cluster as shown below:
Maxscale Deployment
Maxscale is a database load balancer, database proxy, and firewall that sits between your application and the MariaDB nodes.
Some of Maxscale’s features are :
- Automatic Failover for High Availability
- Traffic load balancing (read and write split)
- Traffic controls for queries and connections.
There are two ways to go through Load Balancer Deployment, you can “Add Load Balancer” in Cluster Menu as shown below:
Or you can go to Manage -> Load Balancer.
It will go to the same page, which is the Load Balancer page. Choose the “Maxscale tab” for deployment of the Maxscale load balancer:
Choose the Server Address, define maxscale username and password, you can leave the default configuration for Threads and Read/Write port.
Also include the MariaDB node(s) to be added in the load balancer.
You can “Deploy MaxScale” for deploying MaxScale database proxy and load balancing.
The best practice to make the load balancer highly available is to set up at least 2 MaxScale instances on different hosts.
Keepalived Deployment
Keepalived is a daemon service in linux used for health checks, and also used for failover if one of the servers is down.
The mechanism is using VIP (Virtual IP Address) to achieve high availability, consisting of one server acting as primary, and the other acting as backup.
Deployment of Keepalived is service can be done at Manage -> Load Balancer.
Please choose your Load Balancer type, which is MaxScale in our example here.
ClusterControl also supports HAProxy and ProxySQL as load balancers which can be integrated with Keepalived.
Define your Virtual IP (VIP) and Network Interface for Virtual IP Address.
After that, just click Deploy Keepalived.
It will trigger a new job to deploy Keepalived on both MaxScale hosts.
The final architecture for MariaDB Cluster for High Availability consists of 3 database nodes, 2 load balancer node, and a keepalived service on top of each load balancer as shown on the Topology below :
Conclusion
We have shown how we can quickly deploy a High Availability MariaDB Cluster with MaxScale and Keepalived via ClusterControl. We went through the setups for database nodes and proxy nodes.
To read more about Galera Cluster, check out our online tutorial.
Note that ClusterControl also supports other load balancers like ProxySQL and HAProxy. Do give these a try and let us know if you have any questions.
Stay on top of all things MariaDB by subscribing to our newsletter below.
Follow us on LinkedIn and Twitter for more great content in the coming weeks. Stay tuned!