先来了解下同步复制和异步复制的概念:
- vim /etc/my.cnf
- datadir=/data/mydata
- server-id = 1
- log-bin = /bin/log/mysql-bin
- sync_binlog = 1
- service mysqld start
- mysql> grant replication client,replication slave on *.* to 'rpuser'@'172.16.9.2' identified by 'redhat';
- mysql> flush privileges;
- mysql> install plugin rpl_semi_sync_master soname 'semisync_master.so'; #为主服务器安装插件
- mysql> set global rpl_semi_sync_master_enabled=1; #设定启用半同步机制
- mysql> set global rpl_semi_sync_master_timeout=1000; #设定通知的超时时间,单位是毫秒,这里设置为1秒
- mysql> show master status; #记录二进制文件以及所在位置
- +------------------+----------+--------------+------------------+
- | File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
- +------------------+----------+--------------+------------------+
- | mysql-bin.000004 | 354 | | |
- +------------------+----------+--------------+------------------+
- 1 row in set (0.00 sec)
- vim /etc/my.cnf
- datadir = /data/mydata
- server-id = 5
- relay-log = /relaylog/mysql-relay #开启中继日志功能
- relay-log-index = /relaylog/mysql-relay.index #开启中继日志的索引功能
- read-only = 1 #只读功能
- #bin-log = mysql-bin #关闭二进制日志功能
- service mysqld start
- mysql> change master to master_host='172.16.9.1', master_user='reuser', master_password='reuser', master_port=3306, master_log_file='mysql-bin.000004', master_log_pos=354;
- mysql> install plugin rpl_semi_sync_slave soname 'semisync_slave.so';
- mysql> set global rpl_semi_sync_slave_enabled=1; #开启半同步机制
- mysql> start slave;
- mysql> show slave status\G;
- *************************** 1. row ***************************
- Slave_IO_State: Waiting for master to send event
- Master_Host: 172.16.9.1
- Master_User: reuser
- Master_Port: 3306
- Connect_Retry: 60
- Master_Log_File: mysql-bin.000004
- Read_Master_Log_Pos: 354
- Relay_Log_File: mysql-relay.000011
- Relay_Log_Pos: 500
- Relay_Master_Log_File: mysql-bin.000004
- Slave_IO_Running: Yes
- Slave_SQL_Running: Yes
- …………………………………………………………………………………………………………………………………………
- vim /etc/my.cnf
- 在[mysqld]字段中添加
- rpl_semi_sync_master_enabled=1
- rpl_semi_sync_master_timeout=1000
- 在[mysqld]字段中添加
- rpl_semi_sync_slave_enabled=1