Linux学习-MySQL的高可用性集群Galera Cluste
作者:互联网
一、Galera Cluste简介
1、Galera Cluster
集成了Galera插件的MySQL集群,是一种新型的,数据不共享的,高度冗余的高可用方案,目前Galera Cluster有两个版本,分别是Percona Xtradb Cluster及MariaDB Cluster,Galera本身是具有多主特性的,即采用multi-master的集群架构,是一个既稳健,又在数据一致性、完整性及高性能方面有出色表现的高可用解决方案。通过wsrep(MySQL extended with the Write Set Replication)协议在全局实现复制;任何一节点都可读写,不需要主从复制,实现多主读写。
下图图示:三个节点组成了一个集群,与普通的主从架构不同,它们都可以作为主节点,三个节点是对等的,称为multi-master架构,当有客户端要写 入或者读取数据时,连接哪个实例都是一样的,读到的数据是相同的,写入某一个节点之后,集群自己会将新数据同步到其它节点上面,这种架构不共享任何数据,是一种高冗余架构;
2、Galera Cluster特点
多主架构:真正的多点读写的集群,在任何时候读写数据,都是最新的
同步复制:集群不同节点之间数据同步,没有延迟,在数据库挂掉之后,数据不会丢失
并发复制:从节点APPLY数据时,支持并行执行,更好的性能
故障切换:在出现数据库故障时,因支持多点写入,切换容易
热插拔:在服务期间,如果数据库挂了,只要监控程序发现的够快,不可服务 时间就会非常少。在节点故障期间,节点本身对集群的影响非常小
自动节点克隆:在新增节点,或者停机维护时,增量数据或者基础数据不需要 人工手动备份提供,Galera Cluster会自动拉取在线节点数据,最终集群会变为一致
对应用透明:集群的维护,对应用程序是透明的
3、Galera Cluster工作过程
当客户端发出一个commit的指令,在事务被提交之前,所有对数据库的更改都会被 write-set 收集起来,并且将write-set 纪录的内容发送给其他节点。write-set 将在每个节点进行认证测试,测试结果决定着节点是否应用write-set更改数据。如果认证测试失败,节点将丢弃 write-set;如果认证测试成功,则事务提交。可以自动解决同时写入相同数据的冲突问题,和自动增长id问题。
二、安装部署
1、实验环境
主机:3台,节点1 (192.168.214.17),节点2 (192.168.214.27),节点3 (192.168.214.37);注意至少需要三个节点,且不能安装mariadb-server服务
系统:CentOS7.6
软件包:MariaDB-Galera-server-5.5.63 (yum源安装)
参考仓库:https://mirrors.tuna.tsinghua.edu.cn/mariadb/mariadb-5.5.63/yum/centos7-amd64/ (已失效)
2、开始部署
(1) 在三台主机节点中配置yum,并安装MariaDB-Galera-server软件包
[root@centos7-17 ~]# cat > /etc/yum.repos.d/mysql.repo << EOF [mysql] name=galera cluster baseurl=http://ftp.hosteurope.de/mirror/archive.mariadb.org//mariadb-5.5.63/yum/centos7-amd64/ gpgcheck=0 [root@centos7-27 ~]# yum install -y MariaDB-Galera-server [root@centos7-37 ~]# yum install -y MariaDB-Galera-server
(2) 修改配置文件 /etc/my.cnf.d/server.cnf,三台节点一样配置,找到 [galera],修改以下信息
[galera]
wsrep_provider = /usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address="gcomm://192.168.214.17,192.168.214.27,192.168.8.37"
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
下面配置可选项
wsrep_cluster_name = 'mycluster' 默认my_wsrep_cluster wsrep_node_name = 'node1'
wsrep_node_address = '192.168.8.7’
[root@centos7-17 ~]# vim /etc/my.cnf.d/server.cnf ... [galera] # Mandatory settings wsrep_provider=/usr/lib64/galera/libgalera_smm.so wsrep_cluster_address="gcomm://192.168.214.17,192.168.214.27,192.168.214.37" binlog_format=row default_storage_engine=InnoDB innodb_autoinc_lock_mode=2 bind-address=0.0.0.0 wsrep_cluster_name = 'testcluster' ...
(3) 初始化与启动,首次启动时,需要初始化集群,在其中一个节点上执行命令 /etc/init.d/mysql start --wsrep-new-cluster,其它节点正常启动即可
[root@centos7-17 ~]# /etc/init.d/mysql start --wsrep-new-cluster Starting MariaDB.191209 14:36:49 mysqld_safe Logging to '/var/lib/mysql/centos7.localdomain.err'. 191209 14:36:49 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql ... SUCCESS! #另外两个节点正常启动即可,以下两种启动方式均可 [root@centos7-27 ~]# /etc/init.d/mysql start Starting MariaDB.191209 14:37:12 mysqld_safe Logging to '/var/lib/mysql/centos7-27.err'. 191209 14:37:12 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql ...SST in progress, setting sleep higher....... SUCCESS! [root@centos7-37 ~]# service mysql start Starting MariaDB.191209 14:37:21 mysqld_safe Logging to '/var/lib/mysql/centos7-37.err'. 191209 14:37:21 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql ...SST in progress, setting sleep higher....... SUCCESS!
(4) 启动成功后,测试数据的同步即可
[root@centos7-17 ~]# mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 5 Server version: 5.5.63-MariaDB-wsrep MariaDB Server, wsrep_25.25.r9949137 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)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 5 rows in set (0.00 sec) MariaDB [(none)]> create database db1; #测试建库 #在其它节点上查看是否复制成功 [root@centos7-27 ~]# mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 4 Server version: 5.5.63-MariaDB-wsrep MariaDB Server, wsrep_25.25.r9949137 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)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | db1 | #可以看到此节点已经有了 | mysql | | performance_schema | | test | +--------------------+ 5 rows in set (0.00 sec) [root@centos7-37 ~]# mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 4 Server version: 5.5.63-MariaDB-wsrep MariaDB Server, wsrep_25.25.r9949137 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)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | db1 | #另一节点也有了 | mysql | | performance_schema | | test | +--------------------+ 5 rows in set (0.00 sec)View Code
标签:Galera,Cluste,mysql,节点,centos7,Linux,MariaDB,wsrep 来源: https://www.cnblogs.com/hovin/p/12010967.html