[5] MariaDB – Galera Klaster

27 stycznia 2022 Wyłączono przez Adam [zicherka] Nogły

Skonfiguruj Klaster Galera w MariaDB. Wszystkie węzły w tej konfiguracji pracują jako Master-Serwer.

[1] Zainstaluj pakiet MariaDB Galera na wszystkich węzłach.

[root@vlsr01 ~]# dnf install mariadb-server-galera

[2] Jeżeli Firewalld jest uruchomiony to zezwól na ruch na następujących portach na wszystkich hostach węzła.

[root@vlsr01 ~]# firewall-cmd --add-service=mysql --permanent
[root@vlsr01 ~]# firewall-cmd --add-port={3306/tcp,4567/tcp,4568/tcp,4444/tcp} --permanent
[root@vlsr01 ~]# firewall-cmd --reload

[3] Skonfiguruj pierwszy węzeł.

[root@vlsr01 ~]# mcedit /etc/my.cnf.d/galera.cnf
#linia 34: zmień
wsrep_on=1
#linia 43: ustaw nazwę klastra
wsrep_cluster_name="Galera_Cluster"
#linia 46: odkomentuj i zmień na poniższe
wsrep_cluster_address="gcomm://"
#linia 54: odkomentuj i zmień na adres IP pierwszego węzła
wsrep_node_address="192.168.100.101"

#wystartuj Klaster
[root@vlsr01 ~]# galera_new_cluster
[root@vlsr01 ~]# systemctl enable mariadb

[root@vlsr01 ~]# mcedit /etc/my.cnf.d/galera.cnf
#linia 46: dodaj wszystkie węzły klastra
wsrep_cluster_address="gcomm://192.168.100.101,192.168.100.102"
#uruchom inicjację bazy danych
[root@vlsr01 ~]# mysql_secure_installation

[4] Skonfiguruj pozostałe węzły klastra (z wyjątkiem pierwszego, wcześniej konfigurowanego).

[root@vlsr02 ~]# mcedit /etc/my.cnf.d/galera.cnf
#linia 34: zmień
wsrep_on=1
#linia 43: wpisz nazwę klastra, ustawioną w czasie konfiguracji pierwszego węzła
wsrep_cluster_name="Galera_Cluster"
#linia 46: odkomentuj i wpisz adresy IP wszystkich węzłów w klastrze
wsrep_cluster_address="gcomm://192.168.100.101,192.168.100.102"
#linia 54: odkomentuj i wpisz adres IP danego węzła w klastrze
wsrep_node_address="192.168.100.102"

[root@vlsr02 ~]# systemctl enable --now mariadb

[5] Wszystko jest OK. Potwierdź poprawność pracy klastra. Dobry znak to informacja [wsrep_local_state_comment] ze statusem [Synced].

[root@vlsr02 ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 10.5.9-MariaDB-log 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)]> MariaDB [(none)]> show status like 'wsrep_%';
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
| Variable_name                 | Value                                                                                                                                          |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
| wsrep_local_state_uuid        | 12926db2-7f4c-11ec-b5c1-e7634bba8a6f                                                                                                           |
| wsrep_protocol_version        | 10                                                                                                                                             |
| wsrep_last_committed          | 4                                                                                                                                              |
| 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                | 3                                                                                                                                              |
| wsrep_received_bytes          | 224                                                                                                                                            |
| 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    | 1                                                                                                                                              |
| wsrep_local_recv_queue_min    | 0                                                                                                                                              |
| wsrep_local_recv_queue_avg    | 0                                                                                                                                              |
| wsrep_local_cached_downto     | 2                                                                                                                                              |
| 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      | 1                                                                                                                                              |
| wsrep_apply_oooe              | 0                                                                                                                                              |
| wsrep_apply_oool              | 0                                                                                                                                              |
| wsrep_apply_window            | 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         | 2                                                                                                                                              |
| wsrep_causal_reads            | 0                                                                                                                                              |
| wsrep_cert_interval           | 2.5                                                                                                                                            |
| 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.00012882/0.000366167/0.00102964/0.000338387/5                                                                                                |
| wsrep_evs_state               | OPERATIONAL                                                                                                                                    |
| wsrep_gcomm_uuid              | ea5ae47e-7f4c-11ec-8206-ab1a45ff85f7                                                                                                           |
| 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      | 12926db2-7f4c-11ec-b5c1-e7634bba8a6f                                                                                                           |
| 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        | 4.7(rXXXX)                                                                                                                                     |
| wsrep_ready                   | ON                                                                                                                                             |
| wsrep_rollbacker_thread_count | 1                                                                                                                                              |
| wsrep_thread_count            | 2                                                                                                                                              |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
68 rows in set (0.001 sec)