Step-by-step installation and configuration of 3 node MariaDB Galera Cluster and MariaDB MaxScale on CentOS
This blog is aimed to help anyone who is interested in setting-up 3 node MariaDB Galera Cluster with MariaDB MaxScale for building highly available / reliable, fault-tolerant and self-healing MariaDB infrastructure operations. We have not tried to explain MariaDB Galera Cluster and MariaDB MaxScale Architecture or internals in this post. MariaDB documentation on both MariaDB Galera Cluster and MariaDB MaxScale is neat and direct , You can read the same here – https://mariadb.com/kb/en/library/galera-cluster/ (MariaDB Galera Cluster) and https://mariadb.com/kb/en/mariadb-maxscale-20-setting-up-mariadb-maxscale/ (MariaDB MaxScale). If you are building maximum availability Database Infrastructure Operations on MariaDB stack, it’s worth investing and exploring MariaDB Galera Cluster and MariaDB MaxScale.
Our lab for building highly available and fault-tolerant MariaDB Ops. using 3 node MariaDB Galera Cluster and MariaDB MaxScale
We have 3 nodes MariaDB Galera Cluster and 1 node for MariaDB MaxScale
Nodes | IP address |
---|---|
MariaDB Galera Cluster Node 1 | 192.168.56.101 |
MariaDB Galera Cluster Node 2 | 192.168.56.102 |
MariaDB Galera Cluster Node 3 | 192.168.56.103 |
MariaDB MaxScale | 192.168.56.104 |
LINUX Configuration
Disable SELinux and the Linux firewall (which is firewalld in CentOS and RedHat 7.0 and up, and not iptables) and also set the hostname.
Disable SELinux
We recommend disabling SELinux unless your IT security demands SELinux, You disable / enable SELinux through the file /etc/selinux/config, looks something like this:
# This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=disabled # SELINUXTYPE= can take one of these two values: # targeted - Targeted processes are protected, # minimum - Modification of targeted policy. Only selected processes are protected. # mls - Multi Level Security protection. SELINUXTYPE=targeted
Disable firewalld
Firewalld is a standard service that is disabled using the systemctl command:
$ sudo systemctl disable firewalld
Configuring hostname
We recommend configuring hostname to tell which server you are connecting to when using MariaDB MaxScale, Please follow the steps appropriately for your infrastructure / IP:
$ sudo hostname node101
MariaDB Repository Installation
Before we install the software we need to set up the MariaDB repository on all 4 servers:
$ curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
Having run this on the four servers, let us now go on with installing MariaDB Galera server on the three nodes where this is appropriate, in the case here we are looking at nodes 192.168.56.101, 192.168.56.102 and 192.168.56.103 On these three nodes run this:
$ sudo yum -y install MariaDB-server
When this is completed, we should have MariaDB Server installed. The next thing to do then is to install MariaDB MaxScale on the instance 192.168.56.104 :
$ sudo yum -y install maxscale
We recommend our customers to install MariaDB client programs on the MariaDB MaxScale instance (192.168.56.104) for good reasons, Though there are blogs which says it’s optional
$ sudo yum -y install MariaDB-client
Configuring MariaDB Galera Cluster
In this blog we are only mentioning about the minimal settings to make MariaDB Galera Cluster working with MariaDB MaxScale, Here we are not talking about how to make MariaDB Galera Cluster optimal and Scalable, The settings below make MariaDB Galera Cluster fully operational, We have to edit the file /etc/my.cnf.d/server.cnf and we have to adjust the Galera specific settings on the nodes 192.168.56.101, 192.168.56.102 and 192.168.56.103. Edit the [galera] section to look like this on all three nodes:
[galera] # Mandatory settings wsrep_on=ON wsrep_provider=/usr/lib64/galera/libgalera_smm.so wsrep_cluster_address=gcomm://192.168.56.101,192.168.56.102,192.168.56.103 binlog_format=row default_storage_engine=InnoDB innodb_autoinc_lock_mode=2
Starting MariaDB Galera Cluster
To start a Galera Cluster from scratch we run a process called a bootstrap, and the reason this is a bit different from the usual MariaDB startup is that for HA reasons a node in a cluster attaches to one or more other nodes in the cluster, but for the first node, this is not possible. This is not complicated though, there is a script that is included with MariaDB Server that manages this, but remember that this script is only to be used when the first node in a Cluster is started with no existing nodes in it. In this case, on 192.168.56.101 run:
$ sudo galera_new_cluster
Confirm MariaDB is running successfully:
$ ps -f -u mysql | more UID PID PPID C STIME TTY TIME CMD mysql 1411 1 0 18:33 ? 00:00:00 /usr/sbin/mysqld --wsrep-new-cluster --wsrep_start_position=00000000-0000-0000-0000-000000000000:-1
Confirm the status of Galera Cluster:
$ mysql -u root Welcome to the MariaDB monitor. Commands end with ; or g. Your MariaDB connection id is 10 Server version: 10.3.15-MariaDB MariaDB Server Copyright (c) 2000, 2019, Oracle, MariaDB Corporation Ab and others. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. MariaDB [(none)]> show global status like 'wsrep_cluster_size'; +--------------------+-------+ | Variable_name | Value | +--------------------+-------+ | wsrep_cluster_size | 1 | +--------------------+-------+ 1 row in set (0.00 sec)
Start MariaDB instance in 192.168.56.102
$ sudo systemctl start mariadb.service
We should now have 2 nodes running in the cluster, let’s check it out from the MariaDB command line on 192.168.56.101:
MariaDB [(none)]> show global status like 'wsrep_cluster_size'; +--------------------+-------+ | Variable_name | Value | +--------------------+-------+ | wsrep_cluster_size | 2 | +--------------------+-------+ 1 row in set (0.00 sec)
Start MariaDB instances in 192.168.56.103
$ sudo systemctl start mariadb.service
Check the cluster size on 192.168.56.101 again:
MariaDB [(none)]> show global status like 'wsrep_cluster_size'; +--------------------+-------+ | Variable_name | Value | +--------------------+-------+ | wsrep_cluster_size | 3 | +--------------------+-------+ 1 row in set (0.00 sec)
The wsrep_cluster_size is 3 , So have successfully added all the three nodes to the Galera Cluster
Configuring MariaDB for MariaDB MaxScale
First we need to set up a user that MariaDB MaxScale use to attach to the cluster to get authentication data. On 192.168.56.101, using the MariaDB command line as the database root user:
$ mysql -u root Welcome to the MariaDB monitor. Commands end with ; or g. Your MariaDB connection id is 11 Server version: 10.3.15-MariaDB MariaDB Server Copyright (c) 2000, 2019, Oracle, MariaDB Corporation Ab and others. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. MariaDB [(none)]> create user 'dbuser1'@'192.168.56.104' identified by 'My@PAssword'; Query OK, 0 rows affected (0.01 sec) MariaDB [(none)]> grant select on mysql.user to 'dbuser1'@'192.168.56.104'; Query OK, 0 rows affected (0.01 sec)
we need some extra privileges for table and database level grants:
MariaDB [(none)]> grant select on mysql.db to 'dbuser1'@'192.168.56.104'; Query OK, 0 rows affected (0.01 sec) MariaDB [(none)]> grant select on mysql.tables_priv to 'dbuser1'@'192.168.56.104'; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> grant show databases on *.* to 'dbuser1'@'192.168.56.104'; Query OK, 0 rows affected (0.00 sec)
MariaDB MaxScale Configuration
MariaDB MaxScale configure file is located in /etc/maxscale.cnf . we have copied below the “MaxScale.cnf” used in our lab:
# Globals [maxscale] threads=1 # Servers [server1] type=server address=192.168.56.101 port=3306 protocol=MySQLBackend [server2] type=server address=192.168.56.102 port=3306 protocol=MySQLBackend [server3] type=server address=192.168.56.103 port=3306 protocol=MySQLBackend # Monitoring for the servers [Galera Monitor] type=monitor module=galeramon servers=server1,server2,server3 user=dbuser1 passwd=My@PAssword monitor_interval=1000 # Galera router service [Galera Service] type=service router=readwritesplit servers=server1,server2,server3 user=dbuser1 passwd=My@PAssword # MaxAdmin Service [MaxAdmin Service] type=service router=cli # Galera cluster listener [Galera Listener] type=listener service=Galera Service protocol=MySQLClient port=3306 # MaxAdmin listener [MaxAdmin Listener] type=listener service=MaxAdmin Service protocol=maxscaled socket=default
Starting MariaDB MaxScale
$ sudo systemctl start maxscale.service
Connecting to MariaDB Galera Cluster from MariaDB MaxScale:
$ mysql -h 192.168.56.104 -u dbuser1 -pMy@PAssword Welcome to the MariaDB monitor. Commands end with ; or g. Your MySQL connection id is 4668 Server version: 10.0.0 3.1.5-maxscale MariaDB Server Copyright (c) 2000, 2019, Oracle, MariaDB Corporation Ab and others. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. MySQL [(none)]>
You can see that we are connected to MariaDB MaxScale now, but which server in the MariaDB Galera Cluster we are connected to? Let’s confirm that now:
MySQL [(none)]> show variables like 'hostname'; +---------------+---------+ | Variable_name | Value | +---------------+---------+ | hostname | node101 | +---------------+---------+ 1 row in set (0.00 sec)
let’s stop MariaDB server on 192.168.56.101 and see what happens. On 192.168.56.101 run the following command:
$ sudo systemctl stop mariadb.service
Now login from MariaDB MaxScale command prompt and check which MariaDB instance are we connecting to:
$ mysql -h 192.168.56.104 -u dbuser1 -pMy@PAssword Welcome to the MariaDB monitor. Commands end with ; or g. Your MySQL connection id is 4668 Server version: 10.0.0 2.1.5-maxscale MariaDB Server Copyright (c) 2000, 2019, Oracle, MariaDB Corporation Ab and others. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. MySQL [(none)]> show variables like 'hostname'; +---------------+---------+ | Variable_name | Value | +---------------+---------+ | hostname | node102 | +---------------+---------+ 1 row in set (0.00 sec)
We are connecting to “node102” (192.168.56.102) because “node1” (192.168.56.101) is not available
Conclusion
To conclude this post we have successfully installed and configured 3 node MariaDB Galera Cluster with single node MariaDB MaxScale.
The post Installation and configuration of 3 node MariaDB Galera Cluster and MariaDB MaxScale on CentOS appeared first on MySQL Consulting, Support and Remote DBA Services.