How to Create a Linux MariaBD Galera Cluster 2022

How to Create a Linux MariaBD Galera Cluster 2022

Install CentOs

Firstly we will use three machine instances with CentOs 7 operative system installed, in my case i used this image [CentOS-7-x86_64-DVD-2009].

Internet Config

nano /etc/sysconfig/network-scripts/ifcfg-enp0s3

VirtualBoxVM_1qrwhlPXCH.png Ctrl+O + enter + Ctrl+X

yum install openssh-server

therefore execute sshd demon.

systemctl enable sshd
systemctl start sshd
systemctl status sshd

image.png

Execute the command ip a, to find the static ip for every machine, and change the hostname. Remember each ip equivalent for every hostname.

nano /etc/hostname

EXCEL_z1KUousqdz.png

Install MariaBD

nano /etc/yum.repos.d/MariaBD.repo

Download MariaDB Server Repositories

# MariaDB 10.3 CentOS repository list - created 2022-08-16 05:37 UTC
# https://mariadb.org/download/
[mariadb]
name = MariaDB
baseurl = https://mirror.its.dal.ca/mariadb/yum/10.3/centos7-amd64
gpgkey=https://mirror.its.dal.ca/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1
yum install MariaDB-server MariaDB-client

ConEmu64_iwIVO3ku6u.png Verify the instalation of mariadb, and that it works.

systemctl enable mariadb
systemctl start mariadb
systemctl status mariadb

ConEmu64_KKyturLIiN.png Execute mysql_secure_installation to change some parameters to make the cluster more secure (just follow each step, create the password and type "y" to allow the changes).

mysql_secure_installation

ConEmu64_2hwZVqRCYt.png

Configure Cluster

After executing all this steps in every machine we will stop every mariadb process in all nodes, and we will use the name of every host and their ip, to edit this file.

nano /etc/my.cnf.d/server.cnf

Same changes for every node

  • wsrep_cluster_address="gcomm://192.168.0.11,192.168.0.12,192.168.0.13".

Add every ip address you will use in your cluster, seperating them by commas.

  • wsrep_cluster_name="Cluster" Give a name to you cluster

Different change for every machine

  • wsrep_node_address="192.168.0.11".

Ip address of the actual machine.

  • wsrep_node_name="node1.host".

Hostname of the actual machine.

EXCEL_z1KUousqdz.png

[galera]
# Mandatory settings
wsrep_on=ON
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address="gcomm://192.168.0.11,192.168.0.12,192.168.0.13"
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
#
# Allow server to accept connections on all interfaces.
#
bind-address=0.0.0.0
wsrep_cluster_name="Cluster"
wsrep_node_address="192.168.0.11"
wsrep_node_name="node1.host"
wsrep_sst_method=rsync
#
# Optional setting
#wsrep_slave_threads=1
#innodb_flush_log_at_trx_commit=0

# this is only for embedded server
[embedded]

# This group is only read by MariaDB servers, not by MySQL.
# If you use the same .cnf file for MySQL and MariaDB,
# you can put MariaDB-only options here
[mariadb]

# This group is only read by MariaDB-10.3 servers.
# If you use the same .cnf file for MariaDB of different versions,
# use this group for options that older servers don't understand
[mariadb-10.3]

Cluster

Execute the next command in the node that you want to be the princial

galera_new_cluster

ConEmu64_olChBDTEsd.png For every machine, that it is not the principal one, (node2,node3) we will start mariadb with systemctl.

ConEmu64_olXgyyp1TD.png ConEmu64_nATugiHhCa.png From every node we can access to mariadb using the next command.

mysql -u root -p

ConEmu64_vDMiTQYL0x.png Check that every node is connected.

show status like "wsrep_cluster_size";

ConEmu64_hymulLPs32.png

show databases; #//shows all the databases
create database database_name; #//create data base

ConEmu64_ZTtWAU8o1L.png Now i will execute different SQL instructions in different nodes, that we can see in the bottom of the screen that the machine is changing, and effectively all nodes are connected to the same data base. ConEmu64_iqPs7jKZ2G.png ConEmu64_gS6kmOCr6F.png ConEmu64_ey6xW9neyZ.png ConEmu64_BlcPMhxMeS.png ConEmu64_waW0FNOc1h.png fcpcLDEfao.png