MySQL高可用实战部署方案——Galera Cluster

一、Galera Cluster

Galera Cluster介绍

Galera Cluster:集成了Galera插件的MySQL集群,是一种新型的,数据不共享的,高度冗余的高可用方
目前Galera Cluster有两个版本,分别是Percona Xtradb Cluster及MariaDB Cluster,Galera本身是具有多主特性的,即采用multi-master的集群架构,是一个既稳健,又在数据一致性、完整性及高性能方面有出色表现的高可用解决方案。

Galera Cluster特点

多主架构:真正的多点读写的集群,在任何时候读写数据,都是最新的
同步复制:集群不同节点之间数据同步,没有延迟,在数据库挂掉之后,数据不会丢失
并发复制:从节点APPLY数据时,支持并行执行,更好的性能
故障切换:在出现数据库故障时,因支持多点写入,切换容易
热插拔:在服务期间,如果数据库挂了,只要监控程序发现的够快,不可服务时间就会非常少。在节点故障期间,节点本身对集群的影响非常小
自动节点克隆:在新增节点,或者停机维护时,增量数据或者基础数据不需要人工手动备份提供,Galera Cluster会自动拉取在线节点数据,最终集群会变为一致
对应用透明:集群的维护,对应用程序是透明的

Galera Cluster缺点

由于DDL 需全局验证通过,则集群性能由集群中最差性能节点决定(一般集群节点配置都是一样的)
新节点加入或延后较大的节点重新加入需全量拷贝数据(SST,State Snapshot Transfer),作为donor( 贡献者,如: 同步数据时的提供者)的节点在同步过程中无法提供读写
只支持innodb存储引擎的表

Galera Cluster工作过程

在这里插入图片描述

二、实战部署

1、环境准备

四台主机

pxc01	192.168.47.101
pxc02	192.168.47.102
pxc03	192.168.47.103
pxc04	192.168.47.104

2、安装Percona XtraDB Cluster 5.7

1、配置yum源
#在每台机器上执行安装命令
[root@pxc01 ~]# cat /etc/yum.repos.d/pxc.repo
[percona]
name=percona_repo
baseurl=https://mirrors.tuna.tsinghua.edu.cn/percona/release/$releasever/RPMS/$basearch/
enabled=1
gpgcheck=0
[root@pxc01 ~]#

每台主机配置上述yum源,并执行安装命令

#在每台机器上执行安装命令
[root@pxc01 ~]# yum -y install Percona-XtraDB-Cluster-57

3、Percona XtraDB Cluster配置文件

/etc/my.cnf为主配置文件, 当前版本中, 其余的配置文件都放在/etc/percona-xtradb-cluster.conf.d目录里, 包括mysqld.conf, mysqld_safe.cnf, wsrep.cnf三个文件

#主配置文件
[root@pxc01 ~]# ll /etc/my.cnf
-rw-r--r-- 1 root root 370 May 13 04:31 /etc/my.cnf
[root@pxc01 ~]# ll /etc/percona-xtradb-cluster.conf.d/
mysqld.cnf       mysqld_safe.cnf  wsrep.cnf
# 
[root@pxc01 ~]# ll /etc/percona-xtradb-cluster.conf.d/
total 12
-rw-r--r-- 1 root root  381 Jul 19 09:44 mysqld.cnf
-rw-r--r-- 1 root root  440 May 13 04:31 mysqld_safe.cnf
-rw-r--r-- 1 root root 1126 Jul 19 11:27 wsrep.cnf

4、pxc01节点操作

1、查看my.cnf配置文件
#此文件不做任何修改
[root@pxc01 ~]# cat /etc/my.cnf
#
# The Percona XtraDB Cluster 5.7 configuration file.
#
#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#   Please make any edits and changes to the appropriate sectional files
#   included below.
#
!includedir /etc/my.cnf.d/
!includedir /etc/percona-xtradb-cluster.conf.d/
2、查看mysqld.cnf文件
#此文件可以修改MySQL的数据存放目录 
[root@pxc01 ~]# cat /etc/percona-xtradb-cluster.conf.d/mysqld.cnf
# Template my.cnf for PXC
# Edit to your requirements.
[client]
socket=/var/lib/mysql/mysql.sock

[mysqld]
server-id=1
datadir=/var/lib/mysql  #mysql的存放目录可以修改
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log  #mysql的日志路径可以修改
pid-file=/var/run/mysqld/mysqld.pid
log-bin
log_slave_updates
expire_logs_days=7

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
3、查看mysqld_safe.cnf文件
#此文件不做任何修改
[root@pxc01 ~]# cat /etc/percona-xtradb-cluster.conf.d/mysqld_safe.cnf
#
# The Percona Server 5.7 configuration file.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[mysqld_safe]
pid-file = /var/run/mysqld/mysqld.pid
socket   = /var/lib/mysql/mysql.sock
nice     = 0
4、查看wsrep.cnf配置文件
[root@pxc01 ~]# cat /etc/percona-xtradb-cluster.conf.d/wsrep.cnf
[mysqld]
# Path to Galera library
wsrep_provider=/usr/lib64/galera3/libgalera_smm.so

