Galera集群介绍

MariaDB集群是MariaDB同步多主机集群。它仅支持XtraDB/ InnoDB存储引擎。

主要功能

  

  • 同步复制
  • 真正的multi-master,即所有节点可以同时读写数据库
  • 自动的节点成员控制,失效节点自动被清除
  • 新节点加入数据自动复制
  • 真正的并行复制,行级
  • 用户可以直接连接集群,使用感受上与MySQL完全一致

优势

  • 因为是多主,所以不存在Slavelag(延迟)
  • 不存在丢失事务的情况
  • 同时具有读和写的扩展能力
  • 更小的客户端延迟
  • 节点间数据是同步的,而Master/Slave模式是异步的,不同slave上的binlog可能是不同的

技术

Galera集群的复制功能基于Galeralibrary实现,为了让MySQL与Galera library通讯,特别针对MySQL开发了wsrep API。

Galera插件保证集群同步数据,保持数据的一致性,靠的就是可认证的复制,工作原理如下图:

当客户端发出一个commit的指令,在事务被提交之前,所有对数据库的更改都会被 write-set 收集起来,并且将 write-set 纪录的内容发送给其他节点。

write-set 将在每个节点进行认证测试,测试结果决定着节点是否应用write-set更改数据。

如果认证测试失败,节点将丢弃 write-set ;如果认证测试成功,则事务提交。

安装环境准备

准备三台服务器

操作系统版本: centos7

数据库版本:5.5.56-MariaDB

主节点:192.168.64.4

节点1:192.168.64.5

节点2:192.168.64.7

各个节点之间需要解析

[root@ken-node1 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
:: localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.64.4 ken-node1
192.168.64.5 ken-node2
192.168.64.7 ken-node3

配置yum源

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.3.5/centos74-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=
enabled=

安装配置

第一步:在各个节点下载下面的软件包

[root@ken ~]# yum install -y MariaDB-server MariaDB-client galera -y

第二步: 初始化数据库

只需要在一个节点执行即可192.168.64.4

[root@ken ~]# systemctl restart mariadb
[root@ken ~]# mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here. Enter current password for root (enter for none):
OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation. Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success! By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment. Remove anonymous users? [Y/n] y
... Success! Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] n
... skipping. By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment. Remove test database and access to it? [Y/n] n
... skipping. Reloading the privilege tables will ensure that all changes made so far
will take effect immediately. Reload privilege tables now? [Y/n] y
... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!

第三步:关闭数据库,修改/etc/my.cnf.d/server.cnf

在主配置节点配置如下

[root@ken ~]# systemctl stop mariadb
[root@ken ~]# 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.64.4,192.168.64.5,192.168,64.7" #节点IP地址
wsrep_node_name= ken-node1 #主节点主机名
wsrep_node_address=192.168.64.4 #主节点IP
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=
wsrep_slave_threads=
innodb_flush_log_at_trx_commit=
innodb_buffer_pool_size=120M
wsrep_sst_method=rsync
wsrep_causal_reads=ON

第四步:将此文件复制到mariadb-2、mariadb-3,注意要把 wsrep_node_name 和 wsrep_node_address 改成相应节点的 hostname 和 ip。

第五步:启动集群

主节点192.168.64.4启动命令如下:

[root@ken-node1 ~]# galera_new_cluster 

各个节点监听的端口

集群服务监听了4567和3306端口(每个节点都监听了4567和3306端口)

[root@ken-node1 ~]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN *: *:*
LISTEN *: *:*
LISTEN 127.0.0.1: *:*
LISTEN ::: :::*
LISTEN ::: :::*
LISTEN ::: :::*
LISTEN ::: :::*

其他节点启动命令如下:

[root@ken-node2 ~]# systemctl restart mariadb

验证集群

在主节点执行如下操作

连接mariadb,查看是否启用galera插件

显示ON表示开启

MariaDB [(none)]> show status like "wsrep_ready";
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wsrep_ready | ON |
+---------------+-------+
row in set (0.005 sec)

查看目前集群机器数

机器数为3个显示正确

MariaDB [(none)]> show status like "wsrep_cluster_size";
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| wsrep_cluster_size | |
+--------------------+-------+
row in set (0.003 sec)

