Galera Cluster is a synchronous multi-master replication solution for MySQL, providing high availability and scalability. In this blog, we’ll walk through the steps to set up a Galera Cluster and address the question of data export/import when adding a new node.
MySQL Version: Ensure you are using a compatible version of MySQL (preferably MySQL 5.7 or 8.0).
Operating System: You should have a Linux-based OS (like Ubuntu, CentOS, etc.).
Network Configuration: Ensure that all nodes can communicate with each other over the network.
Required Packages: Install Galera and MySQL on each node.
# For Ubuntu
sudo apt update
sudo apt install mysql-server galera
# For CentOS
sudo yum install mysql-server galera
Open the MySQL configuration file (usually located at /etc/mysql/my.cnf or /etc/my.cnf) and add the following configurations:
[mysqld]
# Basic settings
bind-address = 0.0.0.0
default-storage-engine = InnoDB
innodb_doublewrite = 1
innodb_flush_log_at_trx_commit = 1
innodb_flush_method = O_DIRECT
# Galera settings
wsrep_on = ON
wsrep_cluster_name = 'my_galera_cluster'
wsrep_cluster_address = 'gcomm://node1_ip,node2_ip,node3_ip' # Replace with actual IPs
wsrep_node_address = 'this_node_ip' # Replace with this node's IP
wsrep_node_name = 'node_name' # Unique name for each node
# SST method
wsrep_sst_method = rsync
On the first node, start MySQL with the Galera cluster:
sudo service mysql start --wsrep-new-cluster
On the other nodes, simply start the MySQL service:
sudo service mysql start
You can check the status of the Galera cluster by running the following command on any node:
SHOW STATUS LIKE 'wsrep_cluster_size';
This should return the number of nodes in the cluster.
No, you do not need to export and import data when adding a new node to a Galera cluster. Instead, the new node will automatically synchronize with the existing nodes using the State Snapshot Transfer (SST) method specified in your configuration.
Install MySQL and Galera on the new node (as described in Step 1).
Configure MySQL on the new node (as described in Step 2), ensuring the wsrep_cluster_address includes the addresses of the existing nodes.
Start the New Node:
sudo service mysql start
Verify the Cluster: Once the new node is up, check the cluster status again:
SHOW STATUS LIKE 'wsrep_cluster_size';
The cluster size should reflect the addition of the new node.
Setting up a Galera Cluster in MySQL is straightforward and provides a robust solution for high availability and scalability. When adding new nodes, you do not need to worry about exporting and importing data; the cluster takes care of synchronizing data automatically. By following these steps, you can create a resilient MySQL environment capable of handling increased loads and providing high availability.