Galera Cluster Setup

From Michael's Information Zone
Jump to navigation Jump to search
  1. https://mariadb.com/kb/en/mariadb/yum/#installing-mariadb-galera-cluster-with-yum
  2. https://geekdudes.wordpress.com/2015/07/18/setting-up-failover-cluster-for-mariadb-on-centos-7/
  3. http://mrbriancollins.blogspot.com/2015/12/mariadb-101-galera-cluster-in-centos-7.html
  4. https://groups.google.com/forum/#!msg/codership-team/a5S0aExW2oI/fY5yBGdSWUYJ


Wow, it took way too long to figure out how to configure this. But before I forget here are the steps I took.

CentOS 7

First off, MariaDB now has Galera baked in so make sure to install the latest stable version.
[root@db1 ~]# yum autoremove mariadb mariadb-server
[root@db1 ~]# nano /etc/yum.repos.d/mariadb.repo

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1.16/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

[root@db1 ~]# yum install MariaDB-server MariaDB-client
[root@db1 ~]# systemctl start mysql
[root@db1 ~]# mysql_secure_installation

  • Create a root password and accept all other defaults. Later we will create the user account that will allow replication.

[root@db1 ~]# mysql -uroot -p

MariaDB [(none)]> grant all on *.* to 'root'@'%' identified by 'password';
MariaDB [(none)]> grant usage on *.* to 'cluster_user'@'%' identified by 'password2';
MariaDB [(none)]> grant all privileges on *.* to 'cluster_user'@'%';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit

[root@db1 ~]# systemctl stop mysql
[root@db1 ~]# nano /etc/my.cnf.d/server.cnf

#
# * Galera-related settings
#
[galera]
wsrep_on=ON
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address=gcomm://xxx.xxx.xxx.xxx,xxx.xxx.xxx.xxx #IPs of all nodes in cluster
wsrep_cluster_name='mariadb_cluster'
wsrep_node_address='xxx.xxx.xxxx.xxx' #IP of node1
wsrep_sst_method=rsync
wsrep_sst_auth=cluster_user:password2
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0

[root@db1 ~]# galera_new_cluster

  • When running this bootstrap script mysql will be started automatically. If you restart mariadb/mysql the bootstrap will be lost and you will be stuck.

[root@db1 ~]# mysql -u root -ptest -e "show status like 'wsrep%'"

  • The output should show a lot of information about wsrep modules. One of which should show the number of nodes as one. At this point we are now working in node 2.
  • Node 2 is the same process with a few exceptions. you want to modify the wsrep_node_address= setting to reflect the address of node2. The other change is that we will not be running the bootstrap script, but instead start the mysql as usual.