码迷,mamicode.com
首页 > 数据库 > 详细

MySQL Group Replication

时间:2017-07-30 23:43:11      阅读:329      评论:0      收藏:0      [点我收藏+]

标签:更新   check   time   sch   mysql集群   image   port   buffer   size   

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

0,修改hosts
vim /etc/hosts
localhost 127.0.0.1

1,实验环境
M1:127.0.0.1 3307
M2:127.0.0.1 3308

2,安装mysql
/usr/local/mysql57/bin/mysqld --initialize-insecure --user=dba --basedir=/usr/local/mysql57 --datadir=/data1/mysql3307
/usr/local/mysql57/bin/mysqld --initialize-insecure --user=dba --basedir=/usr/local/mysql57 --datadir=/data1/mysql3308

3,配置
M1:
[mysqld]

# GENERAL con#
user = dba
port = 3307
default_storage_engine = InnoDB
socket = /tmp/mysql3307.sock
pid_file = /data1/mysql3307/mysql.pid

# SAFETY #
max_allowed_packet = 64M
max_connect_errors = 1000000

# DATA STORAGE #binlog-format
datadir = /data1/mysql3307/

# BINARY LOGGING #
log_bin = /data1/mysql3307/3307-binlog
expire_logs_days = 10
#sync_binlog = 1
relay-log= /data1/mysql3307/3307-relaylog
#replicate-wild-do-table=hostility_url.%
#replicate-wild-do-table=guards.%

# CACHES AND LIMITS #
tmp_table_size = 32M
max_heap_table_size = 32M
query_cache_type = 1
query_cache_size = 0
max_connections = 5000
#max_user_connections = 200
thread_cache_size = 512
open_files_limit = 65535
table_definition_cache = 4096
table_open_cache = 4096
wait_timeout=7500
interactive_timeout=7500
binlog-format=row
character-set-server=utf8
skip-name-resolve
skip-character-set-client-handshake
back_log=1024

# INNODB #
#innodb_flush_method = O_DIRECT
innodb_data_home_dir = /data1/mysql3307/
#innodb_data_file_path = ibdata1:1G:autoextend
innodb_log_group_home_dir=/data1/mysql3307/
innodb_log_files_in_group = 3
innodb_log_file_size = 1G
innodb_flush_log_at_trx_commit = 2
innodb_file_per_table = 1
innodb_file_format=Barracuda
innodb_support_xa=0


innodb_io_capacity=500
innodb_max_dirty_pages_pct=90
innodb_read_io_threads=16
innodb_write_io_threads=8
innodb_buffer_pool_instances=4
innodb_thread_concurrency=0

#GTID

#gtid_mode = on
#enforce_gtid_consistency = on


# LOGGING #
log_error = /data1/mysql3307/error.log
#log_queries_not_using_indexes = 1
slow_query_log = 1
slow_query_log_file = /data1/mysql3307/mysql-slow.log
long_query_time=0.05
server_id=3307
innodb_buffer_pool_size = 1G
report-host=localhost #此处的localhost一定要存在与hosts文件里,即:localhost 127.0.0.1
report-port=3307
log_slave_updates = on

#group replication
gtid_mode = on
enforce_gtid_consistency = on
master_info_repository = table
relay_log_info_repository = table
binlog_checksum=NONE
log_slave_updates=ON

transaction_write_set_extraction=XXHASH64
loose-group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
loose-group_replication_start_on_boot=off
loose-group_replication_local_address= "localhost:24901"
loose-group_replication_group_seeds= "localhost:24901,localhost:24902"
loose-group_replication_single_primary_mode = true
loose-group_replication_bootstrap_group= off
loose-group_replication_enforce_update_everywhere_checks = false


### mysql_version=mysql57
[mysql]
prompt = \u@\h:\p [\d]>

4,启动mysql
nohup /usr/local/mysql57/bin/mysqld_safe --defaults-file=/data1/mysql3307/my3307.cnf 2>/dev/null &
mysql -uroot -S /tmp/mysql3307.sock -p123456

set sql_log_bin=0;
create user rpl_user@‘%‘;
grant replication slave on *.* to rpl_user@‘%‘ 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‘;

5,启动group replication
install plugin group_replication soname ‘group_replication.so‘;
show plugins;
set global group_replication_bootstrap_group=on;
start group_replication;
set global group_replication_bootstrap_group=off;
select * from performance_schema.replication_group_members;

