MGR安装配置
同一个集群中,/etc/hosts文件最好直接配置成一样,把集群中所有ip都配置进去
初始化,这边是三个节点
[root@localhost data]# /usr/local/mysql/bin/mysqld --defaults-file=/etc/my3306.cnf --initialize
启动第一个节点,登陆修改root初始密码
[root@bogon data]# /usr/local/mysql/bin/mysqld --defaults-file=/etc/my3306.cnf & [1] 44900
[root@bogon data]# /usr/local/mysql/bin/mysql -uroot -p -S /tmp/mysql3306.sock Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.21-log Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> alter user root@localhost identified by '123456'; Query OK, 0 rows affected (0.00 sec) mysql> select user,host from mysql.user; +---------------+-----------+ | user | host | +---------------+-----------+ | mysql.session | localhost | | mysql.sys | localhost | | root | localhost | +---------------+-----------+ 3 rows in set (0.00 sec) mysql> exit Bye
[root@bogon data]# /usr/local/mysql/bin/mysql -uroot -p -S /tmp/mysql3306.sock Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.21-log MySQL Community Server (GPL) Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> set sql_log_bin = 0; Query OK, 0 rows affected (0.00 sec) mysql> show master status; +------------------+----------+--------------+------------------+----------------------------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+----------------------------------------+ | mysql-bin.000002 | 386 | | | 8ec33d06-2bf2-11e8-a45d-000c29e0df19:1 | +------------------+----------+--------------+------------------+----------------------------------------+ 1 row in set (0.00 sec) # 这个动作不是必须的,这里只是为了让binlog看着更干净 mysql> reset master; Query OK, 0 rows affected (0.01 sec) mysql> show master status; +------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+ | mysql-bin.000001 | 150 | | | | +------------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) 创建复制用户 mysql> set sql_log_bin = 0; Query OK, 0 rows affected (0.00 sec) mysql> create user repl@'%' identified by 'repl4slave'; Query OK, 0 rows affected (0.00 sec) mysql> grant replication slave on *.* to repl@'%'; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> set sql_log_bin = 1; Query OK, 0 rows affected (0.00 sec) mysql> change master to master_user='repl', master_password='repl4slave' for channel 'group_replication_recovery'; Query OK, 0 rows affected, 2 warnings (0.03 sec) mysql> install plugin group_replication soname 'group_replication.so'; Query OK, 0 rows affected (0.06 sec) # 只在第一个节点操作,表示是集群中的第一个节点 mysql> set global group_replication_bootstrap_group = on; Query OK, 0 rows affected (0.00 sec) mysql> start group_replication; Query OK, 0 rows affected (2.05 sec) mysql> select * from performance_schema.replication_group_members; +---------------------------+--------------------------------------+-------------+-------------+--------------+ | CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | +---------------------------+--------------------------------------+-------------+-------------+--------------+ | group_replication_applier | 24b4f050-2c17-11e8-a9fc-000c29e0df19 | bogon | 3306 | ONLINE | +---------------------------+--------------------------------------+-------------+-------------+--------------+ 1 row in set (0.00 sec) mysql> set global group_replication_bootstrap_group = off; Query OK, 0 rows affected (0.00 sec)
接下来配置第二个节点,同样需要初始化
[root@localhost data]# /usr/local/mysql/bin/mysqld --defaults-file=/etc/my3306.cnf --initialize [root@localhost data]# cat error.log | grep password 2018-03-20T08:36:06.902818Z 1 [Note] A temporary password is generated for root@localhost: qslBuo,q81VX [root@localhost data]# mysqld --defaults-file=/etc/my3306.cnf & [1] 50387 [root@localhost data]# [root@localhost data]# mysql -uroot -p -S /tmp/mysql3306.sock Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.21-log Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> alter user user() identified by '123456'; Query OK, 0 rows affected (0.00 sec) mysql> show master status; +------------------+----------+--------------+------------------+-----------------------------------------------------------------------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-----------------------------------------------------------------------------------+ | mysql-bin.000003 | 442 | | | 3db33b36-0e51-409f-a61d-c99756e90155:1-11, bba76cb3-2c19-11e8-9012-000c296cd2f8:1 | +------------------+----------+--------------+------------------+-----------------------------------------------------------------------------------+ 1 row in set (0.00 sec) mysql> reset master; Query OK, 0 rows affected (0.00 sec) mysql> set sql_log_bin = 0; Query OK, 0 rows affected (0.00 sec) mysql> create user repl@'%' identified by 'repl4slave'; Query OK, 0 rows affected (0.00 sec) mysql> grant replication slave on *.* to repl@'%'; Query OK, 0 rows affected (0.00 sec) mysql> install plugin group_replication soname 'group_replication.so'; mysql> set sql_log_bin =1; Query OK, 0 rows affected (0.00 sec) mysql> change master to master_user='repl', master_password='repl4slave' for channel 'group_replication_recovery'; Query OK, 0 rows affected, 2 warnings (0.01 sec) mysql> show master status; +------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+ | mysql-bin.000001 | 150 | | | | +------------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) mysql> start group_replication; Query OK, 0 rows affected (4.82 sec) mysql> select * from performance_schema.replication_group_members; +---------------------------+--------------------------------------+-----------------------+-------------+--------------+ | CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | +---------------------------+--------------------------------------+-----------------------+-------------+--------------+ | group_replication_applier | 24b4f050-2c17-11e8-a9fc-000c29e0df19 | bogon | 3306 | ONLINE | | group_replication_applier | bba76cb3-2c19-11e8-9012-000c296cd2f8 | localhost.localdomain | 3306 | ONLINE | +---------------------------+--------------------------------------+-----------------------+-------------+--------------+ 2 rows in set (0.00 sec)
继续添加第三个节点,步骤与第二个节点完全一样,只需要注意配置文件里loose-group_replication_group_name需要填写自身ip
[root@localhost data]# mysqld --defaults-file=/etc/my3306.cnf --initialize [root@localhost data]# [root@localhost data]# [root@localhost data]# cat error.log | grep password 2018-03-20T08:48:27.641519Z 1 [Note] A temporary password is generated for root@localhost: r#kyjqZrP0Zw [root@localhost data]# mysqld --defaults-file=/etc/my3306.cnf & [1] 50384 [root@localhost data]# [root@localhost data]# mysql -uroot -p -S /tmp/mysql3306.sock Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.21-log Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> mysql> mysql> alter user user() identified by '123456'; Query OK, 0 rows affected (0.00 sec) mysql> reset master; Query OK, 0 rows affected (0.07 sec) mysql> set sql_log_bin = 0; Query OK, 0 rows affected (0.00 sec) mysql> create user repl@'%' identified by 'repl4slave'; Query OK, 0 rows affected (0.00 sec) mysql> grant replication slave on *.* to repl@'%'; Query OK, 0 rows affected (0.00 sec) mysql> install plugin group_replication soname 'group_replication.so'; mysql> set sql_log_bin = 1; Query OK, 0 rows affected (0.00 sec) mysql> change master to master_user='repl', master_password='repl4slave' for channel 'group_replication_recovery'; Query OK, 0 rows affected, 2 warnings (0.02 sec) mysql> install plugin group_replication soname 'group_replication.so'; Query OK, 0 rows affected (0.07 sec) mysql> start group_replication; Query OK, 0 rows affected (3.07 sec) mysql>
配置文件参考
#my.cnf [client] port = 3306 socket = /tmp/mysql3306.sock [mysql] prompt="\\u@\\h:\\p [\\d]> #pager="less -i -n -S" #tee=/home/mysql/query.log no-auto-rehash [mysqld] #misc user = mysql basedir = /usr/local/mysql datadir = /data/mgr/data port = 3306 socket = /tmp/mysql3306.sock event_scheduler = 0 tmpdir=/data/mgr/tmp #timeout interactive_timeout = 300 wait_timeout = 300 #character set character-set-server = utf8 open_files_limit = 65535 max_connections = 100 max_connect_errors = 100000 # explicit_defaults_for_timestamp #logs log-output=file slow_query_log = 1 slow_query_log_file = slow.log log-error = error.log log_error_verbosity=3 pid-file = mysql.pid long_query_time = 1 #log-slow-admin-statements = 1 #log-queries-not-using-indexes = 1 log-slow-slave-statements = 1 #binlog binlog_format = row log-bin = /data/mgr/logs/mysql-bin binlog_cache_size = 1M max_binlog_size = 200M max_binlog_cache_size = 2G sync_binlog = 0 expire_logs_days = 10 #group replication server_id=1323306 gtid_mode=ON enforce_gtid_consistency=ON master_info_repository=TABLE relay_log_info_repository=TABLE binlog_checksum=NONE log_slave_updates=ON binlog_format=ROW transaction_write_set_extraction=XXHASH64 loose-group_replication_group_name="3db33b36-0e51-409f-a61d-c99756e90155" loose-group_replication_start_on_boot=off loose-group_replication_local_address= "192.168.80.132:23306" loose-group_replication_group_seeds= "192.168.80.132:23306,192.168.80.128:23306,192.168.80.133:23306" loose-group_replication_bootstrap_group= off loose-group_replication_single_primary_mode=off loose-group_replication_enforce_update_everywhere_checks=on #relay log skip_slave_start = 1 max_relay_log_size = 500M relay_log_purge = 1 relay_log_recovery = 1 #slave-skip-errors=1032,1053,1062 #buffers & cache table_open_cache = 2048 table_definition_cache = 2048 table_open_cache = 2048 max_heap_table_size = 96M sort_buffer_size = 2M join_buffer_size = 2M thread_cache_size = 256 query_cache_size = 0 query_cache_type = 0 query_cache_limit = 256K query_cache_min_res_unit = 512 thread_stack = 192K tmp_table_size = 96M key_buffer_size = 8M read_buffer_size = 2M read_rnd_buffer_size = 16M bulk_insert_buffer_size = 32M #myisam myisam_sort_buffer_size = 128M myisam_max_sort_file_size = 10G myisam_repair_threads = 1 #innodb innodb_buffer_pool_size = 100M innodb_buffer_pool_instances = 1 innodb_data_file_path = ibdata1:100M:autoextend innodb_flush_log_at_trx_commit = 2 innodb_log_buffer_size = 64M innodb_log_file_size = 256M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 90 innodb_file_per_table = 1 innodb_rollback_on_timeout innodb_status_file = 1 innodb_io_capacity = 2000 transaction_isolation = READ-COMMITTED innodb_flush_method = O_DIRECT