Keepalived简单安装测试

首先准备俩台服务器

每台服务器上都安装Keepalived (yum安装)

yum -y install keepalived

 修改Keepalived配置文件

vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   router_id NGINX_A
}

vrrp_instance VI_1 {
    state MASTER
    interface ens33  #实例绑定的网卡ens33
    virtual_router_id 51
    priority 100  #权重100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.0.0.100  #vip
    }
}

virtual_server 10.0.0.100 80 {
    delay_loop 6
    lb_algo rr
    lb_kind NAT
    protocol TCP

    real_server 10.0.0.42 80 {  #本机IP
        weight 1
        notify_down /etc/keepalived/bb.sh #当80端口关闭执行脚本
        TCP_CHECK {
            connect_timeout 3    #连接超时时间3秒
            nb_get_retry 3  #重连次数3次
            delay_before_retry 3  #重连间隔3秒
            connect_port 80  #监听80端口
        }
    }
}

启动Keepalive

systemctl start keepalived

 查看IP是否存在VIP

ip a

 配置第二台服务器的Keepalived

vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   router_id NGINX_B
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens33  #实例绑定的网卡ens33
    virtual_router_id 51
    priority 99 #权重99
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.0.0.100  #vip
    }
}

virtual_server 10.0.0.100 80 {
    delay_loop 6
    lb_algo rr
    lb_kind NAT
    protocol TCP

    real_server 10.0.0.43 80 {  #本机IP
        weight 1
        notify_down /etc/keepalived/bb.sh #当80端口关闭执行脚本
        TCP_CHECK {
            connect_timeout 3  #连接超时时间3秒
            nb_get_retry 3   #重连次数3次
            delay_before_retry 3  #重连间隔3秒
            connect_port 80  #监听80端口
        }
    }
}

 关闭第一台服务器测试VIP是否跳转

systemctl stop keepalived

 

第二台查看IP VIP跳转成功

ip a

posted @ 2020-01-09 09:36  似乎还很年轻。  阅读(674)  评论(0)    收藏  举报