5.7.17 GR(group replication)

此搭建试验为5.7GR刚出三天左右搭建的,可能现在又有变化,最近京东出了个搭建文档可以瞅一下

多台服务器相比单台服务器搭建  group replication 需要注意几个点:

1、各个服务器之间需要添加解析:

127.0.0.1 VM-172-31-102-3 localhost localhost.localdomain localhost4 localhost4.localdomain4

172.31.102.243 VM-172-31-102-243

172.31.102.3 VM-172-31-102-3

172.31.102.86 VM-172-31-102-86

2、需要添加白名单参数:

loose-group_replication_ip_whitelist=‘172.31.102.243/24,172.31.102.3/24,172.31.102.86/24,127.0.0.1/8‘

3、 两种模式

mysql5.7.17 Group Replication提供了single-primary和multi-primary两种模式。single-primary mode 组内只有一个节点负责写入,

读可以从任意一个节点读取,组内数据保持强一致;而multi-primary mode 为多写,即写会下发到组内所有节点,组内所有节点同时可读,

也是能够保证组内数据强一致性。一个group的所有节点必须配置使用同一种模式,不可混用。

Single-Primary Mode

这个模式下,group内只有一台节点可写可读,其他节点只可以读。对于group的部署,

需要先跑起primary节点(即那个可写可读的节点),然后再跑起其他的节点,并把这些节点一一加进group。

其他的节点就会自动同步primary节点上面的变化,然后将自己设置为只读模式。

当primary节点意外宕机或者下线,在满足大多数机器存活的情况下,group内部发起选举,选出下一个可用的读节点,提升为primary节点

multi-primary模式:

1、该模式启用需设置两个参数

group_replication_single_primary_mode=0  #这个参数很好理解,就是关闭单master模式

group_replication_enforce_update_everywhere_checks=1 #这个参数设置检查对RP又影响的参数在各个节点是否一致

2、默认启动的都是单master模式,其他节点都设置了read_only、super_read_only这两个参数,需要修改这两个配置

3、完成上面的配置后就可以执行多点写入了,多点写入会存在冲突检查,这耗损性能挺大的,官方建议采用网络分区功能,

在程序端把相同的业务定位到同一节点,尽量减少冲突发生几率

--------------------------------------------------搭建:

一、初始化数据库:

-----5.7安装配置

yum install gcc gcc-c++ -y

yum install -y ncurses-devel.x86_64

yum install -y cmake.x86_64

yum install -y libaio.x86_64

yum install -y bison.x86_64

yum install -y gcc-c++.x86_64

yum install –y autoconf automake imake libxml2-devel expat-devel cmake gcc gcc-c++ libaio libaio-devel bzr bison libtool ncurses5-devel ncurses-devle

yum install -y libaio*

安装boost

./bootstrap.sh

./b2 install

vi /etc/my.cnf

以下为搭建GA的最基本参数,其他优化参数可根据具体情况添加:

##############################################################################

[mysqld]

basedir = /usr/local/mysql

datadir = /data/mysql

user=mysql

explicit_defaults_for_timestamp

port = 3306

server_id = 2

socket = /tmp/mysql.sock

pid-file = /tmp/mysql.pid

# log settings #

log-error = /data/log/3306.err

#binlog binlog

log-bin=mysql-bin

binlog-format = ROW

gtid-mode = ON

enforce-gtid-consistency = ON

log-slave-updates = ON

master-info-repository = TABLE

relay-log-info-repository = TABLE

binlog-checksum = NONE

#group replication

transaction_write_set_extraction=XXHASH64

loose-group_replication_start_on_boot=off

loose-group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"

loose-group_replication_local_address= ‘172.31.102.243:6606‘

loose-group_replication_group_seeds= ‘172.31.102.243:6606,172.31.102.3:6606,172.31.102.86:6606‘

loose-group_replication_ip_whitelist=‘172.31.102.243/24,172.31.102.3/24,172.31.102.86/24,127.0.0.1/8‘

loose-group_replication_bootstrap_group= off

#loose-group-group_replication_single_primary_mode=0

#loose-group-group_replication_enforce_update_everywhere_checks=1

##############################################################################

---注册服务

useradd mysql

cp ./support-files/mysql.server /etc/init.d/mysqld

mkdir -p /data/mysql

mkdir -p /data/log

mkdir -p /data/binlog

mkdir -p /data/undolog

chmod 755 /etc/init.d/mysqld

chown -R mysql:mysql /opt/mysql

chown -R mysql:mysql /data

