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

各个节点之间需要解析

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

配置yum源

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

安装配置

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

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

第二步: 初始化数据库

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

  1. [root@ken ~]# systemctl restart mariadb
  2. [root@ken ~]# mysql_secure_installation
  3.  
  4. NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
  5. SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
  6.  
  7. In order to log into MariaDB to secure it, we'll need the current
  8. password for the root user. If you've just installed MariaDB, and
  9. you haven't set the root password yet, the password will be blank,
  10. so you should just press enter here.
  11.  
  12. Enter current password for root (enter for none):
  13. OK, successfully used password, moving on...
  14.  
  15. Setting the root password ensures that nobody can log into the MariaDB
  16. root user without the proper authorisation.
  17.  
  18. Set root password? [Y/n] y
  19. New password:
  20. Re-enter new password:
  21. Password updated successfully!
  22. Reloading privilege tables..
  23. ... Success!
  24.  
  25. By default, a MariaDB installation has an anonymous user, allowing anyone
  26. to log into MariaDB without having to have a user account created for
  27. them. This is intended only for testing, and to make the installation
  28. go a bit smoother. You should remove them before moving into a
  29. production environment.
  30.  
  31. Remove anonymous users? [Y/n] y
  32. ... Success!
  33.  
  34. Normally, root should only be allowed to connect from 'localhost'. This
  35. ensures that someone cannot guess at the root password from the network.
  36.  
  37. Disallow root login remotely? [Y/n] n
  38. ... skipping.
  39.  
  40. By default, MariaDB comes with a database named 'test' that anyone can
  41. access. This is also intended only for testing, and should be removed
  42. before moving into a production environment.
  43.  
  44. Remove test database and access to it? [Y/n] n
  45. ... skipping.
  46.  
  47. Reloading the privilege tables will ensure that all changes made so far
  48. will take effect immediately.
  49.  
  50. Reload privilege tables now? [Y/n] y
  51. ... Success!
  52.  
  53. Cleaning up...
  54.  
  55. All done! If you've completed all of the above steps, your MariaDB
  56. installation should now be secure.
  57. Thanks for using MariaDB!

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

在主配置节点配置如下

  1. [root@ken ~]# systemctl stop mariadb
  2. [root@ken ~]# vim /etc/my.cnf.d/server.cnf
  3. ...
  4. [galera]
  5. wsrep_on=ON
  6. wsrep_provider=/usr/lib64/galera/libgalera_smm.so
  7. wsrep_cluster_address="gcomm://192.168.64.4,192.168.64.5,192.168,64.7" #节点IP地址
  8. wsrep_node_name= ken-node1 #主节点主机名
  9. wsrep_node_address=192.168.64.4 #主节点IP
  10. binlog_format=row
  11. default_storage_engine=InnoDB
  12. innodb_autoinc_lock_mode=
  13. wsrep_slave_threads=
  14. innodb_flush_log_at_trx_commit=
  15. innodb_buffer_pool_size=120M
  16. wsrep_sst_method=rsync
  17. wsrep_causal_reads=ON

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

第五步:启动集群

主节点192.168.64.4启动命令如下:

  1. [root@ken-node1 ~]# galera_new_cluster

各个节点监听的端口

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

  1. [root@ken-node1 ~]# ss -tnl
  2. State Recv-Q Send-Q Local Address:Port Peer Address:Port
  3. LISTEN *: *:*
  4. LISTEN *: *:*
  5. LISTEN 127.0.0.1: *:*
  6. LISTEN ::: :::*
  7. LISTEN ::: :::*
  8. LISTEN ::: :::*
  9. LISTEN ::: :::*

其他节点启动命令如下:

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

验证集群

在主节点执行如下操作

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

显示ON表示开启

  1. MariaDB [(none)]> show status like "wsrep_ready";
  2. +---------------+-------+
  3. | Variable_name | Value |
  4. +---------------+-------+
  5. | wsrep_ready | ON |
  6. +---------------+-------+
  7. row in set (0.005 sec)

查看目前集群机器数

机器数为3个显示正确

  1. MariaDB [(none)]> show status like "wsrep_cluster_size";
  2. +--------------------+-------+
  3. | Variable_name | Value |
  4. +--------------------+-------+
  5. | wsrep_cluster_size | |
  6. +--------------------+-------+
  7. row in set (0.003 sec)

