Install MariaDB Galera Cluster on Linux

30 minutes
  • 4 Learning Objectives

About this Hands-on Lab

You are working as a Systems Administrator in a large company with many distributed offices, and have been tasked with setting up a MySQL-compatible cluster. You have chosen to implement MariaDB Galera cluster as a proof of concept.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Install the Packages

Create the MariaDB.repo file:

cat <<EOF > ~/MariaDB.repo
# MariaDB 10.4 CentOS repository list - created 2020-01-28 16:00 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF

Copy MariaDB.repo to /etc/yum.repos.d/:

sudo cp ~/MariaDB.repo /etc/yum.repos.d/

Once the YUM repository is configured, install the packages:

sudo yum -y install MariaDB-server MariaDB-client galera-4
Configure Firewall and SELinux

Open TCP ports for Galera replication:

sudo firewall-cmd --zone=public --add-port=4567/tcp --permanent
sudo firewall-cmd --zone=public --add-port=4568/tcp --permanent
sudo firewall-cmd --zone=public --add-port=4444/tcp --permanent
sudo firewall-cmd --zone=public --add-port=3306/tcp --permanent
sudo firewall-cmd --zone=public --add-port=13306/tcp --permanent

sudo firewall-cmd --reload

SELinux already opens the standard MySQL port 3306, but some additional ports are used by Galera:

sudo semanage port -m -t mysqld_port_t -p tcp 4567
sudo semanage port -a -t mysqld_port_t -p tcp 4568
sudo semanage port -m -t mysqld_port_t -p tcp 4444

Set permissive mode for the database server. This will allow the server to function while logging its activity.
We can use this log to create an SELinux policy.

sudo semanage permissive -a mysqld_t
Bootstrap the New Cluster

Create ~/node0.cnf:

[mysqld]
bind-address=10.0.1.100

[galera]
wsrep_on=ON
wsrep_provider=/usr/lib64/galera-4/libgalera_smm.so
binlog_format=ROW
wsrep_cluster_name='galera_cluster'
wsrep_node_name='node0'
wsrep_cluster_address='gcomm://'

Note that by setting wsrep_cluster_address=’gcomm://’, a new cluster will be started.

To make the configuration active, we copy the file to /etc/my.cnf.d/ and start the service:

sudo cp ~/node0.cnf /etc/my.cnf.d/
sudo systemctl start mariadb.service

We can confirm the cluster status:

sudo systemctl status mariadb.service

Finally we can connect to the server using using the mysql client

mysql

Once connected, we can run the following SQL statement to confirm the cluster is running.

SHOW GLOBAL STATUS WHERE Variable_name IN ('wsrep_ready', 'wsrep_cluster_size', 'wsrep_cluster_status', 'wsrep_connected');

A cluster size of 1 means only one node is connected.

Adding Nodes to the Cluster

The binary installation and firewall/SELinux configuration is the same on all nodes.
After the binary packages are installed and the firewall and SELinux are configured, proceed as follows:

Create node1.cnf:

cat <<EOF > ~/node1.cnf
[mysqld]
bind-address=10.0.1.110

[galera]
wsrep_on=ON
wsrep_provider=/usr/lib64/galera-4/libgalera_smm.so
binlog_format=ROW
wsrep_cluster_address='gcomm://10.0.1.100'
wsrep_cluster_name='galera_cluster'
wsrep_node_name='node1'
EOF

Additional nodes can be added using the same configuration after updating the bind-address and wsrep_node_name.

To make the configurations active, we copy the file to /etc/my.cnf.d/ and start the service:

sudo cp ~/node1.cnf /etc/my.cnf.d/
sudo systemctl start mariadb.service

Confirm the cluster status:

sudo systemctl status mariadb.service

Assuming all went well, connect to the server using the mysql client and confirm the cluster status with the following SQL:

SHOW GLOBAL STATUS WHERE Variable_name IN ('wsrep_ready', 'wsrep_cluster_size', 'wsrep_cluster_status', 'wsrep_connected');

Once other nodes have joined the cluster we need to update the cluster address on node0 with the private IP addresses of the other nodes in the cluster.
We can do this by adding the following to /etc/my.cnf.d/node0.cnf on node0:

wsrep_cluster_address='gcomm://10.0.1.110'

After this is done, node0 can be restarted and it will re-join the existing cluster.

Additional Resources

In order to do this, you will need to complete the following tasks:

1. Install the packages.
2. Configure the firewall and SELinux.
3. Bootstrap a new cluster.
4. Add nodes to the cluster.

The YUM repository file and node configurations are available in the download section of this course.

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?