ln -s /opt/mysql/bin/* /usr/bin/

--不生成随机密码

./mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql

三、启动数据库

service mysqld start

四、配置第一个节点

SET SQL_LOG_BIN=0;

alter user ‘root‘@‘localhost‘ identified by ‘root‘;

CREATE USER [email protected]‘%‘;

GRANT REPLICATION SLAVE ON *.* TO [email protected]‘%‘ IDENTIFIED BY ‘rpl_pass‘;

SET SQL_LOG_BIN=1;

CHANGE MASTER TO MASTER_USER=‘rpl_user‘, MASTER_PASSWORD=‘rpl_pass‘

FOR CHANNEL ‘group_replication_recovery‘;

INSTALL PLUGIN group_replication SONAME ‘group_replication.so‘;

mysql> SHOW PLUGINS;

+----------------------------+----------+--------------------+----------------------+-------------+

| Name                       | Status   | Type               | Library              | License     |

+----------------------------+----------+--------------------+----------------------+-------------+

| binlog                     | ACTIVE   | STORAGE ENGINE     | NULL                 | PROPRIETARY |

(...)

| group_replication          | ACTIVE   | GROUP REPLICATION  | group_replication.so | PROPRIETARY |

+----------------------------+----------+--------------------+----------------------+-------------+

SET GLOBAL group_replication_bootstrap_group=ON;

START GROUP_REPLICATION;

SET GLOBAL group_replication_bootstrap_group=OFF;

mysql> SELECT * FROM performance_schema.replication_group_members;

+---------------------------+--------------------------------------+-------------------+-------------+--------------+

| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST       | MEMBER_PORT | MEMBER_STATE |

+---------------------------+--------------------------------------+-------------------+-------------+--------------+

| group_replication_applier | 0e39bfb1-c367-11e6-a5e4-0200621600c2 | VM-172-31-102-243 |        3306 | ONLINE       |

+---------------------------+--------------------------------------+-------------------+-------------+--------------+

1 row in set (0.00 sec)

mysql> CREATE DATABASE test;

Query OK, 1 row affected (0,00 sec)

mysql> use test

Database changed

mysql> CREATE TABLE t1 (c1 INT PRIMARY KEY, c2 TEXT NOT NULL);

Query OK, 0 rows affected (0,00 sec)

mysql> INSERT INTO t1 VALUES (1, ‘Luis‘);

Query OK, 1 row affected (0,01 sec)

mysql> SELECT * FROM t1;

+----+------+

| c1 | c2   |

+----+------+

|  1 | Luis |

+----+------+

1 row in set (0,00 sec)

mysql> SHOW BINLOG EVENTS;

+---------------+-----+----------------+-----------+-------------+--------------------------------------------------------------------+

| Log_name      | Pos | Event_type     | Server_id | End_log_pos | Info                                                               |

+---------------+-----+----------------+-----------+-------------+--------------------------------------------------------------------+

| binlog.000001 |   4 | Format_desc    |         1 |         123 | Server ver: 5.7.17-gr080-log, Binlog ver: 4                        |

| binlog.000001 | 123 | Previous_gtids |         1 |         150 |                                                                    |

| binlog.000001 | 150 | Gtid           |         1 |         211 | SET @@SESSION.GTID_NEXT= ‘aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:1‘  |

| binlog.000001 | 211 | Query          |         1 |         270 | BEGIN                                                              |

| binlog.000001 | 270 | View_change    |         1 |         369 | view_id=14724817264259180:1                                        |

| binlog.000001 | 369 | Query          |         1 |         434 | COMMIT                                                             |

| binlog.000001 | 434 | Gtid           |         1 |         495 | SET @@SESSION.GTID_NEXT= ‘aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:2‘  |

| binlog.000001 | 495 | Query          |         1 |         585 | CREATE DATABASE test                                               |

| binlog.000001 | 585 | Gtid           |         1 |         646 | SET @@SESSION.GTID_NEXT= ‘aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:3‘  |

| binlog.000001 | 646 | Query          |         1 |         770 | use `test`; CREATE TABLE t1 (c1 INT PRIMARY KEY, c2 TEXT NOT NULL) |

| binlog.000001 | 770 | Gtid           |         1 |         831 | SET @@SESSION.GTID_NEXT= ‘aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:4‘  |

| binlog.000001 | 831 | Query          |         1 |         899 | BEGIN                                                              |

| binlog.000001 | 899 | Table_map      |         1 |         942 | table_id: 108 (test.t1)                                            |

| binlog.000001 | 942 | Write_rows     |         1 |         984 | table_id: 108 flags: STMT_END_F                                    |

| binlog.000001 | 984 | Xid            |         1 |        1011 | COMMIT /* xid=38 */                                                |