查看集群状态

  1. MariaDB [(none)]> show status like "wsrep%";
  2. +------------------------------+-------------------------------------------------------+
  3. | Variable_name | Value |
  4. +------------------------------+-------------------------------------------------------+
  5. | wsrep_apply_oooe | 0.000000 |
  6. | wsrep_apply_oool | 0.000000 |
  7. | wsrep_apply_window | 0.000000 |
  8. | wsrep_causal_reads | |
  9. | wsrep_cert_deps_distance | 0.000000 |
  10. | wsrep_cert_index_size | |
  11. | wsrep_cert_interval | 0.000000 |
  12. | wsrep_cluster_conf_id | |
  13. | wsrep_cluster_size | |
  14. | wsrep_cluster_state_uuid | 541248ce-56d0-11e9-b41b-3a9775d73ca7 |
  15. | wsrep_cluster_status | Primary #主服务器 |
  16. | wsrep_commit_oooe | 0.000000 |
  17. | wsrep_commit_oool | 0.000000 |
  18. | wsrep_commit_window | 0.000000 |
  19. | wsrep_connected | ON #当前是否连接中 |
  20. | wsrep_desync_count | |
  21. | wsrep_evs_delayed | |
  22. | wsrep_evs_evict_list | |
  23. | wsrep_evs_repl_latency | //// |
  24. | wsrep_evs_state | OPERATIONAL |
  25. | wsrep_flow_control_paused | 0.000000 |
  26. | wsrep_flow_control_paused_ns | |
  27. | wsrep_flow_control_recv | |
  28. | wsrep_flow_control_sent | |
  29. | wsrep_gcomm_uuid | 540ee869-56d0-11e9-955e-9b7f30e437a6 |
  30. | wsrep_incoming_addresses | 192.168.64.5:,192.168.64.4:,192.168.64.7: | #连接中的数据库
  31. | wsrep_last_committed | |
  32. | wsrep_local_bf_aborts | |
  33. | wsrep_local_cached_downto | |
  34. | wsrep_local_cert_failures | |
  35. | wsrep_local_commits | |
  36. | wsrep_local_index | |
  37. | wsrep_local_recv_queue | |
  38. | wsrep_local_recv_queue_avg | 0.100000 |
  39. | wsrep_local_recv_queue_max | |
  40. | wsrep_local_recv_queue_min | |
  41. | wsrep_local_replays | |
  42. | wsrep_local_send_queue | |
  43. | wsrep_local_send_queue_avg | 0.000000 |
  44. | wsrep_local_send_queue_max | |
  45. | wsrep_local_send_queue_min | |
  46. | wsrep_local_state | |
  47. | wsrep_local_state_comment | Synced |
  48. | wsrep_local_state_uuid | 541248ce-56d0-11e9-b41b-3a9775d73ca7 |
  49. | wsrep_protocol_version | |
  50. | wsrep_provider_name | Galera |
  51. | wsrep_provider_vendor | Codership Oy <info@codership.com> |
  52. | wsrep_provider_version | 25.3.(r3789) |
  53. | wsrep_ready | ON |
  54. | wsrep_received | |
  55. | wsrep_received_bytes | |
  56. | wsrep_repl_data_bytes | |
  57. | wsrep_repl_keys | |
  58. | wsrep_repl_keys_bytes | |
  59. | wsrep_repl_other_bytes | |
  60. | wsrep_replicated | |
  61. | wsrep_replicated_bytes | |
  62. | wsrep_thread_count | |
  63. +------------------------------+-------------------------------------------------------+
  64. rows in set (0.002 sec)

查看连接的主机

  1. MariaDB [(none)]> show status like "wsrep_incoming_addresses";
  2. +--------------------------+-------------------------------------------------------+
  3. | Variable_name | Value |
  4. +--------------------------+-------------------------------------------------------+
  5. | wsrep_incoming_addresses | 192.168.64.5:,192.168.64.4:,192.168.64.7: |
  6. +--------------------------+-------------------------------------------------------+
  7. row in set (0.001 sec)

测试集群是否同步

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

我在192.168.64.4创建ken数据库

  1. [root@ken-node1 ~]# mysql -uroot -p
  2. Enter password:
  3. Welcome to the MariaDB monitor. Commands end with ; or \g.
  4. Your MariaDB connection id is
  5. Server version: 10.3.-MariaDB MariaDB Server
  6.  
  7. Copyright (c) , , Oracle, MariaDB Corporation Ab and others.
  8.  
  9. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  10.  
  11. MariaDB [(none)]> create database ken;
  12. Query OK, row affected (0.041 sec)
  13.  
  14. MariaDB [(none)]> show databases;
  15. +--------------------+
  16. | Database |
  17. +--------------------+
  18. | information_schema |
  19. | ken |
  20. | ken1 |
  21. | mysql |
  22. | performance_schema |
  23. | test |
  24. +--------------------+
  25. rows in set (0.001 sec)

