How to install and configure MariaDB Galera as master to master replication cluster on Ubuntu 16.04 LTS

Here’s how you can install and configure MariaDB Galera as a master-to-master replication cluster on Ubuntu 16.04 LTS:

  1. Install MariaDB on each node in the cluster:
sudo apt-get update
sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
sudo add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://ftp.igh.cnrs.fr/pub/mariadb/repo/10.3/ubuntu xenial main'
sudo apt-get update
sudo apt-get install mariadb-server mariadb-client
  1. Start the MariaDB service on the first node:
sudo systemctl start mariadb
  1. Configure MariaDB on the first node by running the following command:
sudo mysql_secure_installation
  1. Stop the MariaDB service on the first node:
sudo systemctl stop mariadb
  1. On the first node, add the following lines to the /etc/mysql/my.cnf file to configure Galera replication:
[mysqld]
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0

# Galera Provider Configuration
wsrep_provider=/usr/lib/galera/libgalera_smm.so

# Galera Cluster Configuration
wsrep_cluster_name="galera_cluster"
wsrep_cluster_address="gcomm://<node1_ip>,<node2_ip>,<node3_ip>"

# Galera Node Configuration
wsrep_node_address="<this_node_ip>"
wsrep_node_name="<this_node_hostname>"

# Galera Synchronization Configuration
wsrep_sst_method=rsync

Replace <node1_ip>, <node2_ip>, and <node3_ip> with the IP addresses of all nodes in the cluster, <this_node_ip> with the IP address of the current node, and <this_node_hostname> with the hostname of the current node.

  1. Repeat steps 2 to 5 on each node in the cluster.
  2. Start the MariaDB service on the first node:
sudo systemctl start mariadb
  1. Start the MariaDB service on the other nodes in the cluster, one node at a time.

After completing these steps, you should have a MariaDB Galera cluster that is configured as a master-to-master replication cluster. To test the cluster, you can create a database on one node and verify that the database is replicated to the other nodes in the cluster.

Leave a Comment