[root@mmm-monitor ~]# vim /etc/mysql-mmm/mmm_mon.conf include mmm_common.conf <monitor> ip 192.168.1.15 pid_path /var/run/mysql-mmm/mmm_mond.pid bin_path /usr/libexec/mysql-mmm status_path /var/lib/mysql-mmm/mmm_mond.status ping_ips 192.168.1.11, 192.168.1.12, 192.168.1.13, 192.168.1.14 auto_set_online 60 # The kill_host_bin does not exist by default, though the monitor will # throw a warning about it missing. See the section 5.10 "Kill Host # Functionality" in the PDF documentation. # # kill_host_bin /usr/libexec/mysql-mmm/monitor/kill_host # </monitor> <host default> monitor_user mmm_monitor monitor_password 123456 </host> debug 0
9.启动服务:
在mmm-monitor启动:
[root@mmm-monitor ~]# chkconfig mysql-mmm-monitor on [root@mmm-monitor ~]# service mysql-mmm-monitor start
在所有mysql服务器上启动
chkconfig mysql-mmm-agent on service mysql-mmm-agent start
六、高可用性测试:服务器读写采有VIP地址进行读写,出现故障时VIP会漂移到其它节点,由其它节点提供服务。
mysql-mmm故障处理机制:
1.首先查看整个集群的状态,可以看到整个集群状态正常
[root@mmm-monitor ~]# mmm_control show master-db1(192.168.1.11) master/ONLINE. Roles: reader(192.168.1.251), writer(192.168.1.250) master-db2(192.168.1.12) master/ONLINE. Roles: reader(192.168.1.254) slave-db1(192.168.1.13) slave/ONLINE. Roles: reader(192.168.1.252) slave-db2(192.168.1.14) slave/ONLINE. Roles: reader(192.168.1.253)
2.关闭master-db1上的mysql服务,模拟mysql宕机
[root@master-db1 ~]# service mysqld stop Shutting down MySQL... [确定]
3.mmm-monitor上查看集群状态
[root@mmm-monitor ~]# mmm_control show master-db1(192.168.1.11) master/HARD_OFFLINE. Roles: master-db2(192.168.1.12) master/ONLINE. Roles: reader(192.168.1.254), writer(192.168.1.250) slave-db1(192.168.1.13) slave/ONLINE. Roles: reader(192.168.1.251), reader(192.168.1.252) slave-db2(192.168.1.14) slave/ONLINE. Roles: reader(192.168.1.253)
从显示结果可以看出master-db1的状态有ONLINE转换为HARD_OFFLINE,写VIP转移到了master-db2主机上。
4.查看slave-db1和slave-db2主从状态
mysql> show slave status\G #slave-db1 *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.1.12 Master_User: replication Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000001 Read_Master_Log_Pos: 636231 Relay_Log_File: relay-log.000002 Relay_Log_Pos: 283 Relay_Master_Log_File: mysql-bin.000001 Slave_IO_Running: Yes Slave_SQL_Running: Yes
mysql> show slave status\G #slave-db2 *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.1.12 Master_User: replication Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000001 Read_Master_Log_Pos: 636231 Relay_Log_File: relay-log.000002 Relay_Log_Pos: 283 Relay_Master_Log_File: mysql-bin.000001 Slave_IO_Running: Yes Slave_SQL_Running: Yes
可以看到写请求的VIP已经转移到master-db2上了,且从节点的主都指向了master-db2
5.启动master-db1的mysql服务
[root@master-db1 ~]# service mysqld start Starting MySQL...... [确定]
6.再次查看集群状态(大概等待一分钟左右)