------------------------------TigerLiu的技术园地([email protected])--------------------------------
参考文档:
搭建步骤:https://www.cnblogs.com/manger/p/7211932.html
参数配置:http://shift-alt-ctrl.iteye.com/blog/2269539
官方文档:https://dev.mysql.com/doc/refman/5.7/en/group-replication.html
环境:redhat linux6.5 MySQL5.7.19 Xtrabackup2.4.8
搭建3节点组复制集群具体如下:(笔者在实验环境中搭建,两台虚拟机其中115起了两个实例,生产环境建议实例分布在不同的机器上)
IP 端口号 主机名
192.168.56.117 3306 SlaveSed
192.168.56.115 3306 SlaveFri
192.168.56.115 3307 SlaveFri
搭建思路:
1、配置参数文件,将组复制参数配好
2、安装组复制插件
3、配置组复制
a、117-3306原库配置
b、使用xtrabackup初始化115-3306及115-3307节点
c、115-3306及115-3307配置
4、组复制同步测试
5、组复制数据全局一致性测试
6、组复制宕机及恢复测试
7、错误总结
========================================正文分割线================================================
1、配置参数文件:
关键参数:
server-id = 1 每个主机不要一样
relay_log_info_repository=TABLE
master_info_repository=table
binlog_checksum=NONE
log_slave_updates=ON
binlog_format=ROW
gtid_mode=ON
transaction_write_set_extraction=XXHASH64
slave_parallel_type=LOGICAL_CLOCK
slave_preserve_commit_order=1
loose-group_replication_group_name = 'ce9be252-2b71-11e6-b8f4-00212889f851' #组的名字可以随便起,所有节点必须一致,但不能用主机的GTID
loose-group_replication_start_on_boot = off #为了避免每次启动自动引导具有相同名称的第二个组,所以设置为OFF。
loose-group_replication_bootstrap_group = off #同上
loose-group_replication_local_address = '192.168.56.117:33061' #写自己主机所在IP
loose-group_replication_group_seeds ='192.168.56.117:33061,192.168.56.115:33061,192.168.56.115:33071'
loose-group_replication_single_primary_mode = off #关闭单主模式的参数
loose-group_replication_enforce_update_everywhere_checks = on #开启多主模式的参数
117-3306实例:
[mysqld3306]
#auto-rehash
#default-character-set=utf8
socket=/tmp/mysql.sock
server-id=1
gtid_mode=on
enforce_gtid_consistency=on
log-slave-updates=1
binlog_format=row
replicate-ignore-db=information_schema
replicate-ignore-db=mysql
replicate-ignore-db=performance_schema
replicate-ignore-db=sys
replicate-ignore-db=dmm_170401
replicate-ignore-db=sqlauditbo
skip_slave_start=1
sync_master_info = 1
sync_relay_log = 1
sync_relay_log_info = 1
relay_log_recovery = 1
log-bin=/binlog/mysql-bin
sync_binlog=1
innodb_support_xa=1
port=3306
basedir=/usr/local/mysql
datadir=/home/mysql/data/
log-error=/usr/local/mysql/mysqld.log
pid-file=/home/mysql/data/mysqld.pid
default-time-zone = '+8:00'
group_concat_max_len=102400
max_allowed_packet = 4M
max_connections=1000
character-set-server=utf8
lower_case_table_names=1
event_scheduler = 1
sql-mode=''
query_cache_size=0
max_heap_table_size=96M
tmp_table_size=96M
long_query_time=1
################semi sync replication settings 56#################
plugin_dir = /usr/local/mysql/lib/plugin
plugin_load ="rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so"
rpl_semi_sync_master_enabled=1
rpl_semi_sync_slave_enabled=1
rpl_semi_sync_master_timeout=5000
relay_log_info_repository=TABLE
master_info_repository=table
#innodb
default-storage-engine =innodb
innodb_io_capacity=1000
innodb_open_files = 500
innodb_doublewrite=0
innodb_file_format=Barracuda
innodb_flush_log_at_trx_commit=1
innodb_file_per_table=1
innodb_log_buffer_size=8M
innodb_log_file_size=128M
innodb_buffer_pool_size=256M
innodb_write_io_threads = 2
innodb_read_io_threads = 2
innodb_thread_concurrency= 0
innodb_purge_threads = 0
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
#myisam
bulk_insert_buffer_size = 512M
myisam_sort_buffer_size = 512M
myisam_max_sort_file_size = 1G
myisam_repair_threads = 1
#slow query log
slow_query_log=ON
slow_query_log_file=/home/mysql/data/SlaveSed-slow.log
long_query_time=10
log_queries_not_using_indexes=0
########group replication##############
relay_log_info_repository=TABLE
master_info_repository=table
binlog_checksum=NONE
log_slave_updates=ON
binlog_format=ROW
gtid_mode=ON
transaction_write_set_extraction=XXHASH64
slave_parallel_type=LOGICAL_CLOCK
slave_preserve_commit_order=1
loose-group_replication_group_name = 'ce9be252-2b71-11e6-b8f4-00212889f851'
loose-group_replication_start_on_boot = off
loose-group_replication_bootstrap_group = off
loose-group_replication_local_address = '192.168.56.117:33061'
loose-group_replication_group_seeds ='192.168.56.117:33061,192.168.56.115:33061,192.168.56.115:33071'
loose-group_replication_single_primary_mode = off
loose-group_replication_enforce_update_everywhere_checks = on
115-3306实例:
[mysqld3306]
port = 3306
socket = /home/mysql/data/mysql.sock
# GENERAL #
user = mysql
default-storage-engine = InnoDB
pid-file=/home/mysql/data/mysqld.pid
server-id = 2
tmpdir = /mysqltmp/
log-error=/usr/local/mysql/mysqld.log
character_set_server = utf8
default-time-zone = '+8:00'
max_allowed_packet = 4M
event_scheduler = 1
# MyISAM #
key-buffer-size = 32M
bulk_insert_buffer_size = 512M
myisam_sort_buffer_size = 512M
myisam_max_sort_file_size = 1G
myisam_repair_threads = 1
# SAFETY #
max-allowed-packet = 16M
max-connect-errors = 1000000
sql-mode =
sysdate-is-now = 1
innodb = FORCE
# DATA STORAGE #
datadir = /home/mysql/data/
#datadir = /home/mysql/dataUp/
# BINARY LOGGING #
log-bin = /binlog/mysql-bin
expire-logs-days = 30
sync-binlog = 1
lower_case_table_names = 1
binlog_format = row
max_binlog_size = 1073741824
# CACHES AND LIMITS #
tmp-table-size = 32M
max-heap-table-size = 32M
query-cache-type = 0
query-cache-size = 0
max-connections = 2000
thread-cache-size = 128
open-files-limit = 65535
table-definition-cache = 4096
table-open-cache = 4096
# INNODB #
query_cache_size = 0
max_heap_table_size = 96M
tmp_table_size = 96M
long_query_time = 1
innodb-flush-method = O_DIRECT
innodb-log-files-in-group = 2
innodb-log-file-size = 128M
innodb-flush-log-at-trx-commit = 1
innodb-file-per-table = 1
innodb-buffer-pool-size = 1G
innodb_write_io_threads = 8
innodb_read_io_threads = 8
innodb_purge_threads = 4
innodb_buffer_pool_instances = 3
innodb_stats_on_metadata = OFF
join_buffer_size = 262144
sort_buffer_size = 262144
innodb_support_xa = 1
default-storage-engine =innodb
innodb_io_capacity=1000
innodb_open_files = 500
innodb_doublewrite=0
innodb_file_format=Barracuda
innodb_thread_concurrency= 0
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
# LOGGING #
log-error = /home/mysql/data/mysql-error.log
log-queries-not-using-indexes = 1
slow-query-log = 1
slow-query-log-file = /home/mysql/data/mysql-slow.log
# REPLICATION #
slave_compressed_protocol = on
sync_relay_log_info = 10000
log-slave-updates = 1
relay-log = /home/mysql/data/relay-bin
relay_log_recovery = 1
binlog_gtid_simple_recovery = 1
slave-net-timeout = 60
sync_master_info = 1
sync-relay-log = 1
sync-relay-log-info = 1
master_info_repository = TABLE
relay_log_info_repository = TABLE
slave_skip_errors = ddl_exist_errors
binlog_checksum=NONE
replicate-ignore-db=information_schema
replicate-ignore-db=mysql
replicate-ignore-db=performance_schema
replicate-ignore-db=sys
replicate-ignore-db=dmm_170401
replicate-ignore-db=sqlauditbo
# semi sync replication settings #
plugin_dir = /usr/local/mysql/lib/plugin
plugin_load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so"
rpl_semi_sync_master_enabled = 1
rpl_semi_sync_slave_enabled = 1
rpl_semi_sync_master_timeout = 5000
# GTID #
gtid_mode = on
enforce_gtid_consistency = on
# SLOW LOG #
slow_query_log=ON
#slow_query_log_file=/home/mysql/data/SlaveSed-slow.log
long_query_time=5
########group replication##############
relay_log_info_repository=TABLE
master_info_repository=table
binlog_checksum=NONE
log_slave_updates=ON
binlog_format=ROW
gtid_mode=ON
transaction_write_set_extraction=XXHASH64
slave_parallel_type=LOGICAL_CLOCK
slave_preserve_commit_order=1
loose-group_replication_group_name = 'ce9be252-2b71-11e6-b8f4-00212889f851'
loose-group_replication_start_on_boot = off
loose-group_replication_bootstrap_group = off
loose-group_replication_local_address = '192.168.56.115:33061'
loose-group_replication_group_seeds ='192.168.56.117:33061,192.168.56.115:33061,192.168.56.115:33071'
loose-group_replication_single_primary_mode = off
loose-group_replication_enforce_update_everywhere_checks = on
group_replication_ssl_mode=REQUIRED
####################### SLAVE PARAMETER #####################
#read_only=1
#super_read_only=1
####################### mysql 57 #####################
slave_parallel_type=LOGICAL_CLOCK
slave_parallel_workers=4
rpl_semi_sync_master_wait_point = after_sync
rpl_semi_sync_master_wait_for_slave_count = 1
115-3307实例:
[mysqld3307]
port = 3307
socket = /home/mysql/dataUp/mysql.sock
# GENERAL #
user = mysql
default-storage-engine = InnoDB
pid-file = /home/mysql/dataUp/mysqld.pid
server-id = 3
tmpdir = /mysqltmp/
log-error=/usr/local/mysql/mysqld.log
character_set_server = utf8
default-time-zone = '+8:00'
max_allowed_packet = 4M
event_scheduler = 1
# MyISAM #
key-buffer-size = 32M
bulk_insert_buffer_size = 512M
myisam_sort_buffer_size = 512M
myisam_max_sort_file_size = 1G
myisam_repair_threads = 1
# SAFETY #
max-allowed-packet = 16M
max-connect-errors = 1000000
sql-mode =
sysdate-is-now = 1
innodb = FORCE
# DATA STORAGE #
datadir = /home/mysql/dataUp/
# BINARY LOGGING #
log-bin = /binlog/3307/mysql-bin
expire-logs-days = 30
sync-binlog = 1
lower_case_table_names = 1
binlog_format = row
max_binlog_size = 1073741824
# CACHES AND LIMITS #
tmp-table-size = 32M
max-heap-table-size = 32M
query-cache-type = 0
query-cache-size = 0
max-connections = 2000
thread-cache-size = 128
open-files-limit = 65535
table-definition-cache = 4096
table-open-cache = 4096
# INNODB #
query_cache_size = 0
max_heap_table_size = 96M
tmp_table_size = 96M
long_query_time = 1
innodb-flush-method = O_DIRECT
innodb-log-files-in-group = 2
innodb-log-file-size = 128M
innodb-flush-log-at-trx-commit = 1
innodb-file-per-table = 1
innodb-buffer-pool-size = 1G
innodb_write_io_threads = 8
innodb_read_io_threads = 8
innodb_purge_threads = 4
innodb_buffer_pool_instances = 3
innodb_stats_on_metadata = OFF
join_buffer_size = 262144
sort_buffer_size = 262144
innodb_support_xa = 1
default-storage-engine =innodb
innodb_io_capacity=1000
innodb_open_files = 500
innodb_doublewrite=0
innodb_file_format=Barracuda
innodb_thread_concurrency= 0
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
# LOGGING #
log-error = /home/mysql/dataUp/mysql-error.log
log-queries-not-using-indexes = 1
slow-query-log = 1
slow-query-log-file = /home/mysql/dataUp/mysql-slow.log
# REPLICATION #
slave_compressed_protocol = on
sync_relay_log_info = 10000
log-slave-updates = 1
relay-log = /home/mysql/dataUp/relay-bin
relay_log_recovery = 1
binlog_gtid_simple_recovery = 1
slave-net-timeout = 60
sync_master_info = 1
sync-relay-log = 1
sync-relay-log-info = 1
master_info_repository = TABLE
relay_log_info_repository = TABLE
slave_skip_errors = ddl_exist_errors
binlog_checksum=NONE
replicate-ignore-db=information_schema
replicate-ignore-db=mysql
replicate-ignore-db=performance_schema
replicate-ignore-db=sys
replicate-ignore-db=dmm_170401
replicate-ignore-db=sqlauditbo
# semi sync replication settings #
plugin_dir = /usr/local/mysql/lib/plugin
plugin_load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so"
rpl_semi_sync_master_enabled = 1
rpl_semi_sync_slave_enabled = 1
rpl_semi_sync_master_timeout = 5000
# GTID #
gtid_mode = on
enforce_gtid_consistency = on
# SLOW LOG #
slow_query_log=ON
#slow_query_log_file=/home/mysql/dataUp/SlaveSed-slow.log
long_query_time=5
####################### SLAVE PARAMETER #####################
#read_only=1
#super_read_only=1
####################### mysql 57 #####################
slave_parallel_type=LOGICAL_CLOCK
slave_parallel_workers=4
rpl_semi_sync_master_wait_point = after_sync
rpl_semi_sync_master_wait_for_slave_count = 1
########group replication##############
relay_log_info_repository=TABLE
master_info_repository=table
binlog_checksum=NONE
log_slave_updates=ON
binlog_format=ROW
gtid_mode=ON
transaction_write_set_extraction=XXHASH64
slave_parallel_type=LOGICAL_CLOCK
slave_preserve_commit_order=1
loose-group_replication_group_name = 'ce9be252-2b71-11e6-b8f4-00212889f851'
loose-group_replication_start_on_boot = off
loose-group_replication_bootstrap_group = off
loose-group_replication_local_address = '192.168.56.115:33071'
loose-group_replication_group_seeds ='192.168.56.117:33061,192.168.56.115:33061,192.168.56.115:33071'
loose-group_replication_single_primary_mode = off
loose-group_replication_enforce_update_everywhere_checks = on
group_replication_ssl_mode=REQUIRED
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'SlaveFri' IDENTIFIED BY 'repl';
配置复制使用组复制
START GROUP_REPLICATION;
查看组复制是否成功
关闭引导
set global group_replication_bootstrap_group=off;
c、配置 group_replication_recovery 通道的恢复凭据
192.168.56.115 3306 && 192.168.56.115 3307:
给用户赋权
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'SlaveSed' IDENTIFIED BY 'repl';
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'SlaveFri' IDENTIFIED BY 'repl';
配置复制使用组复制
5、组复制数据全局一致性测试
因为之前搭建过双主复制,但其无法保证数据的全局一致性,故在此对组复制也进行了测试
注意!在事务不自动提交的情况下做测试(set autocommit=0)
测试方式如下
1、117-3306修改t2表数据 ------------------------update t2 set c2='1111111111' where c1=2;
2、115-3306也修改该行数据并进行提交-------update t2 set c2='22222' where c1=2; commit;
3、当117-3306在对该行执行操作的时候,需要重新生成事务
ERROR 1213 (40001): Deadlock found when trying to get lock; try restarting transaction
6、模拟节点宕机验证
宕机前查询+----+-----------+
7、错误总结: