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

Do your career a favor. Join DEV. (The website you're on right now)

It takes one minute and it's free.

Get started

Top comments (0)

Billboard image

Try REST API Generation for MS SQL Server.

DevOps for Private APIs. With DreamFactory API Generation, you get:

  • Auto-generated live APIs mapped from database schema
  • Interactive Swagger API documentation
  • Scripting engine to customize your API
  • Built-in role-based access control

Learn more

πŸ‘‹ Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay