How To Configure A Galera Cluster With Mariadb On Centos 7 Servers


MariaDB Galera Cluster is a synchronous multi-master cluster for MariaDB. It is a fork of Galera Cluster, the world"s most advanced, free and open source cluster engine. Currently, it only supports InnoDB storage engines.

Bạn đang xem: How to configure a galera cluster with mariadb on centos 7 servers

MariaDB Galera Cluster is a true Multi-Master & Active-Active cluster. Due khổng lồ it"s synchronous behaviour, there will be no data lost in case of a node crash because all nodes always hold the same state.

MariaDB Galera Cluster also provides Automatic node provisioning. It means we bởi vì not have khổng lồ manually backup the database & restore it on new node before adding it to Galera cluster. This features gives the additional benefit of Cloud support due khổng lồ simple scale-in & scale-out operations.

In this article, we will create a two-node MariaDB Galera Cluster of MariaDB 10.3 Database on CentOS 7. However, the same steps can be used to lớn configure a MariaDB Galera Cluster of larger size.

This article focuses on the installation of MariaDB Galera Cluster on CentOS 7 without diving into theory và definitions pertains to lớn MariaDB. Therefore, it is recommended that you should read Getting Started with MariaDB - Second Edition by Packt Publishing lớn have basic understanding of MariaDB database.

Table of Contents:

System Specification:

For this article, we are using two CentOS 7 virtual machines as the Galera Cluster nodes.

IP Address: /24
CPU: 2.4 Ghz (2 cores) 2.4 Ghz (2 cores)
Memory: 2 GB 2 GB
Operating System: CentOS 7.6 CentOS 7.6
MariaDB Version: 10.3.12 10.3.12

Installing MariaDB 10.3 Database vps on CentOS 7:

Connect to lớn using ssh as root user.

Install MariaDB & MaxScale yum repositories.

mariadb-01 ~># curl -sS | bash Repository tệp tin successfully written to /etc/yum.repos.d/mariadb.repo. Adding trusted package signing keys... Succeessfully added trusted package signing keys.

Build yum cache for all repositories.

mariadb-01 ~># yum makecache fastLoaded plugins: fastestmirrorDetermining fastest mirrors * base: * extras: * updates: repo.inara.pkbase | 3.6 kB 00:00extras | 3.4 kB 00:00mariadb-main | 2.9 kB 00:00mariadb-maxscale | 2.4 kB 00:00mariadb-tools | 2.9 kB 00:00updates | 3.4 kB 00:00(1/5): mariadb-maxscale/7/x86_64/primary_db | 6.7 kB 00:02(2/5): mariadb-tools/7/x86_64/primary_db | 11 kB 00:02(3/5): mariadb-main/7/x86_64/primary_db | 50 kB 00:03(4/5): extras/7/x86_64/primary_db | 156 kB 00:04(5/5): updates/7/x86_64/primary_db | 1.4 MB 00:09Metadata Cache Created

Install MariaDB 10.3 Server and Galera using yum command.

mariadb-01 ~># yum install -y mariadb-server galera...Installed: MariaDB-compat.x86_64 0:10.3.12-1.el7.centos MariaDB-server.x86_64 0:10.3.12-1.el7.centos galera.x86_64 0:25.3.25-1.rhel7.el7.centosDependency Installed: MariaDB-client.x86_64 0:10.3.12-1.el7.centos MariaDB-common.x86_64 0:10.3.12-1.el7.centos boost-program-options.x86_64 0:1.53.0-27.el7 lsof.x86_64 0:4.87-6.el7 perl.x86_64 4:5.16.3-294.el7_6 perl-Carp.noarch 0:1.26-244.el7 perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7 perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7 perl-DBI.x86_64 0:1.627-4.el7 perl-Data-Dumper.x86_64 0:2.145-3.el7 perl-Encode.x86_64 0:2.51-7.el7 perl-Exporter.noarch 0:5.68-3.el7 perl-File-Path.noarch 0:2.09-2.el7 perl-File-Temp.noarch 0:0.23.01-3.el7 perl-Filter.x86_64 0:1.49-3.el7 perl-Getopt-Long.noarch 0:2.40-3.el7 perl-HTTP-Tiny.noarch 0:0.033-3.el7 perl-IO-Compress.noarch 0:2.061-2.el7 perl-Net-Daemon.noarch 0:0.48-5.el7 perl-PathTools.x86_64 0:3.40-5.el7 perl-PlRPC.noarch 0:0.2020-14.el7 perl-Pod-Escapes.noarch 1:1.04-294.el7_6 perl-Pod-Perldoc.noarch 0:3.20-4.el7 perl-Pod-Simple.noarch 1:3.28-4.el7 perl-Pod-Usage.noarch 0:1.63-3.el7 perl-Scalar-List-Utils.x86_64 0:1.27-248.el7 perl-Socket.x86_64 0:2.010-4.el7 perl-Storable.x86_64 0:2.45-3.el7 perl-Text-ParseWords.noarch 0:3.29-4.el7 perl-Time-HiRes.x86_64 4:1.9725-3.el7 perl-Time-Local.noarch 0:1.2300-2.el7 perl-constant.noarch 0:1.27-2.el7 perl-libs.x86_64 4:5.16.3-294.el7_6 perl-macros.x86_64 4:5.16.3-294.el7_6 perl-parent.noarch 1:0.225-244.el7 perl-podlators.noarch 0:2.5.1-3.el7 perl-threads.x86_64 0:1.87-4.el7 perl-threads-shared.x86_64 0:1.43-6.el7 rsync.x86_64 0:3.1.2-4.el7Replaced: mariadb-libs.x86_64 1:5.5.60-1.el7_5Complete!

