Discover the step-by-step process to install Galera Cluster on Rocky Linux 9 with our comprehensive guide. Harness the power of this robust MySQL high availability solution and optimize your database infrastructure effortlessly. #centlinux #linux #mysql
Table of Contents
What is Galera Cluster?:
Galera Cluster is a popular multi-master synchronous replication solution for database systems. It is specifically designed to provide high availability and data consistency for Database clusters. Galera allows you to create a cluster of multiple database nodes that can all accept write operations and synchronize data in real-time.
In a Galera cluster, all nodes are equal and can function as both primary and backup nodes. When a write operation is performed on any node, it is immediately propagated to all other nodes in the database cluster, ensuring that all nodes have the same data. This synchronous replication mechanism guarantees data consistency across the cluster.
Galera is commonly used with relational database management systems (RDBMS) such as MySQL or MariaDB. It eliminates the need for traditional database replication methods like master-slave or master-master setups, providing a simpler and more robust solution for high availability and data redundancy.
Install Galera cluster to achieve automatic failover, where if one node fails, another node takes over seamlessly without any data loss or downtime. This makes Galera well-suited for applications that require continuous availability and real-time data synchronization, such as e-commerce platforms, online gaming, or financial systems.
It’s worth noting that Galera is a specific implementation of the synchronous replication concept, and there are other similar solutions available for database clustering and replication, each with its own features and considerations.
Read Also: How to Install MariaDB Galera Cluster on CentOS 7
Environment Specification:
We are using three identical Rocky Linux 9 virtual machines with following specifications.
- CPU – 3.4 Ghz (2 cores)
- Memory – 2 GB
- Storage – 40 GB
- Operating System – Rocky Linux release 9.2 (Blue Onyx)
- Hostname – mariadb-01, mariadb-02, mariadb-03
- IP Address – (192.168.18.88, 192.168.18.89, 192.168.18.90)/24
Configure your Network:
By using a ssh client, logon to each node as root user and configure your network.
Set static IP address and Hostname on your First node.
# nmcli c m enp0s3 ipv4.method manual ipv4.addresses 192.168.18.88/24 ipv4.gateway 192.168.116.2 ipv4.dns 192.168.116.2
# nmcli c down enp0s3; nmcli c up enp0s3
# hostnamectl set-hostname mariadb-01.centlinux.com
Set static IP address and Hostname on your Second node.
# nmcli c m enp0s3 ipv4.method manual ipv4.addresses 192.168.18.89/24 ipv4.gateway 192.168.116.2 ipv4.dns 192.168.116.2
# nmcli c down enp0s3; nmcli c up enp0s3
# hostnamectl set-hostname mariadb-02.centlinux.com
Set static IP address and Hostname on your Third node.
# nmcli c m enp0s3 ipv4.method manual ipv4.addresses 192.168.18.90/24 ipv4.gateway 192.168.116.2 ipv4.dns 192.168.116.2
# nmcli c down enp0s3; nmcli c up enp0s3
# hostnamectl set-hostname mariadb-03.centlinux.com
Configure Name Resolution:
Setup Local DNS resolution, so your Cluster nodes do not depend upon a DNS server for name resolution.
Login to your First MariaDB node as root user.
Edit /etc/hosts file by using a vim text editor.
# vi /etc/hosts
Adding following lines in this file.
192.168.18.88 mariadb-01 mariadb-01.centlinux.com
192.168.18.89 mariadb-02 mariadb-02.centlinux.com
192.168.18.90 mariadb-03 mariadb-03.centlinux.com
Now, use scp command to copy your updated hosts file on remaining database nodes.
# scp /etc/hosts root@mariadb-02:/etc/hosts # scp /etc/hosts root@mariadb-03:/etc/hosts
Configure Linux Firewall:
Execute following commands on each MariaDB node to allow galera service in Linux firewall.
# firewall-cmd --permanent --add-service=galera success # firewall-cmd --reload success
Update Software Packages:
Execute follow set of commands on each cluster node to update software packages and note down the Linux OS and Linux Kernel versions.
# dnf update -y # cat /etc/rocky-release Rocky Linux release 9.2 (Blue Onyx) # uname -r 5.14.0-284.11.1.el9_2.x86_64
Install Galera Cluster on Rocky Linux 9:
Execute following dnf command on each node of database cluster to install Galera software.
# dnf install -y mariadb-server-galera
Now, connect to your first node as root user and edit Galera configuration file in vim text editor.
# vi /etc/my.cnf.d/galera.cnf
Locate and set following directives in this file.
# Enable wsrep wsrep_on=1 # Logical cluster name. Should be the same for all nodes. wsrep_cluster_name="mariadb_cluster" # Group communication system handle wsrep_cluster_address="gcomm://192.168.18.88,192.168.18.89,192.168.18.90" # Base replication <address|hostname>[:port] of the node. # The values supplied will be used as defaults for state transfer receiving, # listening ports and so on. Default: address of the first network interface. wsrep_node_address="192.168.18.88"
Start Galera cluster on first node.
# galera_new_cluster
Enable and start MariaDB database service.
# systemctl enable --now mariadb.service Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service. Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service. Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
Configure initial settings of your MariaDB server as follows.
# mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and haven't set the root password yet, you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password or using the unix_socket ensures that nobody can log into the MariaDB root user without the proper authorisation. You already have your root account protected, so you can safely answer 'n'. Switch to unix_socket authentication [Y/n] n ... skipping. You already have your root account protected, so you can safely answer 'n'. Change the root password? [Y/n] Y New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] Y ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] Y ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] Y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] Y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
Login to your MariaDB Database server by using mysql command.
# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or g. Your MariaDB connection id is 16 Server version: 10.5.16-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
Check the value to wsrep_cluster_size variable to get the number of nodes in your Galera cluster.
MariaDB [(none)]> show global status like 'wsrep_cluster_size'; +--------------------+-------+ | Variable_name | Value | +--------------------+-------+ | wsrep_cluster_size | 1 | +--------------------+-------+ 1 row in set (0.001 sec)
Currently, there is only one node in your Galera cluster.
Adding Nodes in Galera Cluster:
Your Galera Cluster has been started successfully, now you can add more MariaDB server nodes in it.
Login to your second node as root user and edit Galera configuration file.
# ssh root@mariadb-02 # vi /etc/my.cnf.d/galera.cnf
Set following directives in this file.
# Enable wsrep wsrep_on=1 # Logical cluster name. Should be the same for all nodes. wsrep_cluster_name="mariadb_cluster" # Group communication system handle wsrep_cluster_address="gcomm://192.168.18.88,192.168.18.89,192.168.18.90" # Base replication <address|hostname>[:port] of the node. # The values supplied will be used as defaults for state transfer receiving, # listening ports and so on. Default: address of the first network interface. wsrep_node_address="192.168.18.89"
Enable and start MariaDB database service.
# systemctl enable --now mariadb
Check the status of wsrep_cluster_size variable again.
MariaDB [(none)]> show global status like 'wsrep_cluster_size'; +--------------------+-------+ | Variable_name | Value | +--------------------+-------+ | wsrep_cluster_size | 2 | +--------------------+-------+ 1 row in set (0.002 sec)
You can see that, after addition of second node, your Galera Cluster size is become 2.
Similarly, you can add your third node to Galera cluster.
# ssh root@mariadb-03 # vi /etc/my.cnf.d/galera.cnf
Set following directives in Galera configuration file.
# Enable wsrep wsrep_on=1 # Logical cluster name. Should be the same for all nodes. wsrep_cluster_name="mariadb_cluster" # Group communication system handle wsrep_cluster_address="gcomm://192.168.18.88,192.168.18.89,192.168.18.90" # Base replication <address|hostname>[:port] of the node. # The values supplied will be used as defaults for state transfer receiving, # listening ports and so on. Default: address of the first network interface. wsrep_node_address="192.168.18.90"
Enable and start MariaDB database service.
# systemctl enable --now mariadb
Check the value of wsrep_cluster_size variable again.
MariaDB [(none)]> show global status like 'wsrep_cluster_size'; +--------------------+-------+ | Variable_name | Value | +--------------------+-------+ | wsrep_cluster_size | 3 | +--------------------+-------+ 1 row in set (0.002 sec)
All three nodes have been successfully added to your Galera cluster.
You can test your Galera cluster by creating some database objects on one node and check if the changes reflect to other nodes in real time.
Conclusion:
As you navigate through this process to install Galera Cluster on Rocky Linux 9, you’re embarking on a journey toward optimizing your database infrastructure for high availability and reliability. By following our detailed guide, you’re equipping yourself with the knowledge and tools needed to ensure seamless operations and scalability for your MySQL databases. Embrace the opportunity to enhance the resilience of your systems and empower your organization with a robust database clustering solution. If you want to learn more about Galera Cluster, we recommend that you should attend online training Galera Cluster and MariaDB MySQL Replication