Before we install the software we need to set up the MariaDB repository on all 4 servers:<\/p>\n
$ curl -sS https:\/\/downloads.mariadb.com\/MariaDB\/mariadb_repo_setup | sudo bash<\/pre>\nHaving 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:<\/p>\n
$ sudo yum -y install MariaDB-server<\/pre>\nWhen 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 :<\/p>\n
$ sudo yum -y install maxscale<\/pre>\nWe 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<\/p>\n
$ sudo yum -y install MariaDB-client<\/pre>\nConfiguring MariaDB Galera Cluster \u00a0<\/span><\/h1>\nIn 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,\u00a0We have to edit the file \/etc\/my.cnf.d\/server.cnf<\/em> 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:<\/p>\n[galera]\r\n# Mandatory settings\r\nwsrep_on=ON\r\nwsrep_provider=\/usr\/lib64\/galera\/libgalera_smm.so\r\nwsrep_cluster_address=gcomm:\/\/192.168.56.101,192.168.56.102,192.168.56.103\r\nbinlog_format=row\r\ndefault_storage_engine=InnoDB\r\ninnodb_autoinc_lock_mode=2<\/pre>\n<\/span>Starting MariaDB Galera Cluster<\/span><\/h2>\nTo 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:<\/p>\n
$ sudo galera_new_cluster<\/pre>\nConfirm MariaDB is running successfully:<\/p>\n
$ ps -f -u mysql | more\r\nUID PID PPID C STIME TTY TIME CMD\r\nmysql 1411 1 0 18:33 ? 00:00:00 \/usr\/sbin\/mysqld --wsrep-new-cluster --wsrep_start_position=00000000-0000-0000-0000-000000000000:-1<\/pre>\nConfirm the status of Galera Cluster:<\/p>\n
$ mysql -u root\r\nWelcome to the MariaDB monitor. Commands end with ; or g.\r\nYour MariaDB connection id is 10\r\nServer version: 10.3.15-MariaDB MariaDB Server\r\n \r\nCopyright (c) 2000, 2019, Oracle, MariaDB Corporation Ab and others.\r\n \r\nType 'help;' or 'h' for help. Type 'c' to clear the current input statement.\r\n \r\nMariaDB [(none)]> show global status like 'wsrep_cluster_size';\r\n+--------------------+-------+\r\n| Variable_name | Value |\r\n+--------------------+-------+\r\n| wsrep_cluster_size | 1 |\r\n+--------------------+-------+\r\n1 row in set (0.00 sec)<\/pre>\n<\/span>Start MariaDB instance \u00a0in 192.168.56.102<\/span><\/h3>\n$ sudo systemctl start mariadb.service<\/pre>\nWe should now have 2 nodes running in the cluster, let\u2019s check it out from the MariaDB command line on 192.168.56.101:<\/p>\n
MariaDB [(none)]> show global status like 'wsrep_cluster_size';\r\n+--------------------+-------+\r\n| Variable_name | Value |\r\n+--------------------+-------+\r\n| wsrep_cluster_size | 2 |\r\n+--------------------+-------+\r\n1 row in set (0.00 sec)<\/pre>\n<\/span>Start MariaDB instances in 192.168.56.103<\/span><\/h3>\n$ sudo systemctl start mariadb.service<\/pre>\nCheck the cluster size on 192.168.56.101 again:<\/p>\n
MariaDB [(none)]> show global status like 'wsrep_cluster_size';\r\n+--------------------+-------+\r\n| Variable_name | Value |\r\n+--------------------+-------+\r\n| wsrep_cluster_size | 3 |\r\n+--------------------+-------+\r\n1 row in set (0.00 sec)<\/pre>\nThe wsrep_cluster_size is 3 , So have successfully added all the three nodes to the Galera Cluster<\/p>\n
<\/span>Configuring MariaDB for MariaDB MaxScale<\/span><\/h3>\nFirst 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:<\/p>\n
$ mysql -u root\r\nWelcome to the MariaDB monitor. Commands end with ; or g.\r\nYour MariaDB connection id is 11\r\nServer version: 10.3.15-MariaDB MariaDB Server\r\n \r\nCopyright (c) 2000, 2019, Oracle, MariaDB Corporation Ab and others.\r\n \r\nType 'help;' or 'h' for help. Type 'c' to clear the current input statement.\r\n \r\nMariaDB [(none)]> create user 'dbuser1'@'192.168.56.104' identified by 'My@PAssword';\r\nQuery OK, 0 rows affected (0.01 sec)\r\n \r\nMariaDB [(none)]> grant select on mysql.user to 'dbuser1'@'192.168.56.104';\r\nQuery OK, 0 rows affected (0.01 sec)<\/pre>\nwe need some extra privileges for table and database level grants:<\/p>\n
MariaDB [(none)]> grant select on mysql.db to 'dbuser1'@'192.168.56.104';\r\nQuery OK, 0 rows affected (0.01 sec)\r\n \r\nMariaDB [(none)]> grant select on mysql.tables_priv to 'dbuser1'@'192.168.56.104';\r\nQuery OK, 0 rows affected (0.00 sec)\r\n \r\nMariaDB [(none)]> grant show databases on *.* to 'dbuser1'@'192.168.56.104';\r\nQuery OK, 0 rows affected (0.00 sec)<\/pre>\n<\/span>MariaDB MaxScale Configuration<\/span><\/h3>\nMariaDB \u00a0MaxScale configure file is located in \/etc\/maxscale.cnf \u00a0.\u00a0<\/em>we have copied below the “MaxScale.cnf<\/strong>” used in our lab:<\/p>\n# Globals\r\n[maxscale]\r\nthreads=1\r\n \r\n# Servers\r\n[server1]\r\ntype=server\r\naddress=192.168.56.101\r\nport=3306\r\nprotocol=MySQLBackend\r\n \r\n[server2]\r\ntype=server\r\naddress=192.168.56.102\r\nport=3306\r\nprotocol=MySQLBackend\r\n \r\n[server3]\r\ntype=server\r\naddress=192.168.56.103\r\nport=3306\r\nprotocol=MySQLBackend\r\n \r\n# Monitoring for the servers\r\n[Galera Monitor]\r\ntype=monitor\r\nmodule=galeramon\r\nservers=server1,server2,server3\r\nuser=dbuser1\r\npasswd=My@PAssword\r\nmonitor_interval=1000\r\n \r\n# Galera router service\r\n[Galera Service]\r\ntype=service\r\nrouter=readwritesplit\r\nservers=server1,server2,server3\r\nuser=dbuser1\r\npasswd=My@PAssword\r\n \r\n# MaxAdmin Service\r\n[MaxAdmin Service]\r\ntype=service\r\nrouter=cli\r\n \r\n# Galera cluster listener\r\n[Galera Listener]\r\ntype=listener\r\nservice=Galera Service\r\nprotocol=MySQLClient\r\nport=3306\r\n \r\n# MaxAdmin listener\r\n[MaxAdmin Listener]\r\ntype=listener\r\nservice=MaxAdmin Service\r\nprotocol=maxscaled\r\nsocket=default<\/pre>\nStarting MariaDB MaxScale<\/strong><\/p>\n$ sudo systemctl start maxscale.service<\/pre>\nConnecting to MariaDB Galera Cluster from MariaDB MaxScale:<\/strong><\/p>\n$ mysql -h 192.168.56.104 -u dbuser1 -pMy@PAssword\r\nWelcome to the MariaDB monitor. Commands end with ; or g.\r\nYour MySQL connection id is 4668\r\nServer version: 10.0.0 3.1.5-maxscale MariaDB Server\r\n \r\nCopyright (c) 2000, 2019, Oracle, MariaDB Corporation Ab and others.\r\n \r\nType 'help;' or 'h' for help. Type 'c' to clear the current input statement.\r\n \r\nMySQL [(none)]><\/pre>\nYou 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:<\/p>\n
MySQL [(none)]> show variables like 'hostname';\r\n+---------------+---------+\r\n| Variable_name | Value |\r\n+---------------+---------+\r\n| hostname | node101 |\r\n+---------------+---------+\r\n1 row in set (0.00 sec)<\/pre>\nlet\u2019s stop MariaDB server on 192.168.56.101 and see what happens. On 192.168.56.101 run the following command:<\/p>\n
$ sudo systemctl stop mariadb.service<\/pre>\nNow login from MariaDB MaxScale command prompt and check which MariaDB instance are we connecting to:<\/p>\n
$ mysql -h 192.168.56.104 -u dbuser1 -pMy@PAssword\r\nWelcome to the MariaDB monitor. Commands end with ; or g.\r\nYour MySQL connection id is 4668\r\nServer version: 10.0.0 2.1.5-maxscale MariaDB Server\r\n \r\nCopyright (c) 2000, 2019, Oracle, MariaDB Corporation Ab and others.\r\n \r\nType 'help;' or 'h' for help. Type 'c' to clear the current input statement.\r\n \r\nMySQL [(none)]> show variables like 'hostname';\r\n+---------------+---------+\r\n| Variable_name | Value |\r\n+---------------+---------+\r\n| hostname | node102 |\r\n+---------------+---------+\r\n1 row in set (0.00 sec)<\/pre>\nWe are connecting to “node102” (192.168.56.102<\/strong>) because “node1” (192.168.56.101) is not available<\/p>\n