3、在备机操作keepalived
上master的基本一样,只是几个地方修改下而已
global_defs {
notification_email {
coffee_lanshan@sina.com
}
notification_email_from admin@example.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id MySQL_ha
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 90
advert_int 1
nopreempt
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
192.168.135.200
}
}
virtual_server 192.168.135.200 3306 {
delay_loop 2
lb_algo wrr
lb_kind DR
persistence_timeout 10
protocol TCP
real_server 192.168.135.135 3306 {
weight 3
notify_down /usr/local/Mysql/bin/mysql.sh
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
}
找一台机器进行测试
ping 192.168.135.200(vip)
正常,当把master上mysqld杀掉,发现keepalived进程也不见了,说明我们的脚本触发了,但是vip还是可以ping通,说明备机起作用了;
大家也可以查看vrrp协议的信息;根据优先级100或90进行判断
黑线的地方说明备机顶替了;
当把master的mysqld进程和keepalived重启后发现:
说明master又顶替了slave;进行了抢占