Galera-MariaDB多主集群搭建
简介Galera Cluster for MySQL是一种同步复制解决方案,可以提高MySQL服务的可用性和性能。所有Galera Cluster节点都是相同的,完全代表集群,允许无约束的透明mysql客户端访问,充当单分布式MySQL服务器。它提供:透明的客户端连接,因此它与现有应用程序高度兼容;同步数据安全语义 - 如果客户端收到确认,将在每个节点上提交事务;自动写入冲突检测和解决,...
简介
Galera Cluster for MySQL是一种同步复制解决方案,可以提高MySQL服务的可用性和性能。所有Galera Cluster节点都是相同的,完全代表集群,允许无约束的透明mysql客户端访问,充当单分布式MySQL服务器。它提供:
- 透明的客户端连接,因此它与现有应用程序高度兼容;
- 同步数据安全语义 - 如果客户端收到确认,将在每个节点上提交事务;
- 自动写入冲突检测和解决,使节点始终保持一致。
特性:
- 同步复制 Synchronous replication
- Active-active multi-master 拓扑逻辑
- 可对集群中任一节点进行数据读写
- 自动成员控制,故障节点自动从集群中移除
- 自动节点加入
- 真正并行的复制,基于行级
- 直接客户端连接,原生的 MySQL 接口
- 每个节点都包含完整的数据副本
- 多台数据库中数据同步由 wsrep 接口实现
安装
- 官方资源
资源下载地址:http://galeracluster.com/downloads/#downloads
技术说明:http://galeracluster.com/documentation-webpages/technicaldescription.html
GALERA集群文档:http://galeracluster.com/documentation-webpages/index.html
- 下载资源文件
为了担心菜鸟们迷路附带云盘下载地址: https://pan.baidu.com/s/1oACpqNg_E7K4ED3DOLku_Q 提取码: dkbc
节点环境
节点IP
Node1 IP192.168.0.1
Node2 IP198.168.0.2
Node3 IP192.168.0.3
依次安装所有rpm包(三个节点安装步骤一致)
rpm -ivh *.rpm --nodeps --force
节点安装完成后开始配置初始化数据库
vi /etc/my.cnf
复制下面内容到文件里
[client-server]
socket=/opt/mysql_data/mysql/mysql.sock
[mysqld]
user=mysql
datadir=/opt/mysql_data/mysql
socket=/opt/mysql_data/mysql/mysql.sock
#skip-grant-tables
language = /usr/share/mysql/english
[mysqld_safe]
log-error=/opt/mysql_data/mysql/mysql-err.log
pid-file=/opt/mysql_data/mysql/mysqld.pid
!includedir /etc/my.cnf.d
初始化数据库
[root@F8SFRZ ~]$ mkdir -p /opt/mysql_data/mysql/
[root@F8SFRZ ~]$ chown -R mysql:mysql /opt/mysql_data
[root@F8SFRZ ~]$ mysql_install_db --defaults-file=/etc/my.cnf
启动数据库
第一种启动方式
[root@F8SFRZ ~]$ systemctl start mariadb
第二种启动方式
第一台:
sudo /bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --wsrep-new-cluste&
其余:
sudo /bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql&
设置允许mysql远程调用
mysql -uroot -p
输入密码
回车
mysql> use mysql;
mysql> GRANT ALL PRIVILEGES ON *.* TO '用户名'@'%'IDENTIFIED BY '密码' WITH GRANT OPTION;
mysql> flush privileges;
可以找任意一款数据库客户端连接工具验证远程调用配置是否生效博主用的是Navicat Premium 12 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_ready";
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wsrep_ready | ON | ON:启动 OFF:未启动
+---------------+-------+
1 row in set (0.00 sec)
MariaDB [(none)]> show status like "wsrep_cluster_size";
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| wsrep_cluster_size | 2 |
+--------------------+-------+
1 row in set (0.00 sec)
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 | 112 |
| wsrep_cert_deps_distance | 1.000000 |
| wsrep_cert_index_size | 636 |
| wsrep_cert_interval | 0.000000 |
| wsrep_cluster_conf_id | 4 |
| wsrep_cluster_size | 2 |
| wsrep_cluster_state_uuid | 9a9861c4-3a57-11e9-aa90-ebcd6c18b14f |
| wsrep_cluster_status | Primary |
| 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_paused | 0.000000 |
| wsrep_flow_control_paused_ns | 0 |
| wsrep_flow_control_recv | 0 |
| wsrep_flow_control_sent | 0 |
| wsrep_gcomm_uuid | 5fcaa3ef-3a59-11e9-ac9c-17e0602c0385 |
| wsrep_incoming_addresses | 192.168.0.1:3306,192.168.0.2:3306,192.168.0.3:3306 |
| wsrep_last_committed | 113 |
| wsrep_local_bf_aborts | 0 |
| wsrep_local_cached_downto | 4 |
| wsrep_local_cert_failures | 0 |
| wsrep_local_commits | 20 |
| wsrep_local_index | 0 |
| 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.008850 |
| wsrep_local_send_queue_max | 2 |
| wsrep_local_send_queue_min | 0 |
| wsrep_local_state | 4 |
| wsrep_local_state_comment | Synced |
| wsrep_local_state_uuid | 9a9861c4-3a57-11e9-aa90-ebcd6c18b14f |
| wsrep_protocol_version | 7 |
| wsrep_provider_name | Galera |
| wsrep_provider_vendor | Codership Oy <info@codership.com> |
| wsrep_provider_version | 25.3.22(r3764) |
| wsrep_ready | ON |
| wsrep_received | 5 |
| wsrep_received_bytes | 717 |
| wsrep_repl_data_bytes | 1216105 |
| wsrep_repl_keys | 1670 |
| wsrep_repl_keys_bytes | 15879 |
| wsrep_repl_other_bytes | 0 |
| wsrep_replicated | 109 |
| wsrep_replicated_bytes | 1238960 |
| wsrep_thread_count | 2 |
+------------------------------+--------------------------------------+
58 rows in set (0.00 sec)
MariaDB [(none)]> exit
[root@F8SFRZ ~]$
[root@F8SFRZ ~]$
[root@F8SFRZ ~]$
[root@F8SFRZ ~]$
测试数据库集群同步
[root@F8SFRZ ~]$ mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 909
Server version: 10.1.36-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)]> create database testGalera;
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| testGalera |
+--------------------+
5 rows in set (0.00 sec)
MariaDB [(none)]> exit
连接到Node2、Node3节点,连接mysql,查看【testGalera】同步
注意:Galera最好是奇数台,3台起步,因为集群对外提供服务需要保持在半数以上才能对外提供服务(zokeerper同理)
MariaDB Galera局限性
- 目前的复制仅仅支持InnoDB存储引擎,任何写入其他引擎的表,包括mysql.*表将不会复制,但是DDL语句会被复制的,因此创建用户将会被复制,但是insert into mysql.user…将不会被复制的;
- DELETE操作不支持没有主键的表,没有主键的表在不同的节点顺序将不同,如果执行SELECT…LIMIT… 将出现不同的结果集.
- 在多主环境下LOCK/UNLOCK TABLES不支持,以及锁函数GET_LOCK(), RELEASE_LOCK();
- 查询日志不能保存在表中。如果开启查询日志,只能保存到文件中;
- 允许最大的事务大小由wsrep_max_ws_rows和wsrep_max_ws_size定义。任何大型操作将被拒绝。如大型的LOAD DATA操作;
- 如果DDL语句有问题将破坏集群
更多推荐
所有评论(0)