环境说明:
- 系统环境:Centos 7.
- Mysql版本:5.6.33
- Master-Server : 192.168.1.157.88
- Slave-Server : 192.168.1.157.89
- 主从数据库都建立测试库(如:testdatabase)
异步配置
Master 主库配置
1, 增加从库同步账号
mysql> GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.*
-> TO repl@'192.168.157.89' IDENTIFIED BY 'repl_password';
2, 配置my.cnf
[mysqld]
log-bin=mysql-bin
server-id=1
3, 重启 Mysql , 查看 Master Status
# Service mysqld restart;
//进入mysql
mysql> SHOW MASTER STATUS;
Slave 从库配置
1, 配置 my.cnf
[mysqld]
log_bin = mysql-bin
server_id = 2
relay_log = mysql-relay-bin
log_slave_updates = 1
read_only = 1
2, 链接Master ,启动Slave
mysql> CHANGE MASTER TO MASTER_HOST='192.168.1.157.88',
-> MASTER_USER='repl',
-> MASTER_PASSWORD='repl_password',
-> MASTER_LOG_FILE='mysql-bin.000001',
-> MASTER_LOG_POS=0;
//启动 Slave
mysql> START SLAVE;
如图:
Slave_IO_Running:Yes
Slave_SQL_Running:Yes
同步配置成功,可以在主库插入数据库测试!
半同步配置
Master 主库配置
1, 安装插件:semisync_master.so
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;
mysql> SHOW VARIBALES LIKE '%semi%';
2,配置 my.cnf 让 Mysql 启动生效
[mysqld]rpl_semi_sync_master_enabled = 1
rpl_semi_sync_master_timeout = 1000
# Service mysqld restart
Slave 从库配置
1, 安装插件
mysql> INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';
mysql> SET GLOBAL rpl_semi_sync_slave_enabled = 1;
mysql> STOP SLAVE;mysql> START SLAVE;
mysql> SHOW VARIBALES LIKE '%semi%';
2,配置 my.cnf 让 Mysql 启动生效
[mysqld]rpl_semi_sync_slave_enabled = 1
# Service mysqld restart
检查半同步是否生效
Master:
mysql> show global status like 'rpl_semi%';