How to install and configure Galera MySQL cluster on CentOS 7
To install and configure Galera MySQL Cluster on CentOS 7
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. In this tutorial am going install and configure Mariadb cluster 10.0 with 3 nodes on centos 7.
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
Before you begin with the configuration, make sure do the following steps :-
1. Disable the Selinux service.
2. Disable the firewall service.
Cluster details
Node1 192.168.7.211
Node2 192.168.7.212
Node3 192.168.7.213
Configuring Galera
Remove defaults MariaDB library files for all the three nodes
[root@server1 ~]# yum remove mariadb-libs -y
Once it is removed, create the MariaDB repository file for all three nodes as follows.
[root@server1 ~]# vim /etc/yum.repos.d/cluster.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.0/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
Now, install socat dependency package in all the 3 nodes. Use the following command for the same purpose.
[root@server1 ~]# yum install socat
Now is the time to install MariaDB Galera cluster 10.0 and its dependencies packages for all the nodes.
[root@server1 ~]# yum install MariaDB-Galera-server MariaDB-client rsync galera
Once it is installed, start the MariaDB services
[root@server1 ~]# systemctl start msyql
Execute the following commad to set MariaDB root login credential.
[root@server1 ~]# mysql_secure_installation
Now you can stop MariaDB service by running the following command. Do the same for all the three nodes.
[root@server1 ~]# systemctl stop msyql
You can now go on with Galera cluster configuration by adding the cluster address, cluster name, node address, etc. Don' t forget to do the same for the other two nodes as well.
[root@server1 ~]# 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.7.211,192.168.7.212,192.168.7.213"
wsrep_cluster_name=' galera_cluster'
wsrep_node_address=' 192.168.7.211'
wsrep_node_name=' node1'
wsrep_sst_method=rsync
wsrep_sst_auth=db_user:admin
For configuring this cluster configuration on node2 and node3 do not forget to adjust the wsrep_node_address and wsrep_node_name variables. Before doing this steps stop the mysql service on both nodes.
For node2:
wsrep_node_address=' 192.168.7.212' wsrep_node_name=' node2'
For db3
wsrep_node_address=' 192.168.7.213' wsrep_node_name=' node3'
Once all the nodes are configured, you can start first cluster node.
This command should be executed only on node1.
[root@server1 ~]# /etc/init.d/mysql start &ndash wsrep-new-cluster
After that, sart MySQL service on both node2 and node3 as well. Run the following command on both the remaining nodes.
[root@server1 ~]# systemctl start mysql
Now check the status of configured galera cluster at node1. Repeat this command on node2 and node3 to check
# mysql
MariaDB [(none)]> show status like ' wsrep%'
| wsrep_incoming_addresses | 192.168.7.212:3306,192.168.7.211:3306,192.168.7.213:3306
| wsrep_local_state_comment | Synced
| wsrep_cluster_size | 3
| wsrep_ready | ON
Now, you can check replication process by creating a database from node1.
> mysql > create database sample1_db > show schema +--------------------+ | Database | +--------------------+ | sample1_db | | information_schema | | mysql | | performance_schema | +--------------------+
After that login mysql into node2 and check the replication process there too.
> show schemas +--------------------+ | Database | +--------------------+ | sample1_db | | | |information_schema | | mysql | | performance_schema | +--------------------+
Login mysql into node3 and check the replication process in it as well.
> schow schemas +----------------------------+ | Database | +----------------------------+ | sample1_db | | | |information_schema | | mysql | | performance_schema | +----------------------------+
If you want to test more repilcatiom proess create a table and insert the values into that DB.
Node1
MariaDB [sample1_db]> create table os(categories(char(25))) MariaDB [sample1_db]> insert into os values(' Linux' ) MariaDB [sample1_db]> select * from os +----------------+ | categories | +---------------+ | Linux | +----------------+
Node2
MariaDB [sample1_db]> insert into os values(" MAC" ) Query OK, 1 row affected (0.02 sec) MariaDB [sample1_db]> select * from os +--------------+ | categories | +--------------+ | Linux | | MAC | +--------------+
Node3
MariaDB [sample1_db]> insert into os values(' Windows' ) Query OK, 1 row affected (0.00 sec) MariaDB [sample1_db]> select * from os +---------------+ | categories | +---------------+ | Linux | | MAC | | Windows | +---------------+
Comments ( 0 )
No comments available