Create MariaDB Cluster Galera
CLSNode1 = 10.23.20.156
CLSNode2 = 10.23.20.157
Install MariaDB & Galera at All Node
=====================================
# yum install rsync policycoreutils-python -y
# yum install mariadb mariadb-server galera -y
# systemctl start mariadb
# systemctl enable mariadb
# systemctl status mariadb
Stop Service MariaDB at All Node
=====================================
# systemctl stop mariadb
Setup Galera config at Node1
=====================================
# touch /var/log/mariadb.log
# chown mysql:mysql /var/log/mariadb.log
# vi /etc/my.cnf.d/server.cnf
==============================================================================
[mysqld]
log_error=/var/log/mariadb.log
binlog_format=ROW
default-storage-engine=innodb innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
# Galera Provider Configuration
wsrep_on=ON
wsrep_provider=/usr/lib64/galera-4/libgalera_smm.so
# Galera Cluster Configuration
wsrep_cluster_name=”test_cluster”
wsrep_cluster_address=”gcomm://10.23.20.156,10.23.20.157″
# Galera Synchronization Configuration
wsrep_sst_method=rsync
# Galera Node Configuration
wsrep_node_address=”10.23.20.156″ wsrep_node_name=”CLSNode1″
================================================================================
# galera_new_cluster
Setup Galera config at Node2
=======================================
# touch /var/log/mariadb.log
# chown mysql:mysql /var/log/mariadb.log
# vi /etc/my.cnf.d/server.cnf
===========================================================================
[mysqld]
log_error=/var/log/mariadb.log
binlog_format=ROW
default-storage-engine=innodb innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
# Galera Provider Configuration
wsrep_on=ON
wsrep_provider=/usr/lib64/galera-4/libgalera_smm.so
# Galera Cluster Configuration
wsrep_cluster_name=”test_cluster”
wsrep_cluster_address=”gcomm://10.23.20.156,10.23.20.157″
# Galera Synchronization Configuration
wsrep_sst_method=rsync
# Galera Node Configuration
wsrep_node_address=”10.23.20.157″
wsrep_node_name=”CLSNode2″
==========================================================================
# systemctl start mariadb
Open Firewall MariaDB Cluster Galera all Node
=============================================
# firewall-cmd --permanent --zone=public --add-port=3306/tcp
# firewall-cmd --permanent --zone=public --add-port=4567/tcp
# firewall-cmd --permanent --zone=public --add-port=4568/tcp
# firewall-cmd --permanent --zone=public --add-port=4444/tcp
# firewall-cmd --permanent --zone=public --add-port=4567/udp
# firewall-cmd --permanent --zone=public --add-source=galera-node-1-ip/32
# firewall-cmd --permanent --zone=public --add-source=galera-node-2-ip/32
# firewall-cmd reload
Creating a SELinux Policy at All Node
=============================================
# semanage port -a -t mysqld_port_t -p tcp 4567
# semanage port -a -t mysqld_port_t -p udp 4567
# semanage port -a -t mysqld_port_t -p tcp 4568
# semanage port -a -t mysqld_port_t -p tcp 4444
# semanage permissive -a mysqld_t
stop service mariadb on all node by executing :
# systemctl stop mariadb
bootstrap the cluster by executing :
# galera_new_cluster
Create a database and table for the specific purpose of logging SST events by running the following on the first node:
# mysql -u root -p
MariaDB [(none)]> CREATE DATABASE selinux;
MariaDB [(none)]> CREATE TABLE selinux.selinux_policy (id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id));
MariaDB [(none)]> INSERT INTO selinux.selinux_policy VALUES ();
start service mariadb on node2 :
# systemctl start mariadb
You will not see any output for the previous commands. To generate IST events, execute the following on all three servers :
# mysql -u root -p -e 'INSERT INTO selinux.selinux_policy VALUES ();'
Now create and enable the SELinux policy by executing the following commands on all three servers :
# grep mysql /var/log/audit/audit.log | audit2allow -M Galera
This first command searches for generated events in the audit.log file and pipes them to a module named Galera.pp generated by the audit2allow tool. This will result in the following output:
Output
******************** IMPORTANT ***********************
To make this policy package active, execute:
semodule -i Galera.pp
******************************************************
Next, follow the instructions in the output and use the following command to install the generated module:
# semodule -i Galera.ppz
Now that the policy is active, disable permissive mode for the MariaDB server:
# semanage permissive -d mysqld_t
Show Status Galera Cluster
===========================================
MariaDB [(none)]> show status like 'wsrep_cluster_size';
MariaDB [(none)]> show status like 'wsrep_%';
MariaDB [(none)]> show status like 'wsrep_%';
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
| Variable_name | Value |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
| wsrep_local_state_uuid | 171ee238-3d90-11ec-b271-da8d1dc3b89a |
| wsrep_protocol_version | 10 |
| wsrep_last_committed | 2 |
| wsrep_replicated | 0 |
| wsrep_replicated_bytes | 0 |
| wsrep_repl_keys | 0 |
| wsrep_repl_keys_bytes | 0 |
| wsrep_repl_data_bytes | 0 |
| wsrep_repl_other_bytes | 0 |
| wsrep_received | 6 |
| wsrep_received_bytes | 450 |
| wsrep_local_commits | 0 |
| wsrep_local_cert_failures | 0 |
| wsrep_local_replays | 0 |
| wsrep_local_send_queue | 0 |
| wsrep_local_send_queue_max | 1 |
| wsrep_local_send_queue_min | 0 |
| wsrep_local_send_queue_avg | 0 |
| wsrep_local_recv_queue | 0 |
| wsrep_local_recv_queue_max | 2 |
| wsrep_local_recv_queue_min | 0 |
| wsrep_local_recv_queue_avg | 0.166667 |
| wsrep_local_cached_downto | 1 |
| wsrep_flow_control_paused_ns | 0 |
| wsrep_flow_control_paused | 0 |
| wsrep_flow_control_sent | 0 |
| wsrep_flow_control_recv | 0 |
| wsrep_flow_control_active | false |
| wsrep_flow_control_requested | false |
| wsrep_cert_deps_distance | 0 |
| wsrep_apply_oooe | 0 |
| wsrep_apply_oool | 0 |
| wsrep_apply_window | 0 |
| wsrep_apply_waits | 0 |
| wsrep_commit_oooe | 0 |
| wsrep_commit_oool | 0 |
| wsrep_commit_window | 0 |
| wsrep_local_state | 4 |
| wsrep_local_state_comment | Synced |
| wsrep_cert_index_size | 0 |
| wsrep_causal_reads | 0 |
| wsrep_cert_interval | 0 |
| wsrep_open_transactions | 0 |
| wsrep_open_connections | 0 |
| wsrep_incoming_addresses | AUTO,AUTO |
| wsrep_cluster_weight | 2 |
| wsrep_desync_count | 0 |
| wsrep_evs_delayed | |
| wsrep_evs_evict_list | |
| wsrep_evs_repl_latency | 0/0/0/0/0 |
| wsrep_evs_state | OPERATIONAL |
| wsrep_gcomm_uuid | 171e6a15-3d90-11ec-894a-a2fefe5f2d89 |
| wsrep_gmcast_segment | 0 |
| wsrep_applier_thread_count | 1 |
| wsrep_cluster_capabilities | |
| wsrep_cluster_conf_id | 2 |
| wsrep_cluster_size | 2 |
| wsrep_cluster_state_uuid | 171ee238-3d90-11ec-b271-da8d1dc3b89a |
| wsrep_cluster_status | Primary |
| wsrep_connected | ON |
| wsrep_local_bf_aborts | 0 |
| wsrep_local_index | 1 |
| wsrep_provider_capabilities | :MULTI_MASTER:CERTIFICATION:PARALLEL_APPLYING:TRX_REPLAY:ISOLATION:PAUSE:CAUSAL_READS:INCREMENTAL_WRITESET:UNORDERED:PREORDERED:STREAMING:NBO: |
| wsrep_provider_name | Galera |
| wsrep_provider_vendor | Codership Oy <info@codership.com> |
| wsrep_provider_version | 26.4.9(r819f29c) |
| wsrep_ready | ON |
| wsrep_rollbacker_thread_count | 1 |
| wsrep_thread_count | 2 |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
69 rows in set (0.001 sec)
Testing Syncronize MariaDB Cluster Galera
============================================
Create Database with tables and some data record on Node1.
Check data on database at Node 1 and Node 2
If Cluster Galera is running, You can see the same data record on all Node.