5.7.17 GR(group replication)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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)


本文出自 “12729686” 博客,请务必保留此出处http://12739686.blog.51cto.com/12729686/1908484

以上是关于5.7.17 GR(group replication)的主要内容,如果未能解决你的问题,请参考以下文章

MySQL 5.7.20 Group Relication(组复制)搭建手册

MySQL Group Replication(组复制MGR)

SyntaxException: <ErrorMessage code=2000 [CQL 查询中的语法错误] message="Unknown property 'replicati

MySQL Group Replication的安装部署

mysql-group-replication 测试环境的搭建与排错

High Aavialability with Group Replication-by宋利兵