DEV Community

loading...
Cover image for HAProxy With Resolvers In Case Of AWS Application LoadBalancer

HAProxy With Resolvers In Case Of AWS Application LoadBalancer

Vu Dao
Awesome Devops || AWS SA || CloudOpz
Updated on ・2 min read
  • HAProxy allows using a host name on the server line to retrieve its IP address using name servers.

  • By default, HAProxy resolves the name when parsing the
    configuration file, at startup and cache the result for the process' life.

  • This is not sufficient in some cases, such as in Amazon where a server's IP can change after a reboot or an ELB Virtual IP can change based on current workload.

  • This article describes how to user resolvers to process server's name resolution at run time.

Alt Text
1. Update haproxy.cfg

global
    log         127.0.0.1 local2

    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4096
    user        haproxy
    group       haproxy
    daemon
    stats socket /var/lib/haproxy/stats
    stats maxconn 1
    stats timeout 120s

resolvers awsvpc
    nameserver vpc 169.254.169.253:53

defaults
    mode        tcp
    log         global
    retries     3
    timeout     connect 10s
    timeout     client 1m
    timeout     server 1m
    timeout     check 10s
    maxconn     512

backend myweb
    server disabled-server 127.0.0.1:1 disabled
    server mydns XXXXXXXXXXXX.ap-northeast-1.rds.amazonaws.com:80 check port 80 resolvers awsvpc inter 2000 fall 5
Enter fullscreen mode Exit fullscreen mode

Note: nameserver vpc 169.254.169.253:53 is the DNS server/ resolver to be used

2. Restart haproxy service

systemctl restart haproxy
Enter fullscreen mode Exit fullscreen mode

3. Check result

~:# netstat -plunt |grep 53
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      10616/systemd-resol 
udp        0      0 127.0.0.53:53           0.0.0.0:*                           10616/systemd-resol 
Enter fullscreen mode Exit fullscreen mode

More about haproxy

Discussion (0)

Forem Open with the Forem app