MySQL高可用架构之MySQL5.7组复制MGR
###########################################################################################
规划MGR:
host1.us.oracle.com 10.10.20.95
host2.us.oracle.com 10.10.20.97
host3.us.oracle.com 10.10.20.132
MySQL版本:5.7.21
MySQL实例是33061端口
server-id=330611 330612 330613
###########################################################################################
host1:
MySQL实例是33061端口
mysql> select @@port;
+--------+
| @@port |
+--------+
| 33061 |
+--------+
1 row in set (0.01 sec)
[root@host1 ]#cat /etc/hosts
#FOR TEST MGR
10.10.20.132 host3.us.oracle.com
10.10.20.95 host1.us.oracle.com
10.10.20.97 host2.us.oracle.com
vi /data/mysql_33061/my.cnf
1 [client] 2 port = 33061 3 socket = /data/mysql_33061/run/mysql.sock 4 [mysqld] 5 port = 33061 6 socket = /data/mysql_33061/run/mysql.sock 7 pid_file = /data/mysql_33061/run/mysql.pid 8 basedir = /usr/local/mysql 9 datadir = /data/mysql_33061/data 10 default_storage_engine = InnoDB 11 max_allowed_packet = 128M 12 max_connections = 1024 13 open_files_limit = 65535 14 15 server-id=330611 16 skip-name-resolve 17 lower_case_table_names=1 18 19 character-set-server = utf8mb4 20 collation-server = utf8mb4_unicode_ci 21 init_connect='SET NAMES utf8mb4' 22 23 innodb_buffer_pool_size = 4096M 24 innodb_buffer_pool_instances = 8 25 innodb_buffer_pool_load_at_startup = 1 26 innodb_buffer_pool_dump_at_shutdown = 1 27 innodb_file_per_table = 1 28 innodb_flush_log_at_trx_commit = 2 29 innodb_data_home_dir=/data/mysql_33061/data/ 30 innodb_log_group_home_dir=/data/mysql_33061/logs/ 31 innodb_log_files_in_group=3 32 innodb_log_file_size=512M 33 innodb_data_file_path=ibdata1:512M:autoextend 34 log_slave_updates=1 35 binlog_format=ROW 36 key_buffer_size = 16M 37 innodb_log_buffer_size = 32M 38 innodb_io_capacity = 4000 39 innodb_io_capacity_max = 8000 40 innodb_flush_method = O_DIRECT 41 innodb_print_all_deadlocks = 1 42 43 log-error = /data/mysql_33061/logs/mysql_error.log 44 log-bin = /data/mysql_33061/logs/mysql_bin 45 slow_query_log = 1 46 slow_query_log_file = /data/mysql_33061/logs/mysql_slow_query.log 47 long_query_time = 2 48 sync_binlog = 600 49 relay_log_recovery = 1 50 51 tmp_table_size = 64M 52 max_heap_table_size = 64M 53 54 #FOR MGR 55 transaction_write_set_extraction = XXHASH64 56 loose-group_replication_group_name = 'ce9be252-2b71-11e6-b8f4-00212889f856' #不能用主机的GTID 57 loose-group_replication_start_on_boot = off 58 loose-group_replication_bootstrap_group = off 59 loose-group_replication_ip_whitelist = '10.10.20.95,10.10.20.132,10.10.20.97' 60 loose-group_replication_local_address = '10.10.20.95:33066' #写自己主机所在IP,端口自选 61 loose-group_replication_group_seeds ='10.10.20.95:33066,10.10.20.97:33066,10.10.20.132:33066'#写MGR组内主机所在IP,端口自选 62 loose-group_replication_single_primary_mode = off #关闭单主模式的参数 63 loose-group_replication_enforce_update_everywhere_checks = off #开启多主模式的参数 64 init_slave = 'set sql_mode=STRICT_ALL_TABLES' 65 #自动启动组复制 66 #loose-group_replication_start_on_boot = on 67 #group_replication_allow_local_disjoint_gtids_join = on 68 69 #FOR GTID 70 gtid_mode=on 71 enforce_gtid_consistency=on 72 binlog_gtid_simple_recovery=1 73 log_slave_updates=1 74 binlog_checksum=NONE 75 master_info_repository=TABLE 76 relay_log_info_repository=TABLE
mysql>INSTALL PLUGIN group_replication SONAME 'group_replication.so';
mysql> show plugins;
+----------------------------+----------+--------------------+----------------------+---------+
......
| BLACKHOLE | ACTIVE | STORAGE ENGINE | NULL | GPL |
| FEDERATED | DISABLED | STORAGE ENGINE | NULL | GPL |
| ngram | ACTIVE | FTPARSER | NULL | GPL |
| group_replication | ACTIVE | GROUP REPLICATION | group_replication.so | GPL |
+----------------------------+----------+--------------------+----------------------+---------+
45 rows in set (0.00 sec)
mysql>GRANT REPLICATION SLAVE ON *.* TO 'dbsync'@'10.10.%.%' IDENTIFIED BY 'xxxxxxx';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> CHANGE MASTER TO MASTER_USER='dbsync',MASTER_PASSWORD='xxxxxxx' FOR CHANNEL 'group_replication_recovery';
Query OK, 0 rows affected, 2 warnings (0.27 sec)
mysql> set global group_replication_ip_whitelist="10.10.20.95,10.10.20.132,10.10.20.97";
Query OK, 0 rows affected (0.00 sec)
mysql> SET GLOBAL group_replication_bootstrap_group=ON;
Query OK, 0 rows affected (0.00 sec)
mysql> set auto_increment_offset=5555;
Query OK, 0 rows affected (0.00 sec)
mysql> START GROUP_REPLICATION;
Query OK, 0 rows affected (2.04 sec)
mysql> SELECT * FROM performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-----------------------+-------------+--------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-----------------------+-------------+--------------+
| group_replication_applier | 57bc1e44-a447-11e8-8e78-5254000f067d | host1.us.oracle.com | 33061 | ONLINE |
+---------------------------+--------------------------------------+-----------------------+-------------+--------------+
1 row in set (0.00 sec)
###########################################################################################
host2:
[root@host2 ]#cat /etc/hosts
#FOR TEST MGR
10.10.20.132 host3.us.oracle.com
10.10.20.95 host1.us.oracle.com
10.10.20.97 host2.us.oracle.com
vi /data/mysql_33061/my.cnf
1 [client] 2 port = 33061 3 socket = /data/mysql_33061/run/mysql.sock 4 5 [mysqld] 6 port = 33061 7 socket = /data/mysql_33061/run/mysql.sock 8 pid_file = /data/mysql_33061/run/mysql.pid 9 basedir = /usr/local/mysql 10 datadir = /data/mysql_33061/data 11 default_storage_engine = InnoDB 12 max_allowed_packet = 128M 13 max_connections = 1024 14 open_files_limit = 65535 15 16 skip-name-resolve 17 lower_case_table_names=1 18 19 character-set-server = utf8mb4 20 collation-server = utf8mb4_unicode_ci 21 init_connect='SET NAMES utf8mb4' 22 23 innodb_buffer_pool_size = 4096M 24 innodb_buffer_pool_instances = 8 25 innodb_buffer_pool_load_at_startup = 1 26 innodb_buffer_pool_dump_at_shutdown = 1 27 innodb_file_per_table = 1 28 innodb_flush_log_at_trx_commit = 2 29 innodb_data_home_dir=/data/mysql_33061/data/ 30 innodb_log_group_home_dir=/data/mysql_33061/logs/ 31 innodb_log_files_in_group=3 32 innodb_log_file_size=512M 33 innodb_data_file_path=ibdata1:512M:autoextend 34 log_slave_updates=1 35 binlog_format=ROW 36 key_buffer_size = 16M 37 innodb_log_buffer_size = 32M 38 innodb_io_capacity = 4000 39 innodb_io_capacity_max = 8000 40 innodb_flush_method = O_DIRECT 41 innodb_print_all_deadlocks = 1 42 43 log-error = /data/mysql_33061/logs/mysql_error.log 44 log-bin = /data/mysql_33061/logs/mysql_bin.log 45 slow_query_log = 1 46 slow_query_log_file = /data/mysql_33061/logs/mysql_slow_query.log 47 long_query_time = 2 48 sync_binlog = 600 49 relay_log_recovery = 1 50 51 tmp_table_size = 64M 52 max_heap_table_size = 64M 53 54 server-id=330612 55 56 #FOR MGR 57 transaction_write_set_extraction = XXHASH64 58 loose-group_replication_group_name = 'ce9be252-2b71-11e6-b8f4-00212889f856' #不能用主机的GTID 59 loose-group_replication_start_on_boot = off 60 loose-group_replication_bootstrap_group = off 61 loose-group_replication_ip_whitelist = '10.10.20.95,10.10.20.132,10.10.20.97' 62 loose-group_replication_local_address = '10.10.20.97:33066' #写自己主机所在IP,端口自选 63 loose-group_replication_group_seeds ='10.10.20.95:33066,10.10.20.97:33066,10.10.20.132:33066'#写MGR组内主机所在IP,端口自选 64 loose-group_replication_single_primary_mode = off #关闭单主模式的参数 65 loose-group_replication_enforce_update_everywhere_checks = off #开启多主模式的参数 66 init_slave = 'set sql_mode=STRICT_ALL_TABLES' 67 68 #FOR GTID 69 gtid_mode=on 70 enforce_gtid_consistency=on 71 binlog_gtid_simple_recovery=1 72 log_slave_updates=1 73 binlog_checksum=NONE 74 master_info_repository=TABLE 75 relay_log_info_repository=TABLE
mysql>INSTALL PLUGIN group_replication SONAME 'group_replication.so';
mysql> CHANGE MASTER TO MASTER_USER='dbsync',MASTER_PASSWORD='xxxxxxx' FOR CHANNEL 'group_replication_recovery';
Query OK, 0 rows affected, 2 warnings (0.56 sec)
mysql> set global group_replication_ip_whitelist="10.10.20.95,10.10.20.132,10.10.20.97";
Query OK, 0 rows affected (0.00 sec)
mysql> set auto_increment_offset=5555;
Query OK, 0 rows affected (0.00 sec)
mysql> set global group_replication_allow_local_disjoint_gtids_join=ON;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> START GROUP_REPLICATION;
Query OK, 0 rows affected, 1 warning (6.88 sec)
###########################################################################################
host3:
[root@host3 ]#cat /etc/hosts
#FOR TEST MGR
10.10.20.132 host3.us.oracle.com
10.10.20.95 host1.us.oracle.com
10.10.20.97 host2.us.oracle.com
vi /data/mysql_33061/my.cnf
1 [client] 2 port = 33061 3 socket = /data/mysql_33061/run/mysql.sock 4 5 [mysqld] 6 port = 33061 7 socket = /data/mysql_33061/run/mysql.sock 8 pid_file = /data/mysql_33061/run/mysql.pid 9 basedir = /usr/local/mysql 10 datadir = /data/mysql_33061/data 11 default_storage_engine = InnoDB 12 max_allowed_packet = 128M 13 max_connections = 1024 14 open_files_limit = 65535 15 16 skip-name-resolve 17 lower_case_table_names=1 18 19 character-set-server = utf8mb4 20 collation-server = utf8mb4_unicode_ci 21 init_connect='SET NAMES utf8mb4' 22 23 24 innodb_buffer_pool_size = 4096M 25 innodb_buffer_pool_instances = 8 26 innodb_buffer_pool_load_at_startup = 1 27 innodb_buffer_pool_dump_at_shutdown = 1 28 innodb_file_per_table = 1 29 innodb_flush_log_at_trx_commit = 2 30 innodb_data_home_dir=/data/mysql_33061/data/ 31 innodb_log_group_home_dir=/data/mysql_33061/logs/ 32 innodb_log_files_in_group=3 33 innodb_log_file_size=512M 34 innodb_data_file_path=ibdata1:512M:autoextend 35 log_slave_updates=1 36 binlog_format=ROW 37 key_buffer_size = 16M 38 innodb_log_buffer_size = 32M 39 innodb_io_capacity = 4000 40 innodb_io_capacity_max = 8000 41 innodb_flush_method = O_DIRECT 42 innodb_print_all_deadlocks = 1 43 44 log-error = /data/mysql_33061/logs/mysql_error.log 45 log-bin = /data/mysql_33061/logs/mysql_bin.log 46 slow_query_log = 1 47 slow_query_log_file = /data/mysql_33061/logs/mysql_slow_query.log 48 long_query_time = 2 49 sync_binlog = 600 50 relay_log_recovery = 1 51 52 tmp_table_size = 64M 53 max_heap_table_size = 64M 54 55 server-id=330613 56 57 #FOR MGR 58 transaction_write_set_extraction = XXHASH64 59 loose-group_replication_group_name = 'ce9be252-2b71-11e6-b8f4-00212889f856' #不能用主机的GTID 60 loose-group_replication_start_on_boot = off 61 loose-group_replication_bootstrap_group = off 62 loose-group_replication_ip_whitelist = '10.10.20.95,10.10.20.132,10.10.20.97' 63 loose-group_replication_local_address = '10.10.20.132:33066' #写自己主机所在IP,端口自选 64 loose-group_replication_group_seeds ='10.10.20.95:33066,10.10.20.97:33066,10.10.20.132:33066'#写MGR组内主机所在IP,端口自选 65 loose-group_replication_single_primary_mode = off #关闭单主模式的参数 66 loose-group_replication_enforce_update_everywhere_checks = off #开启多主模式的参数 67 init_slave = 'set sql_mode=STRICT_ALL_TABLES' 68 69 #FOR GTID 70 gtid_mode=on 71 enforce_gtid_consistency=on 72 binlog_gtid_simple_recovery=1 73 log_slave_updates=1 74 binlog_checksum=NONE 75 master_info_repository=TABLE 76 relay_log_info_repository=TABLE
mysql>INSTALL PLUGIN group_replication SONAME 'group_replication.so';
mysql> CHANGE MASTER TO MASTER_USER='dbsync',MASTER_PASSWORD='xxxxxxx' FOR CHANNEL 'group_replication_recovery';
Query OK, 0 rows affected, 2 warnings (0.56 sec)
mysql> set global group_replication_ip_whitelist="10.10.20.95,10.10.20.132,10.10.20.97";
Query OK, 0 rows affected (0.00 sec)
mysql> set auto_increment_offset=5555;
Query OK, 0 rows affected (0.00 sec)
mysql> set global group_replication_allow_local_disjoint_gtids_join=ON;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> START GROUP_REPLICATION;
Query OK, 0 rows affected, 1 warning (3.27 sec)
mysql> SELECT * FROM performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-----------------------+-------------+--------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-----------------------+-------------+--------------+
| group_replication_applier | 041eac3b-a40a-11e8-b11f-545200297bd8 | host2.us.oracle.com | 33061 | ONLINE |
| group_replication_applier | 57bc1e44-a447-11e8-8e78-5254000f067d | host1.us.oracle.com | 33061 | ONLINE |
| group_replication_applier | e3d6b2db-a44e-11e8-8769-545200494892 | host3.us.oracle.com | 33061 | ONLINE |
+---------------------------+--------------------------------------+-----------------------+-------------+--------------+
3 rows in set (0.00 sec)
host1:
mysql> SELECT * FROM performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-----------------------+-------------+--------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-----------------------+-------------+--------------+
| group_replication_applier | 041eac3b-a40a-11e8-b11f-545200297bd8 | host2.us.oracle.com | 33061 | ONLINE |
| group_replication_applier | 57bc1e44-a447-11e8-8e78-5254000f067d | host1.us.oracle.com | 33061 | ONLINE |
| group_replication_applier | e3d6b2db-a44e-11e8-8769-545200494892 | host3.us.oracle.com | 33061 | ONLINE |
+---------------------------+--------------------------------------+-----------------------+-------------+--------------+
3 rows in set (0.00 sec)
host2:
mysql> SELECT * FROM performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-----------------------+-------------+--------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-----------------------+-------------+--------------+
| group_replication_applier | 041eac3b-a40a-11e8-b11f-545200297bd8 | host2.us.oracle.com | 33061 | ONLINE |
| group_replication_applier | 57bc1e44-a447-11e8-8e78-5254000f067d | host1.us.oracle.com | 33061 | ONLINE |
| group_replication_applier | e3d6b2db-a44e-11e8-8769-545200494892 | host3.us.oracle.com | 33061 | ONLINE |
+---------------------------+--------------------------------------+-----------------------+-------------+--------------+
3 rows in set (0.00 sec)
查询主节点:
select variable_value from performance_schema.global_status where variable_name='group_replication_primary_member';
查看当前实例是否有延迟等性能问题(通过队列深度判断)的方法:
select * from performance_schema.replication_group_member_statsG;
通过查看COUNT_TRANSACTIONS_IN_QUEUE的值,可以判断等待处理的事务数。
参考:
http://www.cnblogs.com/xinysu/p/6674832.html
https://www.cnblogs.com/manger/p/7211932.html