mysql-mmm+amoeba+keepalived实现mysql高可用和读写分离(二)

u       利用mmm_control监控mysql服务器状态:

[root@server3 ~]#  mmm_control show

  db1(192.168.1.161) master/ONLINE. Roles: reader(192.168.1.111), writer(192.168.1.113)

  db2(192.168.1.162) master/ONLINE. Roles: reader(192.168.1.114)

  db3(192.168.1.164) slave/ONLINE. Roles: reader(192.168.1.115)

  db4(192.168.1.165) slave/ONLINE. Roles: reader(192.168.1.112)

 

u       测试看两个mysql服务器能否实现故障自动切换

停掉作为写的db1上的mysql,查看写的服务器会不会自动转移到db2上去

停掉几秒钟后用mmm_control show查看:

[root@server3 ~]#  mmm_control show

  db1(192.168.1.161) master/HARD_OFFLINE. Roles:

  db2(192.168.1.162) master/ONLINE. Roles: reader(192.168.1.112), writer(192.168.1.113)

  db3(192.168.1.164) slave/ONLINE. Roles: reader(192.168.1.114), reader(192.168.1.115)

  db4(192.168.1.165) slave/ONLINE. Roles: reader(192.168.1.111)

我们可以看到已经把db2当作主写服务器,另外server4server5原来是从server1更新的现在已经被mmm自动更改到从新的主服务器server2上更新了,很神奇!可以登录到server4server5上用show slave status\G;命令查看!

 

        再来看看db1恢复后会是什么情况:

[root@server3 ~]#  mmm_control show

  db1(192.168.1.161) master/ONLINE. Roles: reader(192.168.1.114)

  db2(192.168.1.162) master/ONLINE. Roles: reader(192.168.1.112), writer(192.168.1.113)

  db3(192.168.1.164) slave/ONLINE. Roles: reader(192.168.1.115)

  db4(192.168.1.165) slave/ONLINE. Roles: reader(192.168.1.111)

我们可以看到当db1恢复后就充当slave的角色了!只有当db2挂了以后db1又会担当起主服务器的写入功能

发现个bug,不知道有没有人遇到过:有的时候会出现服务器恢复后,服务器的状态被设置为:AWAITING_RECOVERY,必须要手工执行mmm_control set_online host才能恢复正常,比如:有的时候我恢复db1后,出现如下:

[root@server3 ~]#  mmm_control show

  db1(192.168.1.161) master/AWAITING_RECOVERY. Roles:

  db2(192.168.1.162) master/ONLINE. Roles: reader(192.168.1.112), writer(192.168.1.113)

  db3(192.168.1.164) slave/ONLINE. Roles: reader(192.168.1.114), reader(192.168.1.115)

  db4(192.168.1.165) slave/ONLINE. Roles: reader(192.168.1.111)

解决办法为利用set_online手工更改为在线状态:

[root@server3 ~]#  mmm_control set_online db1

OK: State of 'db1' changed to ONLINE. Now you can wait some time and check its new roles!

[root@server3 ~]#  mmm_control show

  db1(192.168.1.161) master/ONLINE. Roles: reader(192.168.1.114)

  db2(192.168.1.162) master/ONLINE. Roles: reader(192.168.1.112), writer(192.168.1.113)

  db3(192.168.1.164) slave/ONLINE. Roles: reader(192.168.1.115)

  db4(192.168.1.165) slave/ONLINE. Roles: reader(192.168.1.111)

解决这个问题还有一个办法就是将auto_set_online设置小点,默认是60s,设置成10看下会不会有改善?

 

u       mmm_control命令简介

[root@server3 mysql-mmm]# mmm_control help

Valid commands are:

    help                              - show this message

   #查看帮助信息

ping                              - ping monitor

#ping监控

show                              - show status

#查看状态信息

checks [<host>|all [<check>|all]] - show checks status

#显示检查状态,包括(pingmysqlrep_threadsrep_backlog

set_online <host>                 - set host <host> online

#设置某hostonline状态

set_offline <host>                - set host <host> offline

#设置某hostoffline状态

mode                              - print current mode.

#打印当前的模式,是ACTIVEMANUALPASSIVE

#默认ACTIVE模式

set_active                        - switch into active mode.

#更改为active模式

set_manual                        - switch into manual mode.

#更改为manual模式

set_passive                       - switch into passive mode.

#更改为passive模式

    move_role [--force] <role> <host> - move exclusive role <role> to host <host>

       #更改host的模式,比如更改处于slavemysql数据库角色为write  

   (Only use --force if you know what you are doing!)

set_ip <ip> <host>                - set role with ip <ip> to host <host>

#host设置ip,只有passive模式的时候才允许更改!

你可能感兴趣的:(mysql,keepalived,服务器,amoeba,mmm)