Difference between revisions of "Galera Cluster Setup"

From Michael's Information Zone
Jump to navigation Jump to search
 
(2 intermediate revisions by the same user not shown)
Line 7: Line 7:
 
<br>
 
<br>
 
==CentOS 7==
 
==CentOS 7==
First off, MariaDB now has Galera baked in so make sure to install the latest stable version.
+
First off, MariaDB now has Galera baked in so make sure to install the latest stable version.<br>
[root@db1 ~]# yum autoremove mariadb mariadb-server
+
[root@db1 ~]# yum autoremove mariadb mariadb-server<br>
[root@db1 ~]# nano /etc/yum.repos.d/mariadb.repo
+
[root@db1 ~]# nano /etc/yum.repos.d/mariadb.repo<br>
 
<pre>
 
<pre>
 
[mariadb]
 
[mariadb]
Line 17: Line 17:
 
gpgcheck=1
 
gpgcheck=1
 
</pre>
 
</pre>
[root@db1 ~]# yum install MariaDB-server MariaDB-client
+
[root@db1 ~]# yum install MariaDB-server MariaDB-client<br>
[root@db1 ~]# systemctl start mysql
+
[root@db1 ~]# systemctl start mysql<br>
[root@db1 ~]# mysql_secure_installation
+
[root@db1 ~]# mysql_secure_installation<br>
*Create a root password and accept all other defaults. Later we will create the user account that will allow replication.
+
*Create a root password and accept all other defaults. Later we will create the user account that will allow replication.<br>
[root@db1 ~]# mysql -uroot -p
+
[root@db1 ~]# mysql -uroot -p<br>
 
<pre>
 
<pre>
 
MariaDB [(none)]> grant all on *.* to 'root'@'%' identified by 'password';
 
MariaDB [(none)]> grant all on *.* to 'root'@'%' identified by 'password';
Line 28: Line 28:
 
MariaDB [(none)]> flush privileges;
 
MariaDB [(none)]> flush privileges;
 
MariaDB [(none)]> exit
 
MariaDB [(none)]> exit
[root@db1 ~]# systemctl stop mysql
+
</pre>
[root@db1 ~]# nano /etc/my.cnf.d/server.cnf
+
[root@db1 ~]# systemctl stop mysql<br>
 +
*At this time go ahead and allow the ports needed
 +
[root@db1 ~]#
 +
*Configure Galera settings
 +
[root@db1 ~]# nano /etc/my.cnf.d/server.cnf<br>
 
<pre>
 
<pre>
 
#
 
#
Line 37: Line 41:
 
wsrep_on=ON
 
wsrep_on=ON
 
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
 
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address=gcomm://10.200.3.2,10.200.3.3
+
wsrep_cluster_address=gcomm://xxx.xxx.xxx.xxx,xxx.xxx.xxx.xxx #IPs of all nodes in cluster
 
wsrep_cluster_name='mariadb_cluster'
 
wsrep_cluster_name='mariadb_cluster'
wsrep_node_address='10.200.3.2'
+
wsrep_node_address='xxx.xxx.xxxx.xxx' #IP of node1
 
wsrep_sst_method=rsync
 
wsrep_sst_method=rsync
wsrep_sst_auth=cluseruser:test
+
wsrep_sst_auth=cluster_user:password2
 
binlog_format=row
 
binlog_format=row
 
default_storage_engine=InnoDB
 
default_storage_engine=InnoDB
Line 47: Line 51:
 
bind-address=0.0.0.0
 
bind-address=0.0.0.0
 
</pre>
 
</pre>
[root@db1 ~]#
+
[root@db1 ~]# galera_new_cluster<br>
[root@db1 ~]#
+
*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 ~]#
+
[root@db1 ~]# mysql -u root -ptest -e "show status like 'wsrep%'"
[root@db1 ~]#
+
*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.
[root@db1 ~]#
+
*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.

Latest revision as of 08:33, 4 August 2016

  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

  • At this time go ahead and allow the ports needed

[root@db1 ~]#

  • Configure Galera settings

[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.