- Lab
- A Cloud Guru
Install MariaDB Galera Cluster on Linux
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.
Path Info
Table of Contents
-
Challenge
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
-
Challenge
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
-
Challenge
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
clientmysql
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.
-
Challenge
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.
What's a lab?
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.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.