美文网首页
haproxy+keepalive

haproxy+keepalive

作者: epime | 来源:发表于2016-10-21 10:07 被阅读0次

    两个节点安装keepalived

    yum install keepalived haproxy -y
    

    修改keepalived配置文件

    ! Configuration File for keepalived
    
    global_defs {
       notification_email {
         acassen@firewall.loc
         failover@firewall.loc
         sysadmin@firewall.loc
       }
       notification_email_from Alexandre.Cassen@firewall.loc
       smtp_server 192.168.200.1
       smtp_connect_timeout 30
       router_id LVS_DEVEL
    }
    vrrp_script chk_http_port {
        script "/var/mxscripts/check_haproxy.sh"
        interval 2
        weight 2
    }
    
    vrrp_instance VI_1 {
        state MASTER
        interface ens160
        virtual_router_id 51
        priority 120
        advert_int 1
        authentication {
            auth_type PASS
            auth_pass 1111
        }
        track_script {
        chk_http_port
    }
        virtual_ipaddress {
        10.0.10.99
    }
    }
    

    check_haproxy.sh脚本

    if [ $(systemctl status haproxy|grep active|grep running|wc -l) -eq 0 ];then
        systemctl start haproxy
    fi
    sleep 2
    if [ $(systemctl status haproxy|grep active|grep running|wc -l) -eq 0 ];then
        systemctl stop keepalived
    fi
    

    从节点master改成backup
    优先级调第一点
    其余一致

    修改内核选项,

    否则备份节点无VIP则haproxy绑定失败无法启动

    net.ipv4.ip_nonlocal_bind = 1
    

    两个节点启动服务

    systemctl start keepalived
    systemctl enable keepalived
    

    相关文章

      网友评论

          本文标题:haproxy+keepalive

          本文链接:https://www.haomeiwen.com/subject/rxafuttx.html