查看集群状态

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 | |
| wsrep_cert_deps_distance | 0.000000 |
| wsrep_cert_index_size | |
| wsrep_cert_interval | 0.000000 |
| wsrep_cluster_conf_id | |
| wsrep_cluster_size | |
| wsrep_cluster_state_uuid | 541248ce-56d0-11e9-b41b-3a9775d73ca7 |
| wsrep_cluster_status | Primary #主服务器 |
| wsrep_commit_oooe | 0.000000 |
| wsrep_commit_oool | 0.000000 |
| wsrep_commit_window | 0.000000 |
| wsrep_connected | ON #当前是否连接中 |
| wsrep_desync_count | |
| wsrep_evs_delayed | |
| wsrep_evs_evict_list | |
| wsrep_evs_repl_latency | //// |
| wsrep_evs_state | OPERATIONAL |
| wsrep_flow_control_paused | 0.000000 |
| wsrep_flow_control_paused_ns | |
| wsrep_flow_control_recv | |
| wsrep_flow_control_sent | |
| wsrep_gcomm_uuid | 540ee869-56d0-11e9-955e-9b7f30e437a6 |
| wsrep_incoming_addresses | 192.168.64.5:,192.168.64.4:,192.168.64.7: | #连接中的数据库
| wsrep_last_committed | |
| wsrep_local_bf_aborts | |
| wsrep_local_cached_downto | |
| wsrep_local_cert_failures | |
| wsrep_local_commits | |
| wsrep_local_index | |
| wsrep_local_recv_queue | |
| wsrep_local_recv_queue_avg | 0.100000 |
| wsrep_local_recv_queue_max | |
| wsrep_local_recv_queue_min | |
| wsrep_local_replays | |
| wsrep_local_send_queue | |
| wsrep_local_send_queue_avg | 0.000000 |
| wsrep_local_send_queue_max | |
| wsrep_local_send_queue_min | |
| wsrep_local_state | |
| wsrep_local_state_comment | Synced |
| wsrep_local_state_uuid | 541248ce-56d0-11e9-b41b-3a9775d73ca7 |
| wsrep_protocol_version | |
| wsrep_provider_name | Galera |
| wsrep_provider_vendor | Codership Oy <info@codership.com> |
| wsrep_provider_version | 25.3.(r3789) |
| wsrep_ready | ON |
| wsrep_received | |
| wsrep_received_bytes | |
| wsrep_repl_data_bytes | |
| wsrep_repl_keys | |
| wsrep_repl_keys_bytes | |
| wsrep_repl_other_bytes | |
| wsrep_replicated | |
| wsrep_replicated_bytes | |
| wsrep_thread_count | |
+------------------------------+-------------------------------------------------------+
rows in set (0.002 sec)

查看连接的主机

MariaDB [(none)]> show status like "wsrep_incoming_addresses";
+--------------------------+-------------------------------------------------------+
| Variable_name | Value |
+--------------------------+-------------------------------------------------------+
| wsrep_incoming_addresses | 192.168.64.5:,192.168.64.4:,192.168.64.7: |
+--------------------------+-------------------------------------------------------+
row in set (0.001 sec)

测试集群是否同步

在各个节点创建数据库,可以发现每个节点都可以同步

我在192.168.64.4创建ken数据库

