Linux企业实战----mysql的半同步复制(稍后完善)

mysql的gtid的开启

server2.3:
vim /etc/my.cnf

gtid_mode=ON
enforce-gtid-consistency=ON

/etc/init.d/mysqld restart

Linux企业实战----mysql的半同步复制(稍后完善)_第1张图片

 

server3:
mysql -pZxn@@0823

stop slave;

mysql> change master to
    -> master_host='172.25.11.2',
    -> master_user='repl',
    -> master_password='Zxn@@0823',
    -> master_auto_position=1;

start slave

show variables like 'gtid%'; 查看gtid是否开启

Linux企业实战----mysql的半同步复制(稍后完善)_第2张图片

 

2.半同步

server2:
mysql -pZxn@@0823
INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';
show variables like 'rpl%';
SET GLOBAL rpl_semi_sync_master_enabled = 1;
show variables like 'rpl%';(此时rpl_semi_sync_master_enabled  开启)

Linux企业实战----mysql的半同步复制(稍后完善)_第3张图片

server3:
INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';
show variables like 'rpl%';
SET GLOBAL rpl_semi_sync_slave_enabled = 1;
show variables like 'rpl%';(此时rpl_semi_sync_slave_enabled 开启)
STOP SLAVE IO_THREAD;
START SLAVE IO_THREAD;
show slave status\G;

 

注意:若slave的sql出现问题(比master少了个表westos) 可尝试重置slave 步骤如下:
mysql -pZxn@@0823


stop slave;
reset slave;
reset master; 退出mysql

mysql -pZxn@@0823

drop database westos;
start slave;
show slave status\G;

Linux企业实战----mysql的半同步复制(稍后完善)_第4张图片

 

3.slave SQL线程优化

server3:

mysql -pZxn@@0823

mysql> STOP SLAVE SQL_THREAD;
Query OK, 0 rows affected (0.00 sec)

mysql> set global slave_parallel_type=LOGICAL_CLOCK;
Query OK, 0 rows affected (0.00 sec)

mysql> set global slave_parallel_workers=16;
Query OK, 0 rows affected (0.00 sec)

mysql> START SLAVE SQL_THREAD;
Query OK, 0 rows affected (0.08 sec)

mysql> show variables like '%parallel%';
+------------------------------+---------------+
| Variable_name                | Value         |
+------------------------------+---------------+
| innodb_parallel_read_threads | 4             |
| slave_parallel_type          | LOGICAL_CLOCK |
| slave_parallel_workers       | 16            |
+------------------------------+---------------+


4.线性传输a-->b-->c

server3:

mysql:
  create user 'repl'@'172.25.11.%' identified by 'Zxn@@0823';
  grant replication slave on *.* to 'repl'@'172.25.11.%';
  flush privileges;
  show master status;
  退出mysql

cd /usr/local/mysql/
mysqldump -u root -pZxn@@0823 --databases westos ggg --set-gtid-purged=OFF > dump.sql
scp dump.sql server4:

Linux企业实战----mysql的半同步复制(稍后完善)_第5张图片

Linux企业实战----mysql的半同步复制(稍后完善)_第6张图片

 

server4:(my.cnf中gtid需打开)

mysql -h 172.25.11.3 -u repl -pZxn@@0823
cd ~
mysql -u root -pZxn@@0823 < dump.sql
mysql -pZxn@@0823
  change master to
    -> master_host='172.25.11.3',
    -> master_user='repl',
    -> master_password='Zxn@@0823',
    -> get_master_public_key=1;
  start slave;
  show slave status\G;

Linux企业实战----mysql的半同步复制(稍后完善)_第7张图片

Linux企业实战----mysql的半同步复制(稍后完善)_第8张图片

你可能感兴趣的:(Linux企业实战)