端口号 | 数据目录 | group_repplicatoon 通信接口 | |
3307 | /data/mysql/mysql_3306{data,logs,tmp} | 23307 | |
3308 | /data/mysql/mysql_3307{data,logs,tmp} | 23308 | |
3309 | /data/mysql/mysql_3308{data,logs,tmp} | 23309 |
环境的准备:
#my.cnf[client]port = 3307socket = /tmp/mysql3307.sock[mysql]prompt="\\\\[email protected]\\\\h:\\\\p [\\\\d]>#pager="less -i -n -S"#tee=/home/mysql/query.logno-auto-rehash[mysqld]#miscuser = mysqlbasedir = /usr/local/mysqldatadir = /data/mysql/mysql_3306/dataport = 3306socket = /tmp/mysql3306.sockevent_scheduler = 0tmpdir=/data/mysql/mysql_3306/tmp#timeoutinteractive_timeout = 300wait_timeout = 300#character setcharacter-set-server = utf8open_files_limit = 65535max_connections = 100max_connect_errors = 100000#explicit_defaults_for_timestamp#logslog-output=fileslow_query_log = 1slow_query_log_file = slow.loglog-error = error.loglog_error_verbosity=3pid-file = mysql.pidlong_query_time = 1#log-slow-admin-statements = 1#log-queries-not-using-indexes = 1log-slow-slave-statements = 1#binlogbinlog_format = rowlog-bin = /data/mysql/mysql_3306/logs/mysql-binbinlog_cache_size = 1Mmax_binlog_size = 200Mmax_binlog_cache_size = 2Gsync_binlog = 0expire_logs_days = 10#group replicationserver_id=1013307gtid_mode=ONenforce_gtid_consistency=ONmaster_info_repository=TABLErelay_log_info_repository=TABLEbinlog_checksum=NONElog_slave_updates=ONbinlog_format=ROWtransaction_write_set_extraction=XXHASH64loose-group_replication_group_name="3db33b36-0e51-409f-a61d-c99756e90155"loose-group_replication_start_on_boot=offloose-group_replication_local_address= "192.168.5.100:23307" ###注意端口号,要区分开,不要和我们默认的3306混淆了loose-group_replication_group_seeds= "192.168.5.100:23307,192.168.5.100:23308,192.168.5.100:23309"loose-group_replication_bootstrap_group= offloose-group_replication_single_primary_mode=offloose-group_replication_enforce_update_everywhere_checks=on#relay logskip_slave_start = 1max_relay_log_size = 500Mrelay_log_purge = 1relay_log_recovery = 1#slave-skip-errors=1032,1053,1062#buffers & cachetable_open_cache = 2048table_definition_cache = 2048table_open_cache = 2048max_heap_table_size = 96Msort_buffer_size = 2Mjoin_buffer_size = 2Mthread_cache_size = 256query_cache_size = 0query_cache_type = 0query_cache_limit = 256Kquery_cache_min_res_unit = 512thread_stack = 192Ktmp_table_size = 96Mkey_buffer_size = 8Mread_buffer_size = 2Mread_rnd_buffer_size = 16Mbulk_insert_buffer_size = 32M#myisammyisam_sort_buffer_size = 128Mmyisam_max_sort_file_size = 10Gmyisam_repair_threads = 1#innodbinnodb_buffer_pool_size = 100Minnodb_buffer_pool_instances = 1innodb_data_file_path = ibdata1:100M:autoextendinnodb_flush_log_at_trx_commit = 2innodb_log_buffer_size = 64Minnodb_log_file_size = 256Minnodb_log_files_in_group = 3innodb_max_dirty_pages_pct = 90innodb_file_per_table = 1innodb_rollback_on_timeoutinnodb_status_file = 1innodb_io_capacity = 2000transaction_isolation = READ
#mysql>SET SQL_LOG_BIN=0#mysql>CREATE USER [email protected]‘%‘;#mysql>GRANT REPLICATION SLAVE ON *.* TO ‘rpl_user‘@‘%‘ identified by ‘123456‘;#mysql>SET SQL_LOG_BIN=1
change master to master_user=‘rpl_user‘,MASTER_PASSWORD=‘123456‘ for channel ‘group_replication_recovery‘;
install plugin group_replication soname ‘group_replication.so‘;

#mysql> set global group_replication_bootstrap_group=ON; # 只在第一个节点使用#mysq>START GROUP_REPLICATION;
stop group_replication;
select * from performance_schema.replication_group_members;

创建一个测试库
create database czg;use czg;create table t1 (id int not null,name varchar(32), primary key(id));insert into t1 values(1,‘chen‘),(‘2‘,‘zhang‘);
./mysqld --defaults-file=/data/mysql/mysql_3308/my_3308.cnf --initialize-insecure
#mysql>SET SQL_LOG_BIN=0#mysql>CREATE USER [email protected]‘%‘;#mysql>GRANT REPLICATION SLAVE ON *.* TO ‘rpl_user‘@‘%‘ identified by ‘123456‘;#mysql>SET SQL_LOG_BIN=1
change master to master_user=‘rpl_user‘,MASTER_PASSWORD=‘123456‘ for channel ‘group_replication_recovery‘;
install plugin group_replication soname ‘group_replication.so‘;
select * from performance_schema.replication_group_members;

第三个节点的安装:
初始化实列
./mysqld --defaults-file=/data/mysql/mysql_3309/my_3309.cnf --initialize-insecure
#mysql>SET SQL_LOG_BIN=0#mysql>CREATE USER [email protected]‘%‘;#mysql>GRANT REPLICATION SLAVE ON *.* TO ‘rpl_user‘@‘%‘ identified by ‘123456‘;#mysql>SET SQL_LOG_BIN=1
change master to master_user=‘rpl_user‘,MASTER_PASSWORD=‘123456‘ for channel ‘group_replication_recovery‘;
install plugin group_replication soname ‘group_replication.so‘;


其它两台的机器也会看到新增加数据


到此我们的主从环境就算搭建完成。
小结:其实环境的搭建还是比较的简单,你只要按文档说明基本能顺利的搭建下来。
注意事项:
select variable_value from performance_schema.global_status where variable_name=‘group_replication_primary_member‘;
select variable_value from performacne_schema.global_status where variable_name=‘group_repliation_primary_member‘;
另外一个问题就是启动的问题:
看日志就是我们的端口争用。主要是我们的配置文件的时候,没有把端口设置好,设置冲突了。
总结:主从搭建的环境就写到这里,后续还会针对Group Relication 做一个详细的介绍。水平有限,文中如果有不当或者错误之处,欢迎大家拍砖给我发邮件([email protected])。欢迎转载,转载请注明来源即可。