6,测试(创建一个数据库,新建一个实例加入到group replication中后会自动同步到新实例)
create database test;
use test;
create table t(id int primary key auto_increment,name text);
insert into t values(1,‘Lucas‘);
show binlog evnets;

7,添加一个新实例
M2:

[mysqld]

# GENERAL con#
user = dba
port = 3308
default_storage_engine = InnoDB
socket = /tmp/mysql3308.sock
pid_file = /data1/mysql3308/mysql.pid

# SAFETY #
max_allowed_packet = 64M
max_connect_errors = 1000000

# DATA STORAGE #binlog-format
datadir = /data1/mysql3308/

# BINARY LOGGING #
log_bin = /data1/mysql3308/3308-binlog
expire_logs_days = 10
#sync_binlog = 1
relay-log= /data1/mysql3308/3308relaylog
#replicate-wild-do-table=hostility_url.%
#replicate-wild-do-table=guards.%

# CACHES AND LIMITS #
tmp_table_size = 32M
max_heap_table_size = 32M
query_cache_type = 1
query_cache_size = 0
max_connections = 5000
#max_user_connections = 200
thread_cache_size = 512
open_files_limit = 65535
table_definition_cache = 4096
table_open_cache = 4096
wait_timeout=7500
interactive_timeout=7500
binlog-format=row
character-set-server=utf8
skip-name-resolve
skip-character-set-client-handshake
back_log=1024

# INNODB #
#innodb_flush_method = O_DIRECT
innodb_data_home_dir = /data1/mysql3308/
#innodb_data_file_path = ibdata1:1G:autoextend
innodb_log_group_home_dir=/data1/mysql3308/
innodb_log_files_in_group = 3
innodb_log_file_size = 1G
innodb_flush_log_at_trx_commit = 2
innodb_file_per_table = 1
innodb_file_format=Barracuda
innodb_support_xa=0


innodb_io_capacity=500
innodb_max_dirty_pages_pct=90
innodb_read_io_threads=16
innodb_write_io_threads=8
innodb_buffer_pool_instances=4
innodb_thread_concurrency=0

#GTID

#gtid_mode = on
#enforce_gtid_consistency = on


# LOGGING #
log_error = /data1/mysql3308/error.log
#log_queries_not_using_indexes = 1
slow_query_log = 1
slow_query_log_file = /data1/mysql3308/mysql-slow.log
long_query_time=0.05
server_id=3307
innodb_buffer_pool_size = 1G
report-host=localhost #此处的localhost一定要存在与hosts文件里,即:localhost 127.0.0.1
report-port=3307
log_slave_updates = on

#group replication
gtid_mode = on
enforce_gtid_consistency = on
master_info_repository = table
relay_log_info_repository = table
binlog_checksum=NONE
log_slave_updates=ON

transaction_write_set_extraction=XXHASH64
loose-group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
loose-group_replication_start_on_boot=off
loose-group_replication_local_address= "localhost:24901"
loose-group_replication_group_seeds= "localhost:24901,localhost:24902"
loose-group_replication_single_primary_mode = true
loose-group_replication_bootstrap_group= off
loose-group_replication_enforce_update_everywhere_checks = false


### mysql_version=mysql57
[mysql]
prompt = \u@\h:\p [\d]>

8,启动实例 & 配置group replication
nohup /usr/local/mysql57/bin/mysqld_safe --defaults-file=/data1/mysql3308/my3308.cnf 2>/dev/null &
mysql -uroot -S /tmp/mysql3308.sock -p123456

set sql_log_bin=0;
create user rpl_user@‘%‘;
grant replication slave on *.* to rpl_user@‘%‘ 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‘;

9,启动group replication
install plugin group_replication soname ‘group_replication.so‘;
show plugins;
start group_replication;
select * from performance_schema.replication_group_members;

技术分享

 

10,测试同步是否正常
/usr/local/mysql57/bin/mysql -uroot -p123456 -S /tmp/mysql3308.sock

show databases;

技术分享

技术分享

 

 


注意:之前在新加实例的过程中新实例一直报recovering,主要是mysql的配置中report-host未配置,或者是report-host配置的值不在系统hosts里面

 

MySQL Group Replication

标签:更新   check   time   sch   mysql集群   image   port   buffer   size   

原文地址:http://www.cnblogs.com/jandison/p/7260618.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!