MariaDB Galera Cluster in CentOS 7





How to install and config galera-cluster on centos 7 we have 3.
CLUSTER DETAILS
   galera-db01 - 192.168.1.1
   galera-db02 - 192.168.1.2
   galera-db03 - 192.168.1.3
 
Step 1: Remove mysql-server if had
#sudo yum erase mysql-server mysql mysql-devel mysql-libs
#sudo rm -rf /var/lib/mysql

Step 2: Add MariaDB Repositories
vim /etc/yum.repos.d/mariadb.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.0/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

Step 3: Disable selinux
sudo setenforce 0

On CentOS 7 you can install socat package with following command.

sudo yum install socat

Step 4: Install MariaDB Galera Cluster 10.0 software (both galera-db servers)
sudo yum -y install MariaDB-Galera-server MariaDB-client rsync galera

Step 5: Config MariaDB Security
sudo service mysql start
sudo /usr/bin/mysql_secure_installation

Step 6: Create MariaDB Galera Cluster User
#mysql -u root -p //mysql root password : dbpass
or #mysql -uroot -pdbpass
mysql -u root -p
mysql> DELETE FROM mysql.user WHERE user='';
mysql> GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY 'dbpass';
mysql> GRANT USAGE ON *.* to sst_user@'%' IDENTIFIED BY 'dbpass';
mysql> GRANT ALL PRIVILEGES on *.* to sst_user@'%';
mysql> FLUSH PRIVILEGES;
mysql> quit

Stop Mysql service
service mysql stop

Step 7: Config MariaDB Galera Cluster on galera-db01 ( 192.168.1.1)
vim /etc/my.cnf.d/server.cnf

[mariadb-10.0]binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
innodb_locks_unsafe_for_binlog=1
query_cache_size=0
query_cache_type=0
bind-address=0.0.0.0
datadir=/var/lib/mysql
innodb_log_file_size=100M
innodb_file_per_table
innodb_flush_log_at_trx_commit=2
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address="gcomm://192.168.1.1,192.168.1.2,192.168.1.3"
wsrep_cluster_name='galera_cluster'
wsrep_node_address='192.168.1.1'
wsrep_node_name='db1'
wsrep_sst_method=rsync
wsrep_sst_auth=sst_user:dbpass

Step 8: Add galera-db02 ( node 2 ) in MariaDB Cluster
[root@galera-db02 ~]# vim /etc/my.cnf.d/server.cnf

[mariadb-10.0]
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
innodb_locks_unsafe_for_binlog=1
query_cache_size=0
query_cache_type=0
bind-address=0.0.0.0
datadir=/var/lib/mysql
innodb_log_file_size=100M
innodb_file_per_table
innodb_flush_log_at_trx_commit=2
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address="gcomm://192.168.1.1,192.168.1.2,192.168.1.3"
wsrep_cluster_name='galera_cluster'
wsrep_node_address='192.168.1.2'
wsrep_node_name='db2'
wsrep_sst_method=rsync
wsrep_sst_auth=sst_user:dbpass

Step 9: Add galera-db03 ( node 3 ) in MariaDB Cluster
[root@galera-db03 ~]# vim /etc/my.cnf.d/server.cnf

[mariadb-10.0]
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
innodb_locks_unsafe_for_binlog=1
query_cache_size=0
query_cache_type=0
bind-address=0.0.0.0
datadir=/var/lib/mysql
innodb_log_file_size=100M
innodb_file_per_table
innodb_flush_log_at_trx_commit=2
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address="gcomm://192.168.1.1,192.168.1.2,192.168.1.3"
wsrep_cluster_name='galera_cluster'
wsrep_node_address='192.168.1.3'
wsrep_node_name='db2'
wsrep_sst_method=rsync
wsrep_sst_auth=sst_user:dbpass

Step 10: Startup mysql on galera-db03
[root@galera-db02 ~]# /etc/init.d/mysql stop

Step 11: Start MariaDB cluster on galera-db01
[root@galera-db01 ~]# sudo /etc/init.d/mysql start --wsrep-new-cluster

Step 12: Checking result on galera-db01
[root@galera-db01 ~]# mysql -u root -p -e "show status like 'wsrep%'"




Step 13: Start the services with normal command on node 2
[root@galera-db02 ~]# sudo service mysql start
[root@galera-db02 ~]# mysql -u root -p -e "show status like 'wsrep%'"

Step 14: Start the services with normal command on node 3
[root@galera-db03 ~]# sudo service mysql start
[root@galera-db03 ~]# mysql -u root -p -e "show status like 'wsrep%'"




Step 15: Testing DB replication
+ On galera-db01 create db and table
[root@galera-db01 ~]# mysql -uroot -p
MariaDB [(none)]> CREATE DATABASE clustertest;
MariaDB [(none)]> USE clustertest;
MariaDB [clustertest]> CREATE TABLE employees(number int, name varchar(50));
MariaDB [clustertest]> INSERT INTO employees values(1,'NGUYEN HOANG NAM');
MariaDB [clustertest]> SELECT * FROM employees;

+ On galera-db02
[root@galera-db02 ~]# mysql -uroot -p
MariaDB [(none)]> USE clustertest;
MariaDB [clustertest]> SELECT * FROM employees;

Step 16: Power off or kill -9 mysql_pid galera-db01 and on galera-db02 insert value to employees table
MariaDB [clustertest]> INSERT INTO employees values(2,'Mani');
Query OK, 1 row affected (0.13 sec)

Step 17: Power on or startup mysql service galera-db01 and checking
[root@galera-db02 ~]# mysql -uroot -p
MariaDB [(none)]> USE clustertest;
MariaDB [clustertest]> SELECT * FROM employees;

Now we finished the installation and config galera cluster on centos 7.

No comments:
Write comments

Please do not enter spam links

Meet US

Services

More Services