How To Install and Configure Innodb Cluster /shell/Router

 InnoDB Cluster

InnoDB Cluster = MySQL Server + MySQL Shell + MySQL Router 

MySQL InnoDB has three major components:

1. MySQL group replication :– 

It is a group of database servers. It replicates the MySQL databases across the multiple nodes, and it
has fault tolerance. When changes in the data occur in the MySQL databases, it automatically replicates to the secondary nodes of the server. The concept of the MySQL group replication is similar to the concept of the AlwaysOn availability group.

2. MySQL Router: – 

When a failover occurs, the client application must be aware of the PRIMARY instance and cluster topology. This functionality is handled by the MySQL Router. It routes that redirects the data requests to the available MySQL Server instance.MySQL Router acts as a proxy that is used to hide the multiple MySQL database servers. The concept of the MySQL Router is similar to the Virtual network name of the Windows Server failover cluster.

3. MySQL Shell :– 

It is a configuration tool that can be used to connect, deploy, and manage the MySQL InnoDB cluster. MySQL Shell contains an Admin API that has a dba global variable. The dba variable is used to deploy and manage the InnoDB cluster.

Features of InnoDB Cluster :

 Distinct Primary or Multiple Primary Modes:-

It means that the cluster can control either with only a writer and more than one reader, the default setup and recommended one, or with more than one writer where entire nodes can admit write transactions. Due to the conflict firmness, the latter is provided at the cost of a performance penalty.

 Spontaneous Failure Recognition:-

Here, an internal component can detect a failed node which can be either a crash or any network problems and also agrees to eliminate it from the cluster mechanically. Suppose a member does not connect with the cluster and gets inaccessible; it will not receive transactions. This assures that this type of situation has not obstructed the cluster data.

 Fault Tolerance:-

It defines the strategy which the cluster implements to maintain failing members. Since it is also based on the majority kept by the other two members, whereas a cluster requires three members to support one node. If there is a larger number of nodes, then there will also be a larger number of failing nodes supported by the cluster. In a cluster, the number of members or nodes is presently restricted to 7, where four or more active nodes store the majority. We can say that a cluster of seven will support and maintain up to three failing nodes


InnoDB Cluster Installation and Configuration

1. Installation of MySQL Server and MySQL Shell on all the MySQL

machines :

> yum install mysql-server;

> yum install mysql-shell;

2. To map the domain address with IP Address, we must edit the

hosts file. On Linux, the file is in /etc directory. The full path is

/etc/hosts. The entries in the hosts file are in the following format:

> vi /etc/hosts

192.168.xx.xx MYSQL-IDC-01

192.168.xx.xx MYSQL-IDC-02

192.168.xx.xx MYSQL-IDC-03

:wq

Similarly, we need to add these three lines on each server.

Check the ping using > ping MYSQL-IDC-02, all the machines should ping using

domain address.

3. Create the user and grant permission to all databases to connect

remotely with admin permission.

> CREATE USER 'db_user'@'%' IDENTIFIED BY 'Dbuser@123';

> GRANT ALL PRIVILEGES ON *.* TO 'db_user'@'%' WITH GRANT OPTION;

> flush privileges;

4. Configure the instance :

 On MYSQL-IDC-01 Host

> mysqlsh

MySQL JS > dba.configureInstance('db_user@MYSQL-IDC-01:3306')

 On MYSQL-IDC-02 Host

> mysqlsh

MySQL JS > dba.configureInstance('db_user@MYSQL-IDC-02:3306')

 On MYSQL-IDC-03 Host

> mysqlsh

MySQL JS > dba.configureInstance('db_user@MYSQL-IDC-03:3306')

5. Create an InnoDB Cluster :

Once you configured host for innodb cluster , next is to create cluster on

Master/First instance (MYSQL-IDC-01). Run below command to login mysql shell and

create cluster.

First login to MySQL Shell on MYSQL-IDC-01 instance.

> mysqlsh

> MySQL JS > shell.connect('db_user@MYSQL-IDC-01:3306')

