keepalived 配置lvs

发布于 2022-08-17  83 次阅读


keepalived 配置lvs

! Configuration File for keepalived

global_defs {
   router_id lvs-master
}

vrrp_instance VI_1 {
    state MASTER
    nopreempt
    interface em1
    # mcast src ip 发送多播包的地址,如果不设置默认使用绑定网卡的primary ip
    mcast_src_ip 10.3.131.50
    # unicast src ip 如果两节点的上联交换机禁用了组播,则只能采用vrrp单播通告的方式
    # unicast_src_ip  xx.xx.xx.xx

    # unicast_peer {

    #   xx.xx.xx.xx

    # }
    virtual_router_id 80
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.3.131.221
    }
    # 当前节点成为主节点时触发的脚本 notify_master
    notify_master "/etc/keepalived/mail.sh master"
    # 当前节点转为备节点时触发的脚本 notify_backup
    notify_backup "/etc/keepalived/mail.sh backup"
    # 当前节点转为失败状态时触发的脚本 notify_fault
    notify_fault "/etc/keepalived/mail.sh fault"
}

virtual_server 10.3.131.221 80 {
    # 健康检查时间间隔,小于6秒
    delay_loop 6
    # 轮询算法
    lb_algo rr
    # lvs 模式
    lb_kind DR
    nat_mask 255.255.255.0
    # 会话保持时间
    persistence_timeout 20
    # 使用的协议
    protocol TCP
    sorry_server 2.2.2.2 80
    real_server 10.3.131.30 80 {
        # 权重
        weight 1
        # 在服务器健康检查失效时,将其设为0,而不是直接从ipvs中删除
        inhibit_on_failure 
        #在检测到server up后执行脚本
        notify_up /etc/keepalived/start.sh start
        #在检测到server down后执行脚本
        notify_down /etc/keepalived/start.sh shutdown
        # 采用url方式检查
        HTTP_GET { 
            url {
              path /index.html
              digest 481bf8243931326614960bdc17f99b00
            }
            # 检测端口
            connect_port 80
            # 连接超时时间
            connect_timeout 3
            # 重试次数
            nb_get_retry 3
            # 重连间隔时间
            delay_before_retry 2
        }
    }

}

检查方式:
HTTP_GET URL检查
TCP_GET 端口检查