Install and Configure MariaDB Galera Cluster

Step 1: Prepare the Servers

Ensure all servers are updated and have MariaDB installed. For this guide, we will use three servers.


# Update packages
sudo apt-get update
sudo apt-get upgrade

# Install MariaDB
sudo apt-get install mariadb-server
    

Step 2: Install Galera

Install the Galera package on all servers.


# Install Galera
sudo apt-get install galera-3 mariadb-server
    

Step 3: Configure MariaDB

Edit the MariaDB configuration file /etc/mysql/my.cnf or /etc/my.cnf to include the Galera settings. Add the following configuration:

[mysqld]

binlog_format=ROW default_storage_engine=InnoDB innodb_autoinc_lock_mode=2 bind-address=0.0.0.0 # Galera settings wsrep_on=ON wsrep_provider=/usr/lib/galera/libgalera_smm.so wsrep_cluster_name=”galera_cluster” wsrep_cluster_address=”gcomm://IP1,IP2,IP3″ wsrep_node_address=”IP_THIS_NODE” wsrep_node_name=”node_name” wsrep_sst_method=rsync # Adjust IP addresses and node names as needed

Step 4: Start MariaDB Service

Start the MariaDB service on each server. The first node should be started with the --wsrep-new-cluster option:


# On the first node
sudo systemctl start mariadb --wsrep-new-cluster

# On the other nodes
sudo systemctl start mariadb
    

Step 5: Verify the Cluster

Check the status of the Galera cluster by running the following command on each node:


# Check Galera status
mysql -u root -p -e "SHOW STATUS LIKE 'wsrep_%';"
    

All nodes should show the same cluster size and state.

Step 6: Test the Cluster

To ensure the cluster is working correctly, create a database on one node and check if it replicates to the others:


# On any node
mysql -u root -p -e "CREATE DATABASE testdb;"

# Check on other nodes
mysql -u root -p -e "SHOW DATABASES LIKE 'testdb';"
    

Conclusion

Your MariaDB Galera Cluster should now be up and running. Ensure you secure your MariaDB installation and configure firewalls appropriately.

Other Recent Posts