Now create a cluster assigning the return value to a variable.

> MYSQL-IDC-01:3306+ ssl JS > var cluster =dba.createCluster('ProdCluster')

Next add MYSQL-IDC-02 and MYSQL-IDC-03 to ProdCluster. Run below commands

on MYSQL-IDC-01

MySQL JS > cluster.addInstance('fosstechnix@MYSQL-IDC-02:3306')

MySQL JS > cluster.addInstance('fosstechnix@MYSQL-IDC-03:3306')

6. Check the Cluster status :

> MYSQL-IDC-01:33060+ ssl JS > cluster.status()

Output:

cluster.status()

{

"clusterName": "ProdCluster",

"defaultReplicaSet": {

"name": "default",

"primary": "MYSQL-IDC-01:3306",

"ssl": "REQUIRED",

"status": "OK",

"statusText": "Cluster is ONLINE and can tolerate up to ONE failure.",

"topology": {

"MYSQL-IDC-01:3306": {

"address": "MYSQL-IDC-01:3306",

"mode": "R/W",

"readReplicas": {},

"role": "HA",

"status": "ONLINE",

"version": "8.0.17"

},

"MYSQL-IDC-02:3306": {

"address": "MYSQL-IDC-02:3306",

"mode": "R/O",

"readReplicas": {},

"role": "HA",

"status": "ONLINE",

"version": "8.0.17"

},

"MYSQL-IDC-03:3306": {

"address": "MYSQL-IDC-03:3306",

"mode": "R/O",

"readReplicas": {},

"role": "HA",

"status": "ONLINE",

"version": "8.0.17"

}

},

"topologyMode": "Single-Primary"

},

"groupInformationSourceMember": "MYSQL-IDC-01:3306"

}

Common error while configuring InnoDB :

 Access denied for user ‘db_user’@’hostname’, this error generally occurs when

mysql try to connect with DB using hostname.

To overcome this error change hostname of each DB server with the domain

address(step 2).

> hostnamectl set-hostname MYSQL-IDC-01

Need to run above command on all the DB machines to change the hostname.

By the help of above command host name will be changed, if not do the below steps :

> vi /etc/hostname

Haproxy_main

Change it to > MYSQL-IDC-01 and press :wq to save and exit the file.

Then reboot the machines, do these steps on all the DB servers one by one with each

hostname.

7. Installation and Configuration of MySQL router :

We have used separate server for MySQL routing purpose.

> yum install mysql-router

MySQL Router can be deployed using bootstrapping on a server using below

command :

> sudo mysqlrouter --bootstrap db_user@MYSQL-IDC-01:3306 --user=mysqlrouter

Then we have to start MySQL Router using below command,

> mysqlrouter &

To check it’s started and listening / accepting connections on port 6446.

> netstat -an | grep 6446

Output:

tcp 0 0 0.0.0.0:6446 0.0.0.0:* LISTEN

After that we will start mysqlrouter service by using below command :

> systemctl start mysqlrouter.service

Or

> systemctl start mysqlrouter

8. After successfully configuration of MySQL Router , below command

is connect to MySQL Servers/Clusters from application instance.

> mysql -h 127.0.0.1 --port 6446 -u db_user -p

Common errors may occur while installing and configuring mysqlrouter:

 Not able to start mysqlrouter service, this error occurs when selinux or firewall

service is enabled on the mysqlrouter server.

We should disable both selinux and firewall service on each machine (Routing and

DB machines) by using below commands :

> systemctl stop firewalld

> systemctl disable firewalld

> setenforce 0

Or

> vi /etc/selinux/config

SELINUX=disabled

:wq

> sudo reboot

Comments

Popular posts from this blog

MySQL Point in Time Recovery: How To Configure And How Does it Work?

MySQL Replication Switchover: Step-by-Step Guide

Mysql Commercial Mysqlbackup:How to take Differential or Incremental Backup and resotre using mysqlbackup utility in mysql 8.0.37 enterprise edition