MySQL高可用架构之Keepalived+主从架构部署(5)

[root@node1 keepalived]# ip add|grep inet
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
    inet 192.168.1.23/24 brd 192.168.1.255 scope global eth1
    inet 192.168.1.27/32 scope global eth1:1
    inet6 fe80::250:56ff:fe8d:496/64 scope link

备库服务器状态检查:

[root@node2 keepalived]# ip add|grep inet
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
    inet 192.168.1.24/24 brd 192.168.1.255 scope global eth1
    inet 192.168.1.27/32 scope global eth1:1
    inet6 fe80::250:56ff:fe8d:3d1e/64 scope link

如果关掉从库的防火墙,那么VIP会选择高优先级的服务器上(priority)

此现象如何避免?我们可以在check_gateway.sh脚本里添加上组播状态检查的命令,我这里就不做了,仅做了网关检查的脑裂避免(网络问题导致网关暂时不可达而产生的脑裂)

6、模拟主切换到备后,主服务启动后是否会回切(优先级抢占测试)

(本次测试接着测试1进行,首先恢复主库的实例进程和keepalived进程)

主库执行命令:

[root@node1 keepalived]# service mysqld start
Starting MySQL (Percona Server)......                      [  OK  ]
[root@node1 keepalived]# service keepalived start
Starting keepalived:                                      [  OK  ]
[root@node1 keepalived]# service mysqld status   
MySQL (Percona Server) running (1141)                      [  OK  ]
[root@node1 keepalived]# service keepalived status
keepalived (pid  1230) is running...
[root@node1 keepalived]# ip add |grep inet       
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
    inet 192.168.1.23/24 brd 192.168.1.255 scope global eth1
    inet6 fe80::250:56ff:fe8d:496/64 scope link

备库执行命令:

[root@node2 keepalived]# service keepalived status
keepalived (pid  12207) is running...
[root@node2 keepalived]# service mysqld status   
MySQL (Percona Server) running (14146)                    [  OK  ]
[root@node2 keepalived]# ip add |grep inet
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
    inet 192.168.1.24/24 brd 192.168.1.255 scope global eth1
    inet 192.168.1.27/32 scope global eth1:1
    inet6 fe80::250:56ff:fe8d:3d1e/64 scope link

此时发现即使主库的服务恢复正常也不会主动抢占从库的VIP,因为两边设置的都是backup模式,但此时如果备库的服务、实例等原因导致需要切换VIP而此时主库由具备切换的条件,那么依旧可以完成切换(此时切记一旦完成主备切换后,需要手动恢复新的主备状态保障数据一致性后才能进行二次切换)

7、模拟备库数据延迟120S以上切换

从库先停止io_thread

(root:localhost:Sun May 20 10:24:45 2018)[(none)]>stop slave io_thread;
Query OK, 0 rows affected (0.00 sec)

主库做大量的数据变更操作

然后监控从库keepalived状态即可

8、模拟备库数据同步错误切换

从库状态:

[root@node2 keepalived]# mysql -uroot -e "show slave status \G"|egrep  "Slave.*Running|Seconds_Behind_Master|Last_Errno"|grep -v "Slave_SQL_Running_State"
            Slave_IO_Running: Yes
            Slave_SQL_Running: No
                  Last_Errno: 1050
        Seconds_Behind_Master: NULL
[root@node2 keepalived]# service keepalived status
keepalived is stopped
[root@node2 keepalived]# ip add |grep inet
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
    inet 192.168.1.24/24 brd 192.168.1.255 scope global eth1
    inet6 fe80::250:56ff:fe8d:3d1e/64 scope link

主库状态:

[root@node1 keepalived]# service mysqld status
MySQL (Percona Server) running (1141)                      [  OK  ]
[root@node1 keepalived]# service keepalived  status     
keepalived (pid  1230) is running...
[root@node1 keepalived]# ip add |grep inet
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
    inet 192.168.1.23/24 brd 192.168.1.255 scope global eth1
    inet 192.168.1.27/32 scope global eth1:1
    inet6 fe80::250:56ff:fe8d:496/64 scope link

此时如果主库相关服务宕机,是无法完成VIP切换,通过关闭mysqld服务测试

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/a110e7963ffde840823e5a868ac7f306.html