+---------------+-----+----------------+-----------+-------------+--------------------------------------------------------------------+

15 rows in set (0,00 sec)

五、加入其它节点

--二三节点配置:

##############################################################################

[mysqld]

basedir = /usr/local/mysql

datadir = /data/mysql

user=mysql

explicit_defaults_for_timestamp

port = 3306

server_id = 2

socket = /tmp/mysql.sock

pid-file = /tmp/mysql.pid

# log settings #

log-error = /data/log/3306.err

#binlog binlog

log-bin=mysql-bin

binlog-format = ROW

gtid-mode = ON

enforce-gtid-consistency = ON

log-slave-updates = ON

master-info-repository = TABLE

relay-log-info-repository = TABLE

binlog-checksum = NONE

#relay-log=VM-172-31-102-3-relay-bin

#skip-name-resolve

#group replication

transaction_write_set_extraction=XXHASH64

loose-group_replication_start_on_boot=off

loose-group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"

loose-group_replication_local_address= ‘172.31.102.3:6606‘

loose-group_replication_group_seeds= ‘172.31.102.243:6606,172.31.102.3:6606,172.31.102.86:6606‘

loose-group_replication_ip_whitelist=‘172.31.102.243/24,172.31.102.3/24,172.31.102.86/24,127.0.0.1/8‘

loose-group_replication_bootstrap_group= off

#loose-group-group_replication_single_primary_mode=0

#loose-group-group_replication_enforce_update_everywhere_checks=1

##############################################################################

##############################################################################

[mysqld]

basedir = /usr/local/mysql

datadir = /data/mysql

user=mysql

explicit_defaults_for_timestamp

port = 3306

server_id = 3

socket = /tmp/mysql.sock

pid-file = /tmp/mysql.pid

# log settings #

log-error = /data/log/3306.err

log-bin=/data/binlog/mysql-bin

#binlog binlog

log-bin=mysql-bin

binlog-format = ROW

gtid-mode = ON

enforce-gtid-consistency = ON

log-slave-updates = ON

master-info-repository = TABLE

relay-log-info-repository = TABLE

binlog-checksum = NONE

#group replication

transaction_write_set_extraction=XXHASH64

loose-group_replication_start_on_boot=off

loose-group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"

loose-group_replication_local_address= ‘172.31.102.86:6606‘

loose-group_replication_group_seeds= ‘172.31.102.3:6606,172.31.102.243:6606,172.31.102.86:6606‘

loose-group_replication_ip_whitelist=‘172.31.102.243/24,172.31.102.3/24,172.31.102.86/24‘

loose-group_replication_bootstrap_group= off

#loose-group-group_replication_single_primary_mode=0

#loose-group-group_replication_enforce_update_everywhere_checks=1

##############################################################################

--加入节点:(二三节点依次执行)

INSTALL PLUGIN group_replication SONAME ‘group_replication.so‘;

SET SQL_LOG_BIN=0;

alter user ‘root‘@‘localhost‘ identified by ‘root‘;

CREATE USER [email protected]‘%‘;

GRANT REPLICATION SLAVE ON *.* TO [email protected]‘%‘ IDENTIFIED BY ‘rpl_pass‘;

FLUSH PRIVILEGES;

SET SQL_LOG_BIN=1;

CHANGE MASTER TO MASTER_USER=‘rpl_user‘, MASTER_PASSWORD=‘rpl_pass‘ FOR CHANNEL ‘group_replication_recovery‘;

START GROUP_REPLICATION;

--下列抱错可能会因初始化参数执行顺序问题出现:

[ERROR] Plugin group_replication reported: ‘This member has more executed transactions than those present in the group.

Local transactions:

--执行跳过该事物:

SET GLOBAL group_replication_allow_local_disjoint_gtids_join=ON;

搭建完毕:

mysql> SELECT * FROM performance_schema.replication_group_members;

+---------------------------+--------------------------------------+-------------------+-------------+--------------+

| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST       | MEMBER_PORT | MEMBER_STATE |

+---------------------------+--------------------------------------+-------------------+-------------+--------------+

| group_replication_applier | 69717cb5-c59d-11e6-b788-020027b4009a | VM-172-31-102-86  |        3306 | ONLINE       |

| group_replication_applier | b55a9513-c734-11e6-821a-02007de500c1 | VM-172-31-102-3   |        3306 | ONLINE       |

| group_replication_applier | c0d38ada-c730-11e6-8cdc-0200621600c2 | VM-172-31-102-243 |        3306 | ONLINE       |

+---------------------------+--------------------------------------+-------------------+-------------+--------------+

