配置文件

  • 主配置文件
    
    ! Configuration File for keepalived

global_defs {
router_id gd_ha01
}

vrrp_script check_nginx {
script "pidof nginx"
interval 2
}

vrrp_instance VI_1 {
state BACKUP
interface ens160
virtual_router_id 101
priority 100
advert_int 2
nopreempt
authentication {
auth_type PASS
auth_pass 1111
}

notify_master "/application/keepalived/scripts/master.sh"
notify_backup "/application/keepalived/scripts/backup.sh"
notify_fault "/application/keepalived/scripts/fault.sh"

track_script {
    check_nginx
}

virtual_ipaddress {
    192.168.0.93
}

}

- 备配置文件

! Configuration File for keepalived

global_defs {
router_id gd_ha02
}

vrrp_script check_nginx {
script "pidof nginx"
interval 2
}

vrrp_instance VI_1 {
state BACKUP
interface ens160
virtual_router_id 101
priority 80
advert_int 2
nopreempt
authentication {
auth_type PASS
auth_pass 1111
}

notify_master "/application/keepalived/scripts/master.sh"
notify_backup "/application/keepalived/scripts/backup.sh"
notify_fault "/application/keepalived/scripts/fault.sh"

track_script {
    check_nginx
}

virtual_ipaddress {
    192.168.0.93
}

}



# 原因分析
检查多次配置文件没有错,主的上面nginx杀掉后,vip漂移到备上能正常访问,主的nginx起来后,vip又飘回到主上,各种排查(设置preempt_delay、设置ip转发、了解单播/组播),各种配置文件修改,折腾一番后还是没有解决,正准备打算就这种使用抢占模式使用时,突然想起来前几天自己配置的别的keepalived,发现局域网中有virtual_router_id相同的服务器导致的不抢占模式失效。