Programmatically add nodes to a load balancer like Haproxy?
Asked Answered
A

3

13

I'm very sure this problem has been solved, but I can't find any information anywhere about it...

How do sysadmins programmatically add a new node to an existing and running load balancer ? Let's say I have a load balancer running and already balancing say my API server between two EC2 instances, and suddenly there's a traffic spike and I need a third node in the load balancer but I'm asleep... It would be wonderful if I had something monitoring probably RAM usage and some key performance indicators that tell me when I should have another node, and even better if it could add a new node to the load balancer alone...

I'm confident that this is possible and even trivial to do with node-http-proxy and distribute, but I'd like to know if this is possible to do with HAproxy and/or Nginx... I know Amazon's elastic load balancing is probably my best bet but I want to do it on my own (I want to spawn instances from rackspace, EC2, Joyent and probably others as it's convenient).

Once again, spawning a node is easy, I'd like to know how to add it to haproxy.cfg or something similar with Nginx without having to reload the whole proxy, and doing that programatically. Bash scripting is my best bet for this but it still does have to reload the whole proxy which is bad because it loses connections...

Adjudge answered 15/2, 2012 at 19:44 Comment(0)
F
8

You have a few questions in there. For the "add nodes to haproxy without restarting it":

What I do for a similar problem is prepopulate the config file with server names.. e.g. web01, web02 ... web20 even if I only have 5 web servers at the time. Then in my hosts file I map those to the actual ips of the web servers.

To add a new server, you just create an entry for it in the hosts file and it will start passing health checks and get added.

For automated orchestration, it really depends on your environment and you'll probably have to write something custom that fits your needs. There are paid solutions (Scalr comes to mind) to handle orchestration too.

Frock answered 4/3, 2012 at 22:17 Comment(1)
Have you tried this before? I attempted to do so on HAProxy 1.8 and clearly changing the hosts file modified HAProxies behaviour in no way. I even verified the server was fully accessible from the HAProxy through that change to the hosts file.Suggs
T
8

What I do: I have a line in my backend section in haproxy.cfg which says:

# new webservers here

And with a sed script I update haproxy.cfg with something like:

  sed -i -e "/new webservers here/a\    server $ip_address $ip_address:12080 check maxconn 28 weight 100"

And then reload haproxy. Works transparently.

Tod answered 13/3, 2014 at 21:42 Comment(1)
It's a recommended way to do that? Doesn't seems practical to me. Although, it works.Lavatory
A
1

HAProxy has a Runtime API that allows you to do just that dynamically.

Please read the official documentation: Dynamic Configuration HAProxy Runtime API

Ave answered 3/5, 2018 at 8:23 Comment(1)
This is the better and actual answer to the question. this should be acceptedLouiselouisette

© 2022 - 2024 — McMap. All rights reserved.