3 rows in set (0.00 sec)

时间: 2024-10-19 21:56:01

5.7.17 GR(group replication)的相关文章

实践 Mysql Group Replication 组复制

实践过程: 在一台服务器上安装3个MySQL(s1,s2,s3) 配置s1,启动 Group Replication 配置s2,添加到组中 配置s3,添加到组中 测试 内容比较长,可能不方便实际操作,我也做了一个PDF版本,您可以下载查看,发送消息 'gr' 会自动回复下载地址 详细配置过程 (1)下载 mysql-5.7.17 https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

MySQL Group Replication调研剖析

一.MySQL复制的三种模式 MySQL当前存在的三种复制模式有:异步模式.半同步模式和组复制模式,先了解一下三种模式的工作方式. 1.MySQL Asynchronous Replication(异步复制) 异步复制是MySQL最早的也是当前使用最多的复制模式,异步复制提供了一种简单的主-从复制方法,包含一个主库(master)和备库(一个,或者多个)之间,主库执行并提交了事务,在这之后(因此才称之为异步),这些事务才在从库上重新执行一遍(基于statement)或者变更数据内容(基于row)

Percona XtraDB Cluster vs Galera Cluster vs MySQL Group Replication

Overview Galera Cluster Percona XtraDB Cluster MySQL Group Replication MySQL InnoDB Cluster Similarities Similar - Use Cases Similar Limitation Differences GR & Galera Group Communication System 组通信系统 Binlogs & Gcache Node Provisioning 节点配置 GTID v

MySQL group replication介绍

"MySQL group replication" group replication是MySQL官方开发的一个开源插件,是实现MySQL高可用集群的一个工具.第一个GA版本正式发布于MySQL5.7.17中:想要使用group replication只需要从官网上下载MySQL5.7.17及以后的版本即可 group replication发布以后,有3种方法来实现MySQL的高可用集群: ①:异步复制 ②:半同步复制 ③:group replication ---注意: 异步复制是

Mysql Group Replication 简介及单主模式组复制配置【转】

一 Mysql Group Replication简介 Mysql Group Replication(MGR)是一个全新的高可用和高扩张的MySQL集群服务. 高一致性,基于原生复制及paxos协议的组复制技术,以插件方式提供一致数据安全保证: 高容错性,大多数服务正常就可继续工作,自动不同节点检测资源征用冲突,按顺序优先处理,内置自动防脑裂机制: 高扩展性,自动添加移除节点,并更新组信息: 高灵活性,单主模式和多主模式.单主模式自动选主,所有更新操作在主进行:多主模式,所有server同时更

MySQL Group Replication的安装部署

一.简介 这次给大家介绍下MySQL官方最新版本5.7.17中GA的新功能 Group Replication . Group Replication是一种可用于实现容错系统的技术.复制组是一组通过消息传递相互交互的服务器.通信层提供一组保证,例如原子消息和总订单消息传递.这些是非常强大的属性,可以转化为非常有用的抽象,人们可以诉诸构建更高级的数据库复制解决方案.MySQL组复制构建在这些属性和抽象之上,并实现多主复制协议的更新.实质上,复制组由多个服务器形成,并且组中的每个服务器可以独立地执行

MySQL Group Replication

group replication是一种全新的高可用,高扩张的MySQL集群服务.高一致性,基于原生复制及paxos协议的组复制技术,以插件方式提供一致数据安全保证:高容错性,大多数服务正常就可继续工作,自动不同节点检测资源征用冲突,按顺序优先处理,内置自动防脑裂机制:高扩展性,自动添加移除节点,并更新组信息:高灵活性,单主模式和多主模式.单主模式自动选主,所有更新操作在主进行:多主模式,所有server同时更新. 0,修改hostsvim /etc/hostslocalhost 127.0.0

Mysql Group Replication 简析

前段时间做了组内分享,写的关于mysql Group Replication 文章   3, 高扩展 原文地址:https://www.cnblogs.com/yhdgm/p/8124719.html

mysql 5.7 Group Replication

MySQL 组复制实现了基于复制协议的多主更新(单主模式). 复制组由多个 server成员构成,并且组中的每个 server 成员可以独立地执行事务.但所有读写(RW)事务只有在冲突检测成功后才会提交.只读(RO)事务不需要在冲突检测,可以立即提交. 对于任何 RW 事务,提交操作并不是由始发 server 单向决定的,而是由组来决定是否提交.准确地说,在始发 server 上,当事务准备好提交时,该 server 会广播写入值(已改变的行)和对应的写入集(已更新的行的唯一标识符).然后会为该