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
Ctrl+O + enter + Ctrl+X
yum install openssh-server
therefore execute sshd demon.
systemctl enable sshd
systemctl start sshd
systemctl status sshd
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
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
Verify the instalation of mariadb, and that it works.
systemctl enable mariadb
systemctl start mariadb
systemctl status mariadb
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
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.
[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
For every machine, that it is not the principal one, (node2,node3) we will start mariadb with systemctl.
From every node we can access to mariadb using the next command.
mysql -u root -p
Check that every node is connected.
show status like "wsrep_cluster_size";
show databases; #//shows all the databases
create database database_name; #//create data base
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.