Repeat above steps on all other nodes.

Configuring MariaDB Galera Cluster on CentOS 7:

Allow MariaDB and Galera service ports in Linux firewall.

mariadb-01 ~># firewall-cmd --reloadsuccess

Set SELinux to lớn permissive mode for now, & we will enable the enforcing mode later, after creating an SELinux policy for MariaDB Galera cluster.

Xem thêm: Cách Thêm Tiện Ích Idm Vào Chrome Mới Nhất 2021, Hướng Dẫn Bạn Cách Thêm Tiện Ích Idm Vào Chrome

mariadb-01 ~># vi /etc/my.cnf.d/server.cnf

and configure galera section as follows:

# Mandatory settingswsrep_on=ONwsrep_provider=/usr/lib64/galera/libgalera_smm.sowsrep_cluster_address=gcomm://,

Perform above steps on each node.

Start Galera cluster on

mariadb-01 ~># systemctl start mariadb.service

If the service started successfully then, it shows that we have successfully configured our Galera cluster.

Configure MariaDB database instance on each node.

mariadb-01 ~># mysql_secure_installationNOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!In order lớn log into MariaDB to secure it, we"ll need the currentpassword for the root user. If you"ve just installed MariaDB, andyou haven"t mix the root password yet, the password will be blank,so you should just press enter here.Enter current password for root (enter for none):OK, successfully used password, moving on...Setting the root password ensures that nobody can log into the MariaDBroot user without the proper authorisation.Set root password? YNew password:Re-enter new password:Password updated successfully!Reloading privilege tables.. ... Success!By default, a MariaDB installation has an anonymous user, allowing anyoneto log into MariaDB without having to have a user trương mục created forthem. This is intended only for testing, & to make the installationgo a bit smoother. You should remove them before moving into aproduction environment.Remove anonymous users? Y ... Success!Normally, root should only be allowed to connect from "localhost". Thisensures that someone cannot guess at the root password from the network.Disallow root login remotely? Y ... Success!By default, MariaDB comes with a database named "test" that anyone canaccess. This is also intended only for testing, và should be removedbefore moving into a production environment.Remove chạy thử database & access lớn it? Y - Dropping thử nghiệm database... ... Success! - Removing privileges on thử nghiệm database... ... Success!Reloading the privilege tables will ensure that all changes made so farwill take effect immediately.Reload privilege tables now? Y ... Success!Cleaning up...All done! If you"ve completed all of the above steps, your MariaDBinstallation should now be secure.Thanks for using MariaDB!

Connect with MariaDB instance on any node and check wsrep_cluster_size.

wsrep_cluster_size confirms that all of our nodes are now connected in Galera cluster.

Create SELinux Policy for MariaDB Galera cluster:

Since, we have configured SELinux in permissive mode. Therefore, all the violations by MariaDB và Galera has been recorded in /var/log/audit/audit.log. We can use it to create a concrete SELinux policy.

Use fgrep and audit2allow commands khổng lồ extract policy violations log into a text file.

mariadb-01 ~># fgrep "mysqld" /var/log/audit/audit.log | audit2allow -m MySQL_galera -o MySQL_galera.te

Compile these logs to a SELinux policy module.

mariadb-01 ~># checkmodule -M -m MySQL_galera.te -o MySQL_galera.modcheckmodule: loading policy configuration from galera.techeckmodule: policy configuration loadedcheckmodule: writing binary representation (version 19) khổng lồ MySQL_galera.mod

Create a package of compiled policy module.

mariadb-01 ~># semodule_package -m MySQL_galera.mod -o MySQL_galera.pp

Import this policy into SELinux.

mariadb-01 ~># setenforce 1

Test SELinux is working fine by restart MariaDB service on each node.

Finally, enable the MariaDB service on all nodes.

mariadb-01 ~># systemctl enable mariadb.service

We have successfully configured a MariaDB Galera Cluster on CentOS 7. Although we have configured a two node cluster, but the same steps are good enough for configuring a MariaDB Galera cluster of larger size.

After configuring a MariaDB Galera Cluster, you should be looking next for a database proxy to perform load balancing and routing for our cluster. Therefore, it is highly recommended that you should read our next post Install MariaDB MaxScale Database Proxy on CentOS 7.