0

First of all my experience with HAProxy stack is just one day old so I hope my question makes sense.

I have 2 HAProxy VMs and 2 Apache VMs (vagrant machines) as follows.

192.168.50.11 HAPROXY VM1
192.168.50.12 HAPROXY VM2
192.168.50.21 APACHE VM1
192.168.50.22 APACHE VM2

192.168.50.10 FLOATING IP - set in keepalived of both HAProxy servers above

If I bring one of the Apache servers down and call http://192.168.50.10 system still works which is fine. However, if I bring one of the HAProxy servers down, whole service is down. Based on my configurations below, could you please tell me what I'm missing here?

HAPROXY SETTINGS ON BOTH SERVERS

/etc/default/haproxy

ENABLED=1

/etc/haproxy/haproxy.cfg

global
    log /dev/log local0
    log 127.0.0.1 local1 notice
    user haproxy
    group haproxy
    maxconn 2000
    daemon

defaults
    log global
    mode http
    option httplog
    option dontlognull
    retries 3
    option redispatch
    timeout connect 5000
    timeout client 50000
    timeout server 50000

listen webservers 192.168.50.10:80
    balance roundrobin
    stats enable
    stats auth admin:admin
    stats uri /haproxy?stats
    option httpchk
    option forwardfor
    option http-server-close
    server webserver1 192.168.50.21:80 check
    server webserver2 192.168.50.22:80 check

KEEPALIVED SETTINGS ON BOTH SERVERS

/etc/sysctl.conf

net.ipv4.ip_nonlocal_bind=1

etc/keepalived/keepalived.conf

vrrp_script chk_haproxy {
    script "killall -0 haproxy"
    #Ping every 2 seconds
    interval 2
    weight 2
}

vrrp_instance VI_1 {
    interface eth0
    state MASTER
    virtual_router_id 51
    priority 11
    virtual_ipaddress {
        192.168.50.10
    }
    track_script {
        chk_haproxy
    }
}

Note: Only priority is VM dependent so it is priority 11 for 192.168.50.11 HAPROXY VM1 machine and priority 12 for 192.168.50.12 HAPROXY VM2 machine.

I created this example after reading the blog posts below.

gxx
  • 5,591
  • 2
  • 22
  • 42
BentCoder
  • 331
  • 6
  • 21

1 Answers1

2

As I thought, small mistakes were in place for keepalived config file.

state MASTER for 192.168.50.11 # This is the master HAProxy

state BACKUP for 192.168.50.12 # This is the failover HAProxy

And

priority 12 for 192.168.50.11 # the higher priority goes with the master HAProxy

priority 11 for 192.168.50.12

BentCoder
  • 331
  • 6
  • 21