systemctl restart mysql 启动不了请认真检查my.cnf和查看日志。
进入主数据库得到binlog日志文件名和偏移量
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 | 1216| | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec) 注意:如果是在使用数据库需要使用读锁 mysql>flush tables with read lock; 备份主库数据库,并使用source恢复到从机。 mysqldump test > test.sql 然后解锁主库 mysql>unlock tables; 由于本文是新建虚拟机没有数据,这步可以略过。
记录好binlogfile和position之后,在主库创建用户
grant replication slave on *.* to 'repl'@'192.168.1.152' identified by 'repl';
grant replication slave on *.* to 'repl'@'192.168.1.153' identified by 'repl'; 分别进入152和153的mysql执行:
change master to master_host='192.168.1.151',master_user='repl',master_password='repl',master_port=3306,master_log_file='master-bin.000001',master_log_pos=1216; 安装插件,分别进入3台mysql执行:
mysql> install plugin rpl_semi_sync_master soname 'semisync_master.so';
mysql> install plugin rpl_semi_sync_slave soname 'semisync_slave.so';
mysql> set global rpl_semi_sync_master_enabled=on ;
注意 从库最后一行执行set global rpl_semi_sync_slave_enabled=on ; 注意:在启动slave之前,如果你使用虚拟机克隆功能或者直接copy,要删除/var/lib/mysql/auto.cnf,否则会提示同步失败。
启动slave,分别进入152和153的mysql执行:
mysql> start slave;
mysql> set global read_only=1; 在从库查看show slave status\G; Slave_IO_Running: Yes Slave_SQL_Running: Yes
看到以上两个字段带兵同步成功。
在主库可以使用
show global status like 'rpl_semi%';
查看同步情况。
以上mysql半同步配置基本完成。