[root@ken-node1 ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is
Server version: 10.3.-MariaDB MariaDB Server Copyright (c) , , Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> create database ken;
Query OK, row affected (0.041 sec) MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| ken |
| ken1 |
| mysql |
| performance_schema |
| test |
+--------------------+
rows in set (0.001 sec)

在192.168.64.5节点上查看数据库

[root@ken-node2 ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is
Server version: 10.3.-MariaDB MariaDB Server Copyright (c) , , Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| ken | #ken数据库已经同步过来
| mysql |
| performance_schema |
| test |
+--------------------+
rows in set (0.002 sec)

192.168.64.7节点上查看数据库

[root@ken-node3 ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is
Server version: 10.3.-MariaDB MariaDB Server Copyright (c) , , Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| ken | #ken数据库已经同步 |
| mysql |
| performance_schema |
| test |
+--------------------+
rows in set (0.002 sec)

MariaDB Galera集群部署--技术流ken的更多相关文章

  1. Linux下MySQL/MariaDB Galera集群搭建过程【转】

    MariaDB介绍 MariaDB是开源社区维护的一个MySQL分支,由MySQL的创始人Michael Widenius主导开发,采用GPL授权许可证. MariaDB的目的是完全兼容MySQL,包 ...

  2. Mariadb galera 集群

    部署galera 多主架构 (galera集群多用于关键性业务,因为galera集群为了数据的一致性,采用的是同步的机制,这就使galera牺牲了一部分性能来换取数据一致性.) 环境准备:三台服务器 ...

  3. mysql基础之mariadb galera集群(多主)

    一.概念 galera集群多用于关键性业务,因为galera集群为了数据的一致性,采用的是同步的机制,这就使galera牺牲了一部分性能来换取数据一致性. galera集群是基于wsrep协议(端口4 ...

  4. Linux下MySQL/MariaDB Galera集群搭建过程

    MariaDB介绍 MariaDB是开源社区维护的一个MySQL分支,由MySQL的创始人Michael Widenius主导开发,采用GPL授权许可证. MariaDB的目的是完全兼容MySQL,包 ...

  5. MariaDB GALERA 集群双节点部署

    节点1:10.2.2.41 节点2:10.2.2.42 软件: mariadb-galera-10.0.22-linux-x86_64.tar.gz #galera相关参数:(两个节点配置文件类似) ...

  6. zabbix分布式监控部署--技术流ken

    前言 zabbix proxy可以代替zabbix server检索客户端的数据,然后把数据汇报给zabbix server,并且在一定程度上分担了zabbix server的压力.zabbix pr ...

  7. openstack高可用集群21-生产环境高可用openstack集群部署记录

    第一篇 集群概述 keepalived + haproxy +Rabbitmq集群+MariaDB Galera高可用集群   部署openstack时使用单个控制节点是非常危险的,这样就意味着单个节 ...

  8. mysql主从配置和galera集群

    mariadb主从 主从多用于网站架构,因为主从的同步机制是异步的,数据的同步有一定延迟,也就是说有可能会造成数据的丢失,但是性能比较好,因此网站大多数用的是主从架构的数据库,读写分离必须基于主从架构 ...

  9. 使用kolla安装的openstack mariadb为集群所有节点无法启动

    当在做测试时,把所有的openstack节点都关机,再开启做测试时,发现mariadb galera集群启不来,相当于所有的mariadb集群都停止了(跟所有节点断电情况相似),这时候怎么办呢,重新建 ...

随机推荐

  1. BZOJ_1146_[CTSC2008]网络管理Network_主席树+树状数组

    BZOJ_1146_[CTSC2008]网络管理Network_主席树 Description M公司是一个非常庞大的跨国公司,在许多国家都设有它的下属分支机构或部门.为了让分布在世界各地的N个 部门 ...

  2. netcore 获取本地网络IP地址

    .net framework 下面可以用下面的代码获取到本地网络ip地址.netcore下面这个代码也依然可以用 System.Net.Dns.GetHostName() System.Net.Dns ...

  3. 如何优雅地在 Spring Boot 中使用自定义注解,AOP 切面统一打印出入参日志 | 修订版

    欢迎关注个人微信公众号: 小哈学Java, 文末分享阿里 P8 资深架构师吐血总结的 <Java 核心知识整理&面试.pdf>资源链接!! 个人网站: https://www.ex ...

  4. Java集合--TreeSet详细解析

    目录 1.构造函数 2.增 3.删 4.比较器 总结 谈到TreeSet的特点,估计大家脑海里想到的都是:有序,不可重复,红黑树,基于Treemap实现,自定义排序等特点.这篇博客帮助大家从源码梳理下 ...

  5. 【Android】自己动手做个扫雷游戏

    1. 游戏规则 扫雷是玩法极其简单的小游戏,点击玩家认为不存在雷的区域,标记出全部地雷所在的区域,即可获得胜利.当点击不包含雷的块的时候,可能它底下存在一个数,也可能是一个空白块.当点击中有数字的块时 ...

  6. TensorFlow从1到2(三)数据预处理和卷积神经网络

    数据集及预处理 从这个例子开始,相当比例的代码都来自于官方新版文档的示例.开始的几个还好,但随后的程序都将需要大量的算力支持.Google Colab是一个非常棒的云端实验室,提供含有TPU/GPU支 ...

  7. 面试前必须知道的MySQL命令【explain】

    前言 只有光头才能变强 刷面试题的时候,不知道你们有没有见过MySQL这两个命令:explain和profile(反正我就见过了).. 之前虽然知道这两个命令大概什么意思,但一直没有去做笔记.今天发现 ...

  8. UiPath实践经验总结(二)

    1.       UI操作容易受到各种意外的干扰,因此应该缩短UI操作阶段的总体时间.而为了缩短UI操作阶段的总体时间,应该将UI操作尽量放在一起,将后台的各种操作尽量放在UI操作的前后.例如,现在有 ...

  9. gitbook 入门教程之使用 gitbook-editor 编辑器开发电子书

    亲测,目前已不再支持旧版 gitbook-editor 编辑器,而官网也没有相应的新版编辑器,如果哪位找到了新版编辑器,还望告知! 现在注册 gitbook 账号会默认重定向到 新版官网,而 旧版官网 ...

  10. Jmeter + Grafana搭建实时监控可视化

    小贴士: 建议使用jmeter3.3+版本,在这个版本以后才有backend listenter 对接influxDB. Jmeter中backend listenter如图 ​ influxdbUr ...