Friday, March 4, 2022

.::: How to Create HA (High Availability) MariaDB/MySQL using Galera Cluster on Linux from Course (without password) Udemy :::.



A. Installation Galera Cluster (example on 2 node = mariadb01, mariadb02)
1. Disable selinux
[root@mariadb01 ~]# sestatus
SELinux status:                 disabled
[root@mariadb01 ~]# cat /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

[root@mariadb01 ~]#

 
2. alow/disable firewall
# systemctl stop firewalld
# systemctl disable firewalld
# systemctl status firewalld
[root@mariadb01 ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)
[root@mariadb01 ~]#


3. additional node to /etc/hosts

10.10.10.51 mariadb01
10.10.10.52 mariadb02


[root@mariadb01 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.10.10.51 mariadb01
10.10.10.52 mariadb02

[root@mariadb01 ~]#

 

4. remove mariadb-libs
[root@mariadb01 ~]# rpm -qa | grep maria
mariadb-libs-5.5.68-1.el7.x86_64
[root@mariadb01 ~]# yum remove mariadb-libs -y
[root@mariadb01 ~]# rpm -qa | grep maria
[root@mariadb01 ~]#


5. create cluster repo mariadb
[root@mariadb01 ~]# cat /etc/yum.repos.d/cluster.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey = https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

[root@mariadb01 ~]#
[root@mariadb01 ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.mirror.angkasa.id
 * extras: mirror.dewabiz.com
 * updates: centos.mirror.angkasa.id
repo id                                 repo name                                 status
base/7/x86_64                           CentOS-7 - Base                           10,072
extras/7/x86_64                         CentOS-7 - Extras                            498
mariadb                                 MariaDB                                       43
updates/7/x86_64                        CentOS-7 - Updates                         2,458
repolist: 13,071
[root@mariadb01 ~]#


6. install socat (optional)
[root@mariadb01 ~]# yum -y install socat

7. install MariaDB galera cluster package on node 1 2

[root@mariadb01 ~]# yum -y install MariaDB-server MariaDB-client
[root@mariadb01 ~]# rpm -qa | grep MariaDB*
MariaDB-client-10.1.48-1.el7.centos.x86_64
MariaDB-common-10.1.48-1.el7.centos.x86_64
MariaDB-server-10.1.48-1.el7.centos.x86_64

[root@mariadb01 ~]# rpm -qa | grep galera*
galera-25.3.31-1.el7.centos.x86_64
[root@mariadb01 ~]#


8. start  & enable mariadb
[root@mariadb01 ~]# systemctl start mariadb
[root@mariadb01 ~]# systemctl enable mariadb


9. secure mysql
# mysql_secure_installation

[root@mariadb01 ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.0.38-MariaDB-wsrep MariaDB Server, wsrep_25.25.rc3fc46e

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>



B. Configuration MariaDB / Galera Cluster
1. stop mariadb
# systemctl stop mariadb

[root@mariadb01 ~]# systemctl stop mariadb
[root@mariadb01 ~]# systemctl status mariadb
[root@mariadb01 ~]#


2. Configuration to mariadb01 /etc/my.cnf.d/server.cnf


[root@mariadb01 ~]# cat /etc/my.cnf.d/server.cnf
#
......................
# * Galera-related settings
#
[galera]
wsrep_on=ON
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address="gcomm://10.10.10.51,10.10.10.52"
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
wsrep_cluster_name="cluster1"
wsrep_sst_method=rsync
wsrep_node_address= "10.10.10.51"
wsrep_node_name="mariadb01"

#wsrep_sst_auth=teguh:triharto

.........
[root@mariadb01 ~]#



3. Configuration to mariadb02 /etc/my.cnf.d/server.cnf

[root@mariadb02 ~]# cat /etc/my.cnf.d/server.cnf
#
....................
# * Galera-related settings
#
[galera]
wsrep_on=ON
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address="gcomm://10.10.10.51,10.10.10.52"
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
wsrep_cluster_name="cluster1"
wsrep_sst_method=rsync
wsrep_node_address= "10.10.10.52"
wsrep_node_name="mariadb02"
#wsrep_sst_auth=teguh:triharto

..............
[root@mariadb02 ~]#


5. node 1 start mysql
[root@mariadb01 ~]# galera_new_cluster
[root@mariadb01 ~]#

[root@mariadb01 ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.1.48-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.

MariaDB [(none)]> show status like 'wsrep%';
+------------------------------+-----------------------------------------------+
| Variable_name                | Value                                         |
+------------------------------+-----------------------------------------------+
| wsrep_apply_oooe             | 0.000000                                      |
| wsrep_apply_oool             | 0.000000                                      |
| wsrep_apply_window           | 0.000000                                      |
| wsrep_causal_reads           | 0                                             |
| wsrep_cert_deps_distance     | 0.000000                                      |
| wsrep_cert_index_size        | 0                                             |
| wsrep_cert_interval          | 0.000000                                      |
| wsrep_cluster_conf_id        | 2                                             |
| wsrep_cluster_size           | 2                                             |
| wsrep_cluster_state_uuid     | 017021e7-9b73-11ec-8509-7f2cf8b87c0b          |
| wsrep_cluster_status         | Primary                                       |
| wsrep_cluster_weight         | 2                                             |
| wsrep_commit_oooe            | 0.000000                                      |
| wsrep_commit_oool            | 0.000000                                      |
| wsrep_commit_window          | 0.000000                                      |
| wsrep_connected              | ON                                            |
| wsrep_desync_count           | 1                                             |
| wsrep_evs_delayed            |                                               |
| wsrep_evs_evict_list         |                                               |
| wsrep_evs_repl_latency       | 0.000930992/0.0020817/0.00469241/0.00152643/4 |
| wsrep_evs_state              | OPERATIONAL                                   |
| wsrep_flow_control_active    | false                                         |
| wsrep_flow_control_paused    | 0.000000                                      |
| wsrep_flow_control_paused_ns | 0                                             |
| wsrep_flow_control_recv      | 0                                             |
| wsrep_flow_control_requested | false                                         |
| wsrep_flow_control_sent      | 0                                             |
| wsrep_gcomm_uuid             | 016dc622-9b73-11ec-9899-3fa7b75721c2          |
| wsrep_gmcast_segment         | 0                                             |
| wsrep_incoming_addresses     | 10.10.10.51:3306,10.10.10.52:3306             |
| wsrep_last_committed         | 0                                             |
| wsrep_local_bf_aborts        | 0                                             |
| wsrep_local_cached_downto    | 18446744073709551615                          |
| wsrep_local_cert_failures    | 0                                             |
| wsrep_local_commits          | 0                                             |
| wsrep_local_index            | 0                                             |
| wsrep_local_recv_queue       | 0                                             |
| wsrep_local_recv_queue_avg   | 0.250000                                      |
| wsrep_local_recv_queue_max   | 2                                             |
| wsrep_local_recv_queue_min   | 0                                             |
| wsrep_local_replays          | 0                                             |
| wsrep_local_send_queue       | 0                                             |
| wsrep_local_send_queue_avg   | 0.000000                                      |
| wsrep_local_send_queue_max   | 1                                             |
| wsrep_local_send_queue_min   | 0                                             |
| wsrep_local_state            | 2                                             |
| wsrep_local_state_comment    | Donor/Desynced                                |
| wsrep_local_state_uuid       | 017021e7-9b73-11ec-8509-7f2cf8b87c0b          |
| wsrep_open_connections       | 0                                             |
| wsrep_open_transactions      | 0                                             |
| wsrep_protocol_version       | 9                                             |
| wsrep_provider_name          | Galera                                        |
| wsrep_provider_vendor        | Codership Oy <info@codership.com>             |
| wsrep_provider_version       | 25.3.31(r0ede97d)                             |
| wsrep_ready                  | ON                                            |
| wsrep_received               | 4                                             |
| wsrep_received_bytes         | 399                                           |
| wsrep_repl_data_bytes        | 0                                             |
| wsrep_repl_keys              | 0                                             |
| wsrep_repl_keys_bytes        | 0                                             |
| wsrep_repl_other_bytes       | 0                                             |
| wsrep_replicated             | 0                                             |
| wsrep_replicated_bytes       | 0                                             |
| wsrep_thread_count           | 2                                             |
+------------------------------+-----------------------------------------------+
64 rows in set (0.00 sec)

MariaDB [(none)]>


6. node 2 start mysql/mariadb
systemctl start mariadb

[root@teguhth02 ~]# systemctl start mariadb
[root@teguhth02 ~]#

[root@mariadb02 ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 10.1.48-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.

MariaDB [(none)]> show status like 'wsrep%';
+------------------------------+--------------------------------------+
| Variable_name                | Value                                |
+------------------------------+--------------------------------------+
| wsrep_apply_oooe             | 0.000000                             |
| wsrep_apply_oool             | 0.000000                             |
| wsrep_apply_window           | 1.000000                             |
| wsrep_causal_reads           | 0                                    |
| wsrep_cert_deps_distance     | 1.000000                             |
| wsrep_cert_index_size        | 2                                    |
| wsrep_cert_interval          | 0.000000                             |
| wsrep_cluster_conf_id        | 2                                    |
| wsrep_cluster_size           | 2                                    |
| wsrep_cluster_state_uuid     | 017021e7-9b73-11ec-8509-7f2cf8b87c0b |
| wsrep_cluster_status         | Primary                              |
| wsrep_cluster_weight         | 2                                    |
| wsrep_commit_oooe            | 0.000000                             |
| wsrep_commit_oool            | 0.000000                             |
| wsrep_commit_window          | 1.000000                             |
| wsrep_connected              | ON                                   |
| 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_flow_control_active    | false                                |
| wsrep_flow_control_paused    | 0.000000                             |
| wsrep_flow_control_paused_ns | 0                                    |
| wsrep_flow_control_recv      | 0                                    |
| wsrep_flow_control_requested | false                                |
| wsrep_flow_control_sent      | 0                                    |
| wsrep_gcomm_uuid             | 4283efc4-9b73-11ec-b4fd-738e6b09e84d |
| wsrep_gmcast_segment         | 0                                    |
| wsrep_incoming_addresses     | 10.10.10.51:3306,10.10.10.52:3306    |
| wsrep_last_committed         | 2                                    |
| wsrep_local_bf_aborts        | 0                                    |
| wsrep_local_cached_downto    | 1                                    |
| wsrep_local_cert_failures    | 0                                    |
| wsrep_local_commits          | 0                                    |
| wsrep_local_index            | 1                                    |
| wsrep_local_recv_queue       | 0                                    |
| wsrep_local_recv_queue_avg   | 0.000000                             |
| wsrep_local_recv_queue_max   | 1                                    |
| wsrep_local_recv_queue_min   | 0                                    |
| wsrep_local_replays          | 0                                    |
| wsrep_local_send_queue       | 0                                    |
| wsrep_local_send_queue_avg   | 0.000000                             |
| wsrep_local_send_queue_max   | 1                                    |
| wsrep_local_send_queue_min   | 0                                    |
| wsrep_local_state            | 4                                    |
| wsrep_local_state_comment    | Synced                               |
| wsrep_local_state_uuid       | 017021e7-9b73-11ec-8509-7f2cf8b87c0b |
| wsrep_open_connections       | 0                                    |
| wsrep_open_transactions      | 0                                    |
| wsrep_protocol_version       | 9                                    |
| wsrep_provider_name          | Galera                               |
| wsrep_provider_vendor        | Codership Oy <info@codership.com>    |
| wsrep_provider_version       | 25.3.31(r0ede97d)                    |
| wsrep_ready                  | ON                                   |
| wsrep_received               | 4                                    |
| wsrep_received_bytes         | 672                                  |
| wsrep_repl_data_bytes        | 346                                  |
| wsrep_repl_keys              | 1                                    |
| wsrep_repl_keys_bytes        | 32                                   |
| wsrep_repl_other_bytes       | 0                                    |
| wsrep_replicated             | 1                                    |
| wsrep_replicated_bytes       | 448                                  |
| wsrep_thread_count           | 2                                    |
+------------------------------+--------------------------------------+
64 rows in set (0.00 sec)

MariaDB [(none)]>



C. Testing database clustering

for testing can use https://teguhth.blogspot.com/2021/07/how-to-create-ha-high-availability.html

No comments:

Post a Comment

Popular Posts