![防止 master 发生故障后回退到 master](https://linux22.com/image/586716/%E9%98%B2%E6%AD%A2%20master%20%E5%8F%91%E7%94%9F%E6%95%85%E9%9A%9C%E5%90%8E%E5%9B%9E%E9%80%80%E5%88%B0%20master.png)
我正在使用 keepalived 设置指向主服务器的虚拟 IP。发生故障转移时,它应该将虚拟 IP 指向备份服务器,并且该 IP 应该一直保留在那里,直到我手动启用(修复)主服务器。
这很重要,因为我在服务器上运行 mysql 复制,并且写入只能在主服务器上进行。当我进行故障转移时,我会将从服务器提升为主服务器。
主服务器:
global_defs {
! this is who emails will go to on alerts
notification_email {
[email protected]
! add a few more email addresses here if you would like
}
notification_email_from [email protected]
! I use the local machine to relay mail
smtp_server 127.0.0.1
smtp_connect_timeout 30
! each load balancer should have a different ID
! this will be used in SMTP alerts, so you should make
! each router easily identifiable
lvs_id APP1
}
vrrp_instance APP1 {
interface eth0
state EQUAL
virtual_router_id 61
priority 999
nopreempt
virtual_ipaddress {
217.x.x.129
}
smtp_alert
}
备份服务器:
global_defs {
! this is who emails will go to on alerts
notification_email {
[email protected]
! add a few more email addresses here if you would like
}
notification_email_from [email protected]
! I use the local machine to relay mail
smtp_server 127.0.0.1
smtp_connect_timeout 30
! each load balancer should have a different ID
! this will be used in SMTP alerts, so you should make
! each router easily identifiable
lvs_id APP2
}
vrrp_instance APP2 {
interface eth0
state EQUAL
virtual_router_id 61
priority 100
virtual_ipaddress {
217.xx.xx.129
}
notify_master "/etc/keepalived/notify.sh del app2"
notify_backup "/etc/keepalived/notify.sh add app2"
notify_fault "/etc/keepalived/notify.sh add app2”
smtp_alert
}
答案1
我遇到了和你一样的问题。通过设置解决了不抢占在两个 keepalived 服务器上,并且(根据http://article.gmane.org/gmane.linux.keepalived.devel/1537)将两个服务器都设置为备份(具有不同的优先级)。
效果很好!:-)
答案2
这可能不是最优雅的解决方案,但您不能在主服务器上的脚本中停止 keepalived 吗notify_backup
?notify_fault
这样,您必须重新启动它才能再次获得控制权。
类似这样的:
notify_backup "/etc/init.d/keepalived stop"
notify_fault "/etc/init.d/keepalived stop"