MySQL InnoDB Cluster – Quick Guide

Modern database engines like MongoDB provide built-in cluster solutions, making deployment simpler. While MySQL offers clustering products such as MySQL HA and MySQL NDB Cluster, the widely-used InnoDB engine lacked this capability for some time. Recently, MySQL introduced the InnoDB Cluster, allowing users to establish clusters that can handle node outages effectively.

MySQL also provides tools like MySQL-shell and MySQL-router to streamline management.

Initial Setup Tasks

To create a MySQL cluster, three hosts are required. Depending on the host setup, some preliminary tasks must be completed. For clarity, this example will use three virtual machines labeled MySQL-rep-1, MySQL-rep-2, and MySQL-rep-3, all running on the RH7 operating system. Each host will undergo the following initial configuration steps.

Step 1: Verify Hostnames

Each host in the cluster must resolve the hostname to an IP address that is not a loopback address. Editing the /etc/hosts file and removing loopback entries is recommended. Add an entry for each cluster host. Example configurations are shown below:

Initial /etc/hosts Configuration
127.0.0.1 mysql-rep-1
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

After editing, your /etc/hosts file should look like this:

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.11.122 mysql-rep-1
172.16.11.71 mysql-rep-2
172.16.11.204 mysql-rep-3
Note: This setup is intended for testing. Production environments should use DNS or a similar solution for hostname resolution.

Step 2: Disable SELinux

For smooth communication between nodes in a controlled environment, disable SELinux and the firewall. This can be achieved with the following commands:

# systemctl disable firewalld
# Edit /etc/selinux/config and set SELINUX=disabled
# Reboot the host

Component Installation

Each host requires several MySQL components. Follow these steps to install the necessary packages.

Install the MySQL YUM Repository

First, download and install the MySQL YUM repository RPM:

# rpm -ivh mysql80-community-release-el7-1.noarch.rpm

Install MySQL Components

Using yum, install MySQL-community-server, MySQL-community-client, and MySQL-shell:

# yum update
# yum install mysql-community-server mysql-community-client mysql-shell

Update the Root Password

After installation, start MySQL-server and retrieve the temporary password:

# service mysqld start
# grep 'temporary password' /var/log/mysqld.log

Log into MySQL using the temporary password and update it to a strong password following MySQL’s password policy.

Configuring the Cluster Nodes

With MySQL-shell, configure each node to be ready for clustering:

  1. Start MySQL-shell.
  2. Use dba.configureLocalInstance() to verify and configure each node.
  3. MySQL-shell can automatically configure compatible versions (MySQL 8.0.x) for clustering.
# mysqlsh
> dba.configureLocalInstance('root@localhost:3306', {clusterAdmin: "'icadmin'@'%'", clusterAdminPassword: 'icadminPassw0rd!'});

Creating and Managing the Cluster

Step 1: Create the Seed Instance

To initiate the cluster, designate MySQL-rep-1 as the seed node:

> shell.connect('icadmin@mysql-rep-1:3306');
> var cluster = dba.createCluster('testCluster');

Step 2: Adding Additional Instances

With the seed instance active, add MySQL-rep-2 and MySQL-rep-3 as replicas:

> cluster.addInstance('icadmin@mysql-rep-2:3306');
> cluster.addInstance('icadmin@mysql-rep-3:3306');

To check the cluster status, use:

> cluster.status();

Testing

Once the cluster is live, log into each instance as root and verify that all instances reflect changes made on the R/W node (MySQL-rep-1). Here’s a quick example:

mysql-rep-1> create database testdb;
mysql-rep-1> use testdb;
mysql-rep-1> create table test_table (c1 integer primary key);
mysql-rep-1> insert into test_table (c1) values (1);

Run a SELECT query on each node to confirm the replication.

Conclusion

With your MySQL InnoDB cluster configured, you can treat it as a standard MySQL instance. Remember, only designated R/W nodes can handle write operations, while R/O nodes receive replication updates. MySQL InnoDB Cluster supports automatic failover, electing a new R/W node if the primary fails. MySQL-router can facilitate automatic failover handling for applications, a feature detailed in an upcoming post.

,
Previous Post
Prerequisites – Key Issues in IT Projects Execution
Next Post
DHCP: Differences With and Without Relay Agent

You must be logged in to post a comment.
Menu