keepalived非抢占模式

一、前言

     keepalived非抢占模式,当master发生故障时,vip飘移到backup节点,但是当master恢复时,vip不会漂移回master上,只有当backup发生故障时,vip才会飘移回master节点,keepalived默认是抢占模式,需要加上nopreempt参数才能开启非抢占模式,非抢占模式需要所有节点都是backup状态,但是优先级还是有区分,而且优先级高的节点才需要配置非抢占模式,优先级低的不需要配置非抢占模式

二、配置

节点一配置

vi /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {
   script_user root
   enable_script_security
   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 nfs01
  # vrrp_skip_check_adv_addr
  # vrrp_strict
  # vrrp_garp_interval 0
  # vrrp_gna_interval 0
}

vrrp_script check_nfs {
   script "/etc/keepalived/check_nfs.sh"
   interval 3
}

vrrp_instance VI_4 {
    state BACKUP      #配置为backup
    interface ens192
    virtual_router_id 53
    priority 90
    advert_int 1
    nopreempt     #非抢占模式
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.1.60.6
    }
    track_script {
       check_nfs
    }
}

节点二配置

vi /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {
   script_user root
   enable_script_security
   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 nfs02
  # vrrp_skip_check_adv_addr
  # vrrp_strict
  # vrrp_garp_interval 0
  # vrrp_gna_interval 0
}

vrrp_script check_nfs {
   script "/etc/keepalived/check_nfs.sh"
   interval 3
}

vrrp_instance VI_4 {
    state BACKUP      #配置为backup
    interface ens192
    virtual_router_id 53
    priority 80      #配置的权重比节点一低,不需要配置非抢占模式
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.1.60.6
    }
    track_script {
       check_nfs
    }
}

配置完成后启动两个节点的keepalived服务

systemctl start keepalived && systemctl enable keepalived

通过启动keepalived和关闭keepalived的方式测试vip是否会发生抢占

你可能感兴趣的:(keepalived,运维)