Skip to main content

Introduction to clusters

IfClustered youdatabases can’tare affordessential for yourensuring high availability, scalability, and fault tolerance in modern systems.

By distributing data across multiple nodes, they can handle larger workloads, prevent single points of failure, and ensure that services remain accessible even during hardware or network issues. Clusters are critical for businesses that need reliable, fast, and scalable database to be down for even a few minutes, a Multi-Master cluster is a great optionsolutions to ensuresupport highgrowing availability.

A multi-master scenario means that one node can be taken offline (e.g. for maintenance or upgrade purposes) without impacting availability, as the other node will continue to serve production traffic. Further, it doubles your capacity to read or write to the database and provides an additional layer of protection against data loss.

MySQL includes a Multi-Master replication, and Elestio enables you to set up your MySQL Multi-Master cluster in just a few clicks.demands.

To begin, you will needHow to havedeploy deployeda twonew MySQL instancescluster

1) Go to elestiothe DashboardElestio >Clusters tab.

001.png

2) Click on Deploy newMy service>First DatabasesCluster.

>

002.png

select

3) MySQL,Select scrollyour downSoftware, for example, MySQL.

003.png

4) Choose your Provider and Service Plan, then click Next.

5) Choose a name itfor your cluster, for example mysql-1cluster then click on the "Create service button"


6)

Screenshot 2022-09-29 175854.png

On


Select

2)Support Again,& goadvanced tosetting elestio Dashboard > Deploy new service> Databases > select MySQL,part, scroll down anduntil nameCluster configuration(Optional) part.

Here, you’ll have three configuration options:

  • Single Node
  • Primary/Replica
  • Multi-Master

Single node

004.png

When choosing the Single Node option, you’ll deploy a standalone node for MySQL. This means only one node will be set up, but it forwill example mysql-2 then click on the "Create service button"

3) Wait for the 2 instances toalready be ready

configured

4)as In the elestio dashboard open the service details ofa mysql-1Primary andnode. clickThis onsetup theensures "Configure cluster" button

5) Selectthat, in the partner instance dropdown "mysql-2" as the partner, then select "Multi Master" in Cluster mode, then click on "Apply changes" button

Screenshot 2022-09-29 180350.png

6) In the elestio dashboard open the service details of mysql-2 and click on the "Configure cluster" button

7) Select in the partner instance dropdown "mysql-1" as the partner, then select "Multi-Master" in Cluster mode, then click on "Apply changes" button

All done. You now have a multi-master MySQL cluster.


You can now read and write on both instances. If instance A is down you will still be able to use instance B and vice versa. Also,future, if you restorewant ato backupscale onby adding one instanceor more nodes, it will be seamlessly possible without requiring reconfiguration.

 

Primary/Replica

005.png

When choosing the Primary/Replica option, you will deploy at least one Primary node, and you can specify the number of replicas to include in the cluster.

By default, the number of replicas will be determined by the minimum required for the selected software. However, you can increase the number of replicas as long as it fits within your Service Quota.

For example, if you select 3 replicas from the dropdown, your cluster will consist of 4 nodes: 1 Primary and 3 Replicas.

 

Multi-Master

006.png

When choosing the Multi-Master option, you will deploy 2 Primary nodes that are connected to each other, ensuring mutual synchronization and redundancy.

It’s important to note that not all software supports this option. Make sure to verify compatibility with your selected software before proceeding.

 

7) Click on Create Service.

 

Now your cluster will be configured. Depending on the selected software, this process may take a little time.

 

CNAME

When deploying a new cluster, you will choose a CNAME. In our example, we used mysql-cluster.

Each node in the cluster will inherit the base name and receive a number incrementally.

For example, if you deploy a Primary/Replica cluster with 3 nodes, the nodes will be named:

  • mysql-cluster1
  • mysql-cluster2
  • mysql-cluster3

These names will also be used for their individual CNAMEs, automatically replicatedcreated by Elestio.

In addition, you will have a CNAME for the base name itself, such as mysql-cluster.

This base CNAME will always point to the otherPrimary instance.

Node.

How to use Multi-Master cluster from Node.js

If you can configure your two master clusters in Round Robin in your MySQL driver, a load balancer is not needed. The client-side will split the traffic between your instances and avoid a dead node. This helps to greatly simplify the high-availability system.

The regular MySQL driver for node.js supports this: https://www.npmjs.com/package/mysql#poolcluster


How to test your High Availability Cluster

  1. Shut down one of the VMs (instance A). You should still be able to connect, read and write on your cluster.
  2. Restart instance A, wait 30 seconds, then shut down instance B.
  3. Test your connectivity and read/write access to the cluster again.
  4. Finally, restart instance B.


How to use PHPMyAdmin to test your cluster

  1. Open the service details and click on Admin UI to get url and credentials of PHPMyAdmin.
  2. Open a browser tab with the Admin UI for instance B.
  3. Open another browser tab for instance A.
  4. Createpromote a new databasenode into instance A, add a table, and insert a line with sample data.
  5. Check ifPrimary, the databasebase createdCNAME fromwill Aautomatically is correctly replicatedupdate to instance B.
  6. Openreflect the databasechange, inensuring instanceseamless B.
  7. continuity
  8. Addwithout orrequiring editreconfiguration someacross rowsyour in the database on instance B and check if correctly replicated to instance A.


services.