Creating MariaDB Galera Clustering

0
1869

MariaDB Galera Cluster is a synchronous multi-master cluster for MariaDB. It is available on Linux only, and only supports the XtraDB/InnoDB storage engines (although there is experimental support for MyISAM – see the wsrep_replicate_myisam system variable).

Features

  • Synchronous replication
  • Active-active multi-master topology
  • Read and write to any cluster node
  • Automatic membership control, failed nodes drop from the cluster
  • Automatic node joining
  • True parallel replication, on row level
  • Direct client connections, native MariaDB look & feel

Benefits

The above features yield several benefits for a DBMS clustering solution, including:

  • No slave lag
  • No lost transactions
  • Both read and write scalability
  • Smaller client latencies

First Create 3 Nodes of Centminmod Installation

Node1:192.168.1.1 (CMM Installed) (MariaDB Cluster 1)
Node2:192.168.1.2 (CMM Installed) (MariaDB Cluster 2)
Node3:192.168.1.3 (CMM Installed) (MariaDB Cluster 3)
Node4:192.168.1.4 (CMM Installed) (Haproxy)


Open These ports 4567,4568,4444,3306 under TCP in your firewall (CSF or IPTABLES) on All MariaDB Cluster nodes.


On 192.168.1.1 (CMM Installed) (MariaDB Cluster 1)

Edit my.cnf file and at the end add lines below

Must change
Replace wsrep_node_address=”192.168.1.1″ with your node1 IP address.
Replace wsrep_cluster_address=gcomm://192.168.1.1,192.168.1.2,192.168.1.3 with your node1,node2,node3 IP respectively.


Alternatively you can also

Replace wsrep_cluster_name=”bullten” as you want but do remember it should be same on all nodes.
Replace wsrep_node_name=”node1″ to any name you want.

vi /etc/my.cnf
 [galera]
 # Mandatory settings
 wsrep_on=ON
 wsrep_cluster_name="bullten"
 wsrep_node_name="node1"
 wsrep_node_address="192.168.1.1"
 #wsrep_provider_options='pc.recovery=ON'
 wsrep_provider=/usr/lib64/galera/libgalera_smm.so
 wsrep_cluster_address=gcomm://192.168.1.1,192.168.1.2,192.168.1.3
 binlog_format=row
 innodb_autoinc_lock_mode=2 

Stop MariaDB

systemctl stop mariadb

Start Galera Cluster

galera_new_cluster

Change the permission

chown -R mysql:mysql /var/lib/mysql

On 192.168.1.2 (CMM Installed) (MariaDB Cluster 2)

Edit my.cnf file and at the end add lines below

Must change
Replace wsrep_node_address=”192.168.1.2″ with your node2 IP address.
Replace wsrep_cluster_address=gcomm://192.168.1.1,192.168.1.2,192.168.1.3 with your node1,node2,node3 IP respectively.


Alternatively you can also

Replace wsrep_node_name=”node2″ to any name you want.

vi /etc/my.cnf
 [galera]
 # Mandatory settings
 wsrep_on=ON
 wsrep_cluster_name="bullten"
 wsrep_node_name="node2"
 wsrep_node_address="192.168.1.2"
 #wsrep_provider_options='pc.recovery=ON'
 wsrep_provider=/usr/lib64/galera/libgalera_smm.so
 wsrep_cluster_address=gcomm://192.168.1.1,192.168.1.2,192.168.1.3
 binlog_format=row
 innodb_autoinc_lock_mode=2

Change the permission

chown -R mysql:mysql /var/lib/mysql

Stop MariaDB

systemctl stop mariadb

Start MariaDB

systemctl start mariadb

On 192.168.1.3 (CMM Installed) (MariaDB Cluster 3)

Edit my.cnf file and at the end add lines below

Must change
Replace wsrep_node_address=”192.168.1.3″ with your node3 IP address.
Replace wsrep_cluster_address=gcomm://192.168.1.1,192.168.1.2,192.168.1.3 with your node1,node2,node3 IP respectively.


Alternatively you can also

Replace wsrep_node_name=”node3″ to any name you want.

vi /etc/my.cnf
[galera]
 # Mandatory settings
 wsrep_on=ON
 wsrep_cluster_name="bullten"
 wsrep_node_name="node3"
 wsrep_node_address="192.168.1.3"
 #wsrep_provider_options='pc.recovery=ON'
 wsrep_provider=/usr/lib64/galera/libgalera_smm.so
 wsrep_cluster_address=gcomm://192.168.1.1,192.168.1.2,192.168.1.3
 binlog_format=row
 innodb_autoinc_lock_mode=2 

Change the permission

chown -R mysql:mysql /var/lib/mysql

Stop MariaDB

systemctl stop mariadb

Start MariaDB

systemctl start mariadb

Now your Node is connected to check cluster size run the below command on any MariaDB node

SHOW GLOBAL STATUS LIKE 'wsrep_cluster_size';

wsrep_cluster_size = 3 shows three nodes are inter connected.