共计 1682 个字符,预计需要花费 5 分钟才能阅读完成。
keepalived 做 HA 时,经常会遇到抢占式的 master 和 backup 之间的切换
example:
通常如果 master 服务死掉后 backup 会变成 master,但是当 master 服务又好了的时候 master 此时会抢占 VIP,这样就会发生两次切换对业务繁忙的网站来说是不好的。所以我们要在配置文件加入 nopreempt 非抢占,但是这个参数只能用于 state 为 backup,故我们在用 HA 的时候最好 master 和 backup 的 state 都设置成 backup 让其通过 priority 来竞争。
注意:这样配置后,我们要注意启动 keepalived 服务的顺序,假设我想让 A 成为 backup 那就不能先启动 A 的 keepalived 服务。
以下是结合 MHA 架构主、备库配置事例
主库
[root@MySQLtest ~]# more /etc/keepalived/keepalived.conf
#20140916
#!/bin/bash
global_defs {
router_id mysqlmha
}
vrrp_script check_run {
script “/etc/keepalived/check_mysql.sh”
interval 1
}
vrrp_instance VI_1 {
state BACKUP – 这里状态指定为 backup
interface eth0
virtual_router_id 151
priority 100
advert_int 1
nopreempt – 设置 nopreempt 防止抢占资源
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
check_run
}
virtual_ipaddress {
192.168.66.53
}
}
备库
[root@ceshi ~]# more /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id mysqlmha
}
vrrp_script check_run {
script “/etc/keepalived/check_mysql.sh”
interval 1
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 151
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
check_run
}
virtual_ipaddress {
192.168.66.53
}
}
CentOS 6.3 下 Haproxy+Keepalived+Apache 配置笔记 http://www.linuxidc.com/Linux/2013-06/85598.htm
Haproxy + KeepAlived 实现 WEB 群集 on CentOS 6 http://www.linuxidc.com/Linux/2012-03/55672.htm
Keepalived+Haproxy 配置高可用负载均衡 http://www.linuxidc.com/Linux/2012-03/56748.htm
Haproxy+Keepalived 构建高可用负载均衡 http://www.linuxidc.com/Linux/2012-03/55880.htm
CentOS 7 上配置 LVS + Keepalived + ipvsadm http://www.linuxidc.com/Linux/2014-11/109237.htm
Keepalived 高可用集群搭建 http://www.linuxidc.com/Linux/2014-09/106965.htm
Keepalived 的详细介绍 :请点这里
Keepalived 的下载地址 :请点这里