在192.168.64.5节点上查看数据库

  1. [root@ken-node2 ~]# mysql -uroot -p
  2. Enter password:
  3. Welcome to the MariaDB monitor. Commands end with ; or \g.
  4. Your MariaDB connection id is
  5. Server version: 10.3.-MariaDB MariaDB Server
  6.  
  7. Copyright (c) , , Oracle, MariaDB Corporation Ab and others.
  8.  
  9. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  10.  
  11. MariaDB [(none)]> show databases;
  12. +--------------------+
  13. | Database |
  14. +--------------------+
  15. | information_schema |
  16. | ken | #ken数据库已经同步过来
  17. | mysql |
  18. | performance_schema |
  19. | test |
  20. +--------------------+
  21. rows in set (0.002 sec)

192.168.64.7节点上查看数据库

  1. [root@ken-node3 ~]# mysql -uroot -p
  2. Enter password:
  3. Welcome to the MariaDB monitor. Commands end with ; or \g.
  4. Your MariaDB connection id is
  5. Server version: 10.3.-MariaDB MariaDB Server
  6.  
  7. Copyright (c) , , Oracle, MariaDB Corporation Ab and others.
  8.  
  9. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  10.  
  11. MariaDB [(none)]> show databases;
  12. +--------------------+
  13. | Database |
  14. +--------------------+
  15. | information_schema |
  16. | ken | #ken数据库已经同步 |
  17. | mysql |
  18. | performance_schema |
  19. | test |
  20. +--------------------+
  21. 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_1101_[POI2007]Zap_莫比乌斯反演

    题意:FGD正在破解一段密码,他需要回答很多类似的问题:对于给定的整数a,b和d,有多少正整数对x,y,满足x<=a ,y<=b,并且gcd(x,y)=d.作为FGD的同学,FGD希望得到 ...

  2. vim永久显示行号

    先复制一份vim配置模板到个人目录下,如果目录不对的,自己找到这个文件 cp /usr/share/vim/vim74/vimrc_example.vim ~/.vimrc 注:redhat的路径为  ...

  3. CSRF Token介绍与应对策略

    原文地址:点击打开链接 最近模拟登陆,发现CsrfToken是个很麻烦的问题,所以看了一下CsrfToken的一些介绍.发现这篇文章写得很不错,所以转载过来. CSRF 背景与介绍 CSRF(Cros ...

  4. Hadoop权限管理

    1.Hadoop权限管理包括以下几个模块: (1) 用户分组管理.用于按组为单位组织管理,某个用户只能向固定分组中提交作业,只能使用固定分组中配置的资源:同时可以限制每个用户提交的作业数,使用的资源量 ...

  5. kubernetes进阶之四:Label和Label Selector

    一:什么是Label Label是Kubernetes系列中另外一个核心概念.是一组绑定到K8s资源对象上的key/value对.同一个对象的labels属性的key必须唯一.label可以附加到各种 ...

  6. 安卓开发笔记(二十六):Splash实现首页快速开屏功能

    我们在进行安卓开发的时候,首页开有两种方式,一种是利用handler将一个活动进行延时,时间到达之后软件则会跳转到第二个活动当中.而另一种方法则是更加常用的方法,利用splash实现首页的快速开屏,这 ...

  7. 手写事件代理函数 (Delegated function)

    ‘手写 ’ 这个词 ,面试是不是听过无数遍呢 ! 今天我们来手写一个这样的事件委托函数 => function( parent, selector, type ,  handle)  {} 你需 ...

  8. 《k8s-1.13版本源码分析》-测试环境搭建(k8s-1.13版本单节点环境搭建)

    本文原始地址(gitbook格式):https://farmer-hutao.github.io/k8s-source-code-analysis/prepare/debug-environment. ...

  9. .net相关知识

    1.简述 private. protected. public. internal 修饰符的访问权限. private :   私有成员, 在类的内部才可以访问. protected : 保护成员,该 ...

  10. 史上最详尽的NLP预处理模型汇总

    文章发布于公号[数智物语] (ID:decision_engine),关注公号不错过每一篇干货. 转自 | 磐创AI(公众号ID:xunixs) 作者 | AI小昕 编者按:近年来,自然语言处理(NL ...