Implement a Cluster to Reduce Client Read Latency Using MariaDB Galera Cluster and Galera Load Balancer

15 minutes
  • 6 Learning Objectives

About this Hands-on Lab

In this activity you are working as a DBA and have been tasked with configuring a MariaDB Galera Cluster to reduce client read latency.

A POC (proof of concept) cluster has been started for you to configure. You will need to install the Galera Load Balancer and configure it appropriately.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Set the root Database User’s Password and Create a Database User Account

The database nodes are running and connected to the cluster, however the root user’s password has not been set.
You must first set the root user’s password by running the mysql_secure_installation script:

sudo mysql_secure_installation

Now you can connect to the database as the root user and create a user account:

mysql -u root -p

Once connected, you can use the following SQL to create a user named remote who is able to log in remotely.
Be sure to replace mypasswd with a password of your choice:

create user remote identified by 'mypasswd';
grant usage on *.* to 'remote'@'%' identified by 'mypasswd';
Install the Prerequisite Packages
sudo yum -y install git autoconf automake libtool gcc-c++ nmap-ncat        
Build the Binaries
git clone https://github.com/codership/glb
cd glb
./bootstrap.sh
./configure
make
sudo make install
Configure and Start Galera Load Balancer

First copy the MySQL Watchdog script and Galera Load Balancer service files into place:

sudo cp /home/cloud_user/glb/files/mysql.sh /usr/local/bin/mysql-check.sh
sudo cp /home/cloud_user/glb/files/glbd.sh /etc/init.d/glb

We will use the Source Tracking (--source) policy to ensure that connections always go to the same node, reducing client latency:

sudo vim /etc/sysconfig/glbd

# Address to listen for client connections at. Mandatory parameter.
# To bind to all interfaces only port should be specified.
LISTEN_ADDR="10.0.1.100:13306"

# Address for controlling connection. Mandatory part is port.
# If not specified control socket will not be opened
CONTROL_ADDR="127.0.0.1:4444"

# Target servers for client connections, space separated.
# Target specification: IP[:PORT[:WEIGHT]] (WEIGHT and PORT optional)
# WEIGHT defaults to 1, PORT defaults to LISTEN_ADDR port.
DEFAULT_TARGETS="10.0.1.100:3306:10"

# Other glbd options if any as they would appear on the command line.
OTHER_OPTIONS="--source --watchdog exec:'/usr/local/bin/mysql-check.sh -uremote -pmypasswd'"

Start the service:


sudo service glb start
sudo service glb status
Confirm Connections
mysql -h 10.0.1.100 -P 13306 -u remote -p

Check GLB status to confirm:

sudo service glb status
Test Failover Routing

Nodes in other regions can be added with a lower weight to provide failover capability:

sudo service glb add "10.0.1.110:3306:1"

We can then simulate a failure of node0 and test the connection:

sudo systemctl stop mariadb.service
mysql -h 10.0.1.100 -P 13306 -u remote -p

Additional Resources

In this activity you are working as a DBA and have been tasked with configuring a MariaDB Galera Cluster to reduce client read latency.

A POC (proof of concept) cluster has been started for you to configure. You will need to install the Galera Load Balancer and configure it appropriately. To do this, you will need to complete the following steps on each node:

  1. Set the root database user's password and create a database user account.
  2. Install the prerequisite packages.
  3. Build the Galera Load Balancer binaries.
  4. Configure and start Galera Load Balancer.
  5. Confirm connections.
  6. Test failover routing of connections.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?