Hi,
Setup
I am having two servers running locally, and I have Consul running DNS on 127.0.0.1:8600
:
$ dig +short @127.0.0.1 -p 8600 -t srv _whoami-whoami-whoami._tcp.service.consul
1 1 25654 Kaspers-MBP.lan.node.dc1.consul.
1 1 21387 Kaspers-MBP.lan.node.dc1.consul.
This means that the service is running on port 21387
and 25654
, if I visit them I see the following:
$ curl http://localhost:21387/
I’m 8235fc9759d6 running on linux/amd64
and:
$ curl http://localhost:25654/
I’m 0d3dc4abb184 running on linux/amd6
I then setup Haproxy to switch between them like this:
global
maxconn 5000
pidfile /usr/lib/haproxy/haproxy.pid
stats socket /home/kasper/haproxy.sock
defaults
timeout connect 5000
timeout client 50000
timeout server 50000
log global
listen stats
bind 0.0.0.0:8999
mode http
stats enable
stats uri /dashboard # Stats URI
stats admin if { src 127.0.0.1 }
resolvers consuldns
nameserver consul 127.0.0.1:8600
accepted_payload_size 8192
listen whoami
bind *:8022
mode http
option httpchk GET / HTTP/1.0
balance roundrobin
server-template srv 2 _whoami-whoami-whoami._tcp.service.consul resolvers consuldns check resolve-opts allow-dup-ip
And when I boot Haproxy it writes the following:
[WARNING] 140/150710 (38827) : Server whoami/srv1 is DOWN, reason: Socket error, check duration: 0ms. 1 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
[WARNING] 140/150711 (38827) : Server whoami/srv2 is DOWN, reason: Socket error, check duration: 0ms. 0 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
[ALERT] 140/150711 (38827) : proxy ‘whoami’ has no server available!
[WARNING] 140/150711 (38827) : whoami/srv1 changed its IP from to 127.0.0.1 by consuldns/consul.
[WARNING] 140/150711 (38827) : whoami/srv2 changed its IP from to 127.0.0.1 by DNS cache.
[WARNING] 140/150714 (38827) : Server whoami/srv1 is UP, reason: Layer7 check passed, code: 200, info: “OK”, check duration: 2ms. 1 active and 0 backup servers online. 0 sessions requeued, 0 total in queue.
[WARNING] 140/150715 (38827) : Server whoami/srv2 is UP, reason: Layer7 check passed, code: 200, info: “OK”, check duration: 3ms. 2 active and 0 backup servers online. 0 sessions requeued, 0 total in queue.
When I use show servers state
the server show up correctly, with the correct ports:
# be_id be_name srv_id srv_name srv_addr srv_op_state srv_admin_state srv_uweight srv_iweight srv_time_since_last_change srv_check_status srv_check_result srv_check_health srv_check_state srv_agent_state bk_f_forced_id srv_f_forced_id srv_fqdn srv_port srvrecord
3 whoami 1 srv1 127.0.0.1 2 0 1 1 153 15 3 4 6 0 0 0 Kaspers-MBP.lan.node.dc1.consul 25654 _whoami-whoami-whoami._tcp.service.consul
3 whoami 2 srv2 127.0.0.1 2 0 1 1 152 15 3 4 6 0 0 0 Kaspers-MBP.lan.node.dc1.consul 21387 _whoami-whoami-whoami._tcp.service.consul
Issue
However when I visit the service that I setup with Haproxy by going to http://localhost:8022, it doesn’t seem to loadbalance between the different servers because only one of the the names shows up:
Am I missing something?