Skip to content

keepalived

yum install -y keepalived

主 Nginx

vi /ect/keepalived/keepalived.conf

nginx
! Configuration File for keepalived

global_defs {
   router_id lb111
}

vrrp_instance VI_1 {
    state MASTER
    # 网卡名称
    interface ens33
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    # 虚拟的 IP
    virtual_ipaddress {
        192.168.44.200
    }
}

systemctl start keepalived

备 nginx

vi /ect/keepalived/keepalived.conf

nginx
! Configuration File for keepalived

global_defs {
   router_id lb110
}

vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 51
    priority 50
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.44.200
    }
}

systemctl start keepalived

此时备用 nginx 没有虚拟 ip,cmd 中 ping 192.168.44.200 -t,主 nginx 通过 init 0 关机,看超时一次后能否马上又 ping 通。