Mariadb 集群 Galera Cluster 基于多主架构

文章目录

  • 一、下载安装 Galera Cluster
  • 二、集群搭建
    • Master1
    • Master2
    • Master3

一、下载安装 Galera Cluster

Mariadb10.2.25与Mariadb 5.5安装 galera cluster 区别
Mariadb 10.1版本以后,Galera Cluster 与Mariadb-server包在一起,此版本之前需求单独安装MariaDB-Galera-server 包
Mariadb 集群 Galera Cluster 基于多主架构_第1张图片
官方说明详见:https://mariadb.com/kb/en/library/yum/#importing-the-mariadb-gpg-public-key

yum 安装mariadb 10.2.25 自带安装 galera-25.3.26-1.rhel7.el7.centos.x86_64.rpm


===========================================================================================================================
 Package                             Arch               Version                                  Repository           Size
===========================================================================================================================
Installing:
 MariaDB-compat                      x86_64             10.2.25-1.el7.centos                     mariadb             2.8 M
     replacing  mariadb-libs.x86_64 1:5.5.60-1.el7_5
 MariaDB-server                      x86_64             10.2.25-1.el7.centos                     mariadb              24 M
Installing for dependencies:
 MariaDB-client                      x86_64             10.2.25-1.el7.centos                     mariadb              11 M
 MariaDB-common                      x86_64             10.2.25-1.el7.centos                     mariadb              78 k
 boost-program-options               x86_64             1.53.0-27.el7                            base                156 k
 galera                              x86_64             25.3.26-1.rhel7.el7.centos               mariadb             8.1 M
 perl-Compress-Raw-Bzip2             x86_64             2.061-3.el7                              base                 32 k
 perl-Compress-Raw-Zlib              x86_64             1:2.061-4.el7                            base                 57 k
 perl-DBI                            x86_64             1.627-4.el7                              base                802 k
 perl-Data-Dumper                    x86_64             2.145-3.el7                              base                 47 k
 perl-IO-Compress                    noarch             2.061-2.el7                              base                260 k
 perl-Net-Daemon                     noarch             0.48-5.el7                               base                 51 k
 perl-PlRPC                          noarch             0.2020-14.el7                            base                 36 k

Transaction Summary
===========================================================================================================================

Mariadb 集群 Galera Cluster 基于多主架构_第2张图片
libgalera_smm.so模块路径:/usr/lib64/galera/libgalera_smm.so
Mariadb 集群 Galera Cluster 基于多主架构_第3张图片

二、集群搭建

环境

  • 三台主机Centos 7
  • Mariadb版本:10.2.25
  • 数据库安装源:
[mariadb]
name=mariadb
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mariadb/yum/10.2/centos7-amd64/
gpgcheck=0
  • galera 版本 :galera-25.3.26

具体配置如下:

Master1

1.配置集群功能 server.cnf

[root@CentOS7 ~]#vim /etc/my.cnf.d/server.cnf 
[galera]
wsrep_on=ON                                                                                                      
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address=gcomm://192.168.37.100,192.168.37.102,192.168.37.103
binlog_format=row

2.拷贝server.cnf 配置文件到其他节点主机

[root@CentOS7 ~]#scp /etc/my.cnf.d/server.cnf 192.168.37.102:/etc/my.cnf.d/
[root@CentOS7 ~]#scp /etc/my.cnf.d/server.cnf 192.168.37.102:/etc/my.cnf.d/

3.启动第一个节点

#启动方式与其他节点启动方式不同
#脚本位置:/bin/galera_new_cluster
[root@CentOS7 ~]#/galera_new_cluster 

4.查看集群状态
集群中相关系统变量和状态变量官方说明如下:
https://galeracluster.com/library/documentation/mysql-wsrep-options.html#wsrep-cluster-address

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        | 3                                                           |
| wsrep_cluster_size           | 3            #集群节点数                                         |
| wsrep_cluster_state_uuid     | f28cf819-a895-11e9-87ab-ba77915f46d6                        |
| wsrep_cluster_status         | Primary    #集群节点角色                                             |
| wsrep_cluster_weight         | 3                                                           |
| wsrep_commit_oooe            | 0.000000                                                    |
| wsrep_commit_oool            | 0.000000                                                    |
| wsrep_commit_window          | 0.000000                                                    |
| wsrep_connected              | ON   #wsrep连接状态                                                          |
| 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_paused    | 0.000000                                                    |
| wsrep_flow_control_paused_ns | 0                                                           |
| wsrep_flow_control_recv      | 0                                                           |
| wsrep_flow_control_sent      | 0                                                           |
| wsrep_gcomm_uuid             | f28b8e86-a895-11e9-983e-82b82b368128                        |
| wsrep_incoming_addresses     | 192.168.37.100:3306,192.168.37.102:3306,192.168.37.103: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.100000                                                    |
| 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            | 4                                                           |
| wsrep_local_state_comment    | Synced                                                      |
| wsrep_local_state_uuid       | f28cf819-a895-11e9-87ab-ba77915f46d6                        |
| 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.26(r3857)                                              |
| wsrep_ready                  | ON                                                          |
| wsrep_received               | 10                                                          |
| wsrep_received_bytes         | 854                                                         |
| 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                                                           |
+------------------------------+-------------------------------------------------------------+

Master2

1.启动数据库服务

#启动过程较慢,因为集群的节点在通讯
[root@CentOS7 ~]#systemctl restart mariadb

Master3

1.启动数据库服务

#启动过程较慢,因为集群的节点在通讯
[root@CentOS7 ~]#systemctl restart mariadb

你可能感兴趣的:(linux)