Setup MySQL 8 Cluster on Ubuntu 16

MySQL Logo

In this article I am going to discuss how to setup a high availability MySQL Version 8 cluster running on Ubuntu 16.  In order to achieve this, my setup consisted of 4 virtual machines running on Vmware Workstation 15 with bridged networking and fresh installs of Ubuntu 16 configured with static IP addresses.

Install MySQL Server

The first part is to install MySQL server onto the 3 chosen virtual machines. You will need to perform the following on all 3 machines.

first add the MySQL repository and then configure it:

once the above commands have been entered, issue the below:

Configure Innodb Cluster

Configure the Bind-Address of the MySQL server (for each of the 3 virtual machines)

in this file you will need to add the bind-address this is the IP address of the virtual machine in question for example my IP for one of my Virtual machines was 192.168.178.56, once you have done this you will need to restart MySQL

Create a new MySQL admin user

you will need to do this on all 3 virtual machines,  we need to create a user that has all access privilesge to MySQL in the below example my user was called joe.

Hosts File

You now need to edit the hosts file on each of the 3 virtual machines,  in this hosts file you will need to add each of the 3 virtual machines IP and Name, you also need to remove the loopback address of 127.0.1.1 that Ubuntu creates.

Configure the Instance

In order to create and manage the cluster instance you can download the MySQL Shell at the following location:  https://dev.mysql.com/downloads/shell/

I downloaded the zip version for Windows 10 which does not need to be installed. once opened you will need to connect to the instance that will be your primary one.

The above is an example and you will need to change to your details accordingly,  you will be prompted for the password,  if all being well you will be preseneted with the below image showing what instance you are connected too:

MySQL Shell Connection

once connected you we now need to configure the instance issue the below command, and accept the prompts. you will need to do this for each of the 3 virtual machines, but once you have done one you can type the other remote machines in the brackets as parameters.

do the same for the last one.

Create the Cluster

 

we are now in the position of creating the cluster, issue the below command, you only need to do it just the once.  This will create a cluster in the name of myCluster.

Let’s check the status.

this will output the following:

Cluster Status

 

The Router

With our cluster now configured we need to configure the final virtual machine to be our Router, the Router is responsible for allowing your application to talk to the MySQL cluster.

first add the MySQL repository and then configure it, accept all the defaults.

once the above commands have been entered, issue the below:

Bootstrap the Router

Once installed we now need to bootstrap the router, change the name and host name of your server

this is the below output from running the above:

Start the bootstrap

 

Done,  that’s all.  Your cluster is now configured and should one of your virtual machines fail your database application will continue to function.

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *