我非常确定这个问题已经解决,但我在任何地方都找不到有关它的任何信息...
系统管理员如何以编程方式将新节点添加到现有且正在运行的负载均衡器?假设我有一个正在运行的负载均衡器,并且已经在两个 EC2 实例之间平衡我的 API 服务器,突然流量激增,我需要负载均衡器中的第三个节点,但我睡着了......如果我有一些东西可以监控 RAM 使用情况和一些关键性能指标,告诉我何时应该有另一个节点,如果它可以单独向负载均衡器添加一个新节点就更好了……
我相信这是可能的,甚至是微不足道的与node-http-proxy 和 分发,但我想知道这是否可以与 HAproxy 和/或 Nginx 相关...我知道亚马逊的弹性负载平衡可能是我最好的选择,但我想自己做(我想从机架空间、EC2、Joyent 以及其他可能的空间生成实例,因为这样很方便)。
再说一遍,生成节点很容易,我想知道如何将其添加到 haproxy.cfg 或与 Nginx 类似的东西,而无需重新加载整个代理,并以编程方式执行此操作。 Bash 脚本是我最好的选择,但它仍然必须重新加载整个代理,这很糟糕,因为它失去了连接......
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...
发布评论
评论(3)
我所做的:我在 haproxy.cfg 的后端部分有一行内容:
使用 sed 脚本,我用以下内容更新 haproxy.cfg:
然后重新加载 haproxy。工作透明。
What I do: I have a line in my backend section in haproxy.cfg which says:
And with a sed script I update haproxy.cfg with something like:
And then reload haproxy. Works transparently.
HAProxy 有一个运行时 API,允许您动态地执行此操作。
请阅读官方文档:
动态配置 HAProxy 运行时 API
HAProxy has a Runtime API that allows you to do just that dynamically.
Please read the official documentation:
Dynamic Configuration HAProxy Runtime API
你有几个问题。对于“将节点添加到 haproxy 而不重新启动它”:
我对类似问题所做的就是用服务器名称预先填充配置文件.. 例如 web01、web02 ... web20 即使我当时只有 5 个 Web 服务器。然后在我的主机文件中,我将它们映射到 Web 服务器的实际 ip。
要添加新服务器,您只需在主机文件中为其创建一个条目,它将开始通过运行状况检查并被添加。
对于自动化编排,它实际上取决于您的环境,您可能必须编写一些适合您需求的自定义内容。也有付费解决方案(我想到了 Scalr)来处理编排。
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.