HAProxy with Keepalived

Simple setup for one virtual ip 10.200.0.1 address for 2 servers running haproxy (let's say 10.200.0.2 and 10.200.0.3) then reverse proxying to 2 app servers 10.200.0.11 and 10.200.0.12

Keepalived

Same configuration for every haproxy node /etc/keepalived/keepalived.conf

vrrp_script check_haproxy {
    script "killall -0 haproxy"   # check command
    interval 1                    # check every second
    weight 2                      # add 2 points of priority if OK
}

vrrp_instance app {
    state             MASTER
    interface         eth0
    virtual_router_id 1
    priority          100
    advert_int        1
    # notify /opt/app/notify_script.sh    
    authentication {
        auth_type     PASS
        auth_pass     41.1
    }    
    virtual_ipaddress {
        10.200.0.1
    }    
    track_script {
        check_haproxy
    }    
}

HaProxy

/etc/haproxy/haproxy.cfg

global
    log         127.0.0.1 local2
    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon
    stats socket /var/lib/haproxy/stats

defaults
    log                     global
    option                  dontlognull
    option                  redispatch
    retries                 3
    timeout queue           1m
    timeout connect         3s
    timeout client          1m
    timeout server          1m
    timeout check           3s
    maxconn                 3000
    contimeout              5000
    clitimeout              50000
    srvtimeout              50000

listen  app_8080 10.200.0.10:8080
    mode http
    option httpchk GET /app/isAlive.jsp
    cookie SERVERID insert nocache
    balance roundrobin
    server app01 10.200.0.11:8080 cookie 01 id 1001 check inter 2000 rise 2 fall 5
    server app02 10.200.0.12:8080 cookie 03 id 1003 check inter 2000 rise 2 fall 5

listen status_page :9090            # haproxy status page
        mode http
        stats uri /status/          # haproxy status uri