Friday, April 29, 2016

Installing mariadb in ubuntu 14.04 and setting up a 2 node galera cluster

Getting ready



Let's update our apt cache with the mariadb apt repo, so that we can get the latest and greatest version.
Add the following two lines to /etc/apt/sources.list


deb http://mirror.jmu.edu/pub/mariadb/repo/10.1/ubuntu trusty main
deb-src http://mirror.jmu.edu/pub/mariadb/repo/10.1/ubuntu trusty main


Now perform an update of the repo cache in our system

sudo apt-get update

And then install mariadb with galera and rsync

sudo apt-get install mariadb-server galera-3 rsync

Installation is done.


Configuring mariadb with galera


I'm going to use 2 nodes here, 192.168.1.4 (master_node) and 192.168.1.5 (slave node). 

In our master_node I'm going to create a file called  cluster.cnf  in   /etc/mysql/conf.d  (Very important that the file name ends with  .cnf )  and put in the following contents.

[galera]
wsrep_on=ON
wsrep_provider=/usr/lib/libgalera_smm.so
wsrep_cluster_name="cluster_test"
wsrep_cluster_address="gcomm://192.168.1.4,192.168.1.5"
wsrep_node_name="master_node" 

wsrep_node_address=192.168.1.4  
wsrep_provider_options="pc.weight=3" #tells this server is very important
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
innodb_doublewrite=1



In our slave_node I'm going to create the same file, in the same location  and put in the following contents.

[galera]
wsrep_on=ON
wsrep_provider=/usr/lib/libgalera_smm.so
wsrep_cluster_name="cluster_test" # same name as in primary server
wsrep_cluster_address="gcomm://192.168.1.4,192.168.1.5"
wsrep-node-address=192.168.1.5
wsrep_node_name="slave_node"
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
innodb_doublewrite=1
wsrep_sst_method=rsync
wsrep_sst_receive_address=192.168.1.5


We're done configuring. Now in the master_node (primary server) run 

sudo service mysql stop
sudo service mysql start --wsrep-new-cluster


Check if we have successfully started a node in our cluster by running this from our terminal shell

mysql -u root -p -e 'SELECT VARIABLE_VALUE as "cluster size" FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME="wsrep_cluster_size"'

It should return 1. If so, we're good.

We next bring up our slave_node (secondary server). Run these from our second node 

sudo service mysql stop
sudo service mysql start # only use --wsrep-new-cluster in primary server


That's it !. Create a database from any one of the nodes and it'll be reflected on the other.


One more thing


Copy the file /etc/mysql/debian.cnf from the primary server into the secondary server (replace the one it has).

Fin

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home