# Cluster connection URL contains IPs of nodes
#If no IP is found, this implies that a new cluster needs to be created,
#in order to do that you need to bootstrap this node
wsrep_cluster_address=gcomm://192.168.47.101,192.168.47.102,192.168.47.103 #集群所有服务器的ip, 这里演示初期搭建三个服务器

# In order for Galera to work correctly binlog format should be ROW
binlog_format=ROW

# MyISAM storage engine has only experimental support
default_storage_engine=InnoDB

# Slave thread to use
wsrep_slave_threads= 8

wsrep_log_conflicts

# This changes how InnoDB autoincrement locks are managed and is a requirement for Galera
innodb_autoinc_lock_mode=2

# Node IP address
wsrep_node_address=192.168.47.101 #各个节点指定自己的ip
# Cluster name
wsrep_cluster_name=pxc-cluster

#If wsrep_node_name is not specified,  then system hostname will be used
wsrep_node_name=pxc-cluster-node-101 ##各个节点指定自己的节点名称

#pxc_strict_mode allowed values: DISABLED,PERMISSIVE,ENFORCING,MASTER
pxc_strict_mode=ENFORCING

# SST method
wsrep_sst_method=xtrabackup-v2

#Authentication for SST method
wsrep_sst_auth="sstuser:s3cretPass" #取消本行注释, 用于各节点之间信息同步, 生产环境需要修改, 所有节点统一. 此处账号密码需要在数据库启动后, 手动创建

尽管Galera Cluster不再需要通过binlog的形式进行同步, 但还是建议在配置文件中开启二进制日志功能, 原因是后期有新节点需要加入, 老节点通过SST全量传输的方式向新节点传输数据, 很可能会拖垮集群性能, 所以让新节点通过binlog的方式完成同步再加入集群会是一种更好的选择。

5、pxc02节点操作

1、查看my.cnf配置文件
#此文件不做任何修改
[root@pxc01 ~]# cat /etc/my.cnf
#
# The Percona XtraDB Cluster 5.7 configuration file.
#
#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#   Please make any edits and changes to the appropriate sectional files
#   included below.
#
!includedir /etc/my.cnf.d/
!includedir /etc/percona-xtradb-cluster.conf.d/
2、查看mysqld.cnf文件
#此文件可以修改MySQL的数据存放目录 
[root@pxc01 ~]# cat /etc/percona-xtradb-cluster.conf.d/mysqld.cnf
# Template my.cnf for PXC
# Edit to your requirements.
[client]
socket=/var/lib/mysql/mysql.sock

[mysqld]
server-id=1
datadir=/var/lib/mysql  #mysql的存放目录可以修改
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log  #mysql的日志路径可以修改
pid-file=/var/run/mysqld/mysqld.pid
log-bin
log_slave_updates
expire_logs_days=7

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
3、查看mysqld_safe.cnf文件
#此文件不做任何修改
[root@pxc01 ~]# cat /etc/percona-xtradb-cluster.conf.d/mysqld_safe.cnf
#
# The Percona Server 5.7 configuration file.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[mysqld_safe]
pid-file = /var/run/mysqld/mysqld.pid
socket   = /var/lib/mysql/mysql.sock
nice     = 0
4、查看wsrep.cnf配置文件
[root@pxc01 ~]# cat /etc/percona-xtradb-cluster.conf.d/wsrep.cnf
[mysqld]
# Path to Galera library
wsrep_provider=/usr/lib64/galera3/libgalera_smm.so

# Cluster connection URL contains IPs of nodes
#If no IP is found, this implies that a new cluster needs to be created,
#in order to do that you need to bootstrap this node
wsrep_cluster_address=gcomm://192.168.47.101,192.168.47.102,192.168.47.103 #集群所有服务器的ip, 这里演示初期搭建三个服务器

# In order for Galera to work correctly binlog format should be ROW
binlog_format=ROW

# MyISAM storage engine has only experimental support
default_storage_engine=InnoDB

# Slave thread to use
wsrep_slave_threads= 8

wsrep_log_conflicts

# This changes how InnoDB autoincrement locks are managed and is a requirement for Galera
innodb_autoinc_lock_mode=2

# Node IP address
wsrep_node_address=192.168.47.102 #各个节点指定自己的ip
# Cluster name
wsrep_cluster_name=pxc-cluster

#If wsrep_node_name is not specified,  then system hostname will be used
wsrep_node_name=pxc-cluster-node-102 ##各个节点指定自己的节点名称

#pxc_strict_mode allowed values: DISABLED,PERMISSIVE,ENFORCING,MASTER
pxc_strict_mode=ENFORCING

# SST method
wsrep_sst_method=xtrabackup-v2

#Authentication for SST method
wsrep_sst_auth="sstuser:s3cretPass" #取消本行注释, 用于各节点之间信息同步, 生产环境需要修改, 所有节点统一. 此
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值