DEV Community

Cover image for HAProxy With Resolvers In Case Of AWS Application LoadBalancer
πŸš€ Vu Dao πŸš€
πŸš€ Vu Dao πŸš€

Posted on β€’ Edited on

6 2

HAProxy With Resolvers In Case Of AWS Application LoadBalancer

  • 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

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more