keepalived非抢占模式配置及关闭网卡无法实现切换vip的问题

keepalived非抢占模式,大致有三个地方需要配置

1,state BACKUP

2,主备的priority 的值不同

3,nopreempt

我的配置,分别在两台机器上配置

主机1:172.26.0.66

主机2:172.26.0.111

VIP:172.26.0.109

 

主机1的keepalived.conf配置

! Configuration File for keepalived

global_defs {
   notification_email {
     [email protected]
     [email protected]
     [email protected]
   }
   notification_email_from [email protected]
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
   vrrp_skip_check_adv_addr
   #vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}

#vrrp_script check_run {
#    script "/usr/cloudland/keepalived/keepalived_check.sh"
#     script "/usr/cloudland/keepalived/sync_data.sh"
#     interval 3
#}

vrrp_instance VI_1 {
    state BACKUP
    interface ens192
    virtual_router_id 109
    priority 100
    nopreempt
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }

    virtual_ipaddress {
           172.26.0.109/24 dev ens192
    }

#track_script {
#    check_run
# }
    notify_master "/usr/cloudland/keepalived/update_companyId.sh"
    notify_backup "/usr/cloudland/keepalived/master_backup.sh backup"
}

virtual_server 172.26.0.109 3306 {
    delay_loop 6
    lb_algo wrr
    lb_kind Dr
    persistence_timeout 60
    protocol UDP

    real_server 172.26.0.66 3306 {
        weight 3
        #notify_down /root/shutdown.sh
        UDP_CHECK {
            connect_timeout 10
            nb_get_retry 3
            delay_before_retry 3
            connect_port 3306
        }
    }
}

 

主机2的keepalived配置

! Configuration File for keepalived

global_defs {
   notification_email {
     [email protected]
     [email protected]
     [email protected]
   }
   notification_email_from [email protected]
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
   vrrp_skip_check_adv_addr
   #vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}

#vrrp_script check_run {
#    script "/usr/cloudland/keepalived/keepalived_check.sh"
#     script "/usr/cloudland/keepalived/sync_data.sh"
#     interval 3
#}

vrrp_instance VI_1 {
    state BACKUP
    interface ens192
    virtual_router_id 109
    priority 90
    nopreempt
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }

    virtual_ipaddress {
           172.26.0.109/24 dev ens192
    }

#track_script {
#    check_run
# }
    notify_master "/usr/cloudland/keepalived/update_companyId.sh"
    notify_backup "/usr/cloudland/keepalived/master_backup.sh backup"
}

virtual_server 172.26.0.109 3306 {
    delay_loop 6
    lb_algo wrr
    lb_kind Dr
    persistence_timeout 60
    protocol TCP

    real_server 172.26.0.111 3306 {
        weight 3
        #notify_down /root/shutdown.sh
        TCP_CHECK {
            bindto 172.26.0.66
            connect_timeout 10
            nb_get_retry 3
            delay_before_retry 3
            connect_port 3306
        }
    }
}

配置好之后,实际测试的时候发现,通过断网线和kill掉keepalived服务,都可以实现切换,但是通过systemctl stop network就无法实现vip漂移

通过systemctl stop network停用网络服务是不能转移的,尽管这时候你ping不通,你会发现在keepalived的服务还在,拔掉网线或者systemctl stop keepalived
都可以转移,但是不能通过system stop network使VIP漂移,具体原理,应该是systemctl stop network只是停用了上层的网络服务吧,但是底层物理连接
还可以连接吧,而vrrp协议正是基于这种物理的真实连接,所以keepalived应该不能监测网卡故障,你可以写一个监控脚本,一定时间内,ping不通对端的IP,就
把自己的keepalived杀死

你可能感兴趣的:(nginx,centos,服务器,负载均衡,运维)