replication监控及自动故障切换
automatic replication health monitoring and failover
先下载安装包:
http://dev.mysql.com/downloads/
MySQL Utilities (GPL)
MySQL Connectors 中间件
yum install Utilities Connectors
实验环境:
step1:配置好两台replication环境,一台master 两台slave、
step2:在所有被监控机器为监控机授权:
grant create,insert,drop,select,super,replication slave,reload on *.* to 'repl'@'192.168.1.211'(monitior server) identified by '123456' with grant option;
grant create,insert,drop,select,super,replication slave,reload on *.* to 'repl'@'192.168.1.211' identified by '123456' with grant option;
step3: 修改三台机器的配置文件,并启用配置
[mysqld]
log-bin
gtid-mode=on
binlog-format=row
log-slave-updates=1
enforce-gtid-consistency
server-id=3
report-host=192.168.1.211 (本机的ip)
master-info-repository=TABLE 将replication缓存文件保存到table中
relay-log-info-repository=TABLE
/etc/init.d/mysqld restart
step4:
启动监控端:
--master=用户名:密码
mysqlfailover --master=repl:123456@192.168.20.238(master机器) --discover-slaves-login=repl:123456
模拟故障:
1,假如master挂了,slave会自动切换到master,另一个slave也会自动指向新的master
2,数据还可以正常同步
3,如果原先的master启动,failover 是不能自动发现,并且想要回到到原来的状态,需要手动操作。
在原master启动后,
重新change master to
change master to
master_host='192.168.20.238',
master_user='repl',
master_password='123456',
master_auto_position=1;
in 237(新的master 授权旧的master作为slave连接,并授权另一个也可以连接过来)
grant replication slave on *.* to repl@192.168.20.238 identified by '123456';
grant replication slave on *.* to repl@192.168.1.211 identified by '123456'; 无论谁是master 都可以取二进制日志
flush privileges;