让 EC2 实例自动加入 HAProxy 的最佳实践是什么?

发布于 11-19 02:14 字数 483 浏览 3 评论 0原文

我们正在努力扩展我们的 EC2 架构,以达到我们想要管理我们自己的负载平衡的程度。目前,我们在 HAProxy 上配置了一系列机器来执行基本的负载平衡,但我们正在寻找“最佳实践”,即让新实例上线并自动(或几乎自动)加入 HAProxy。

理想情况下,我们会监控系统上的负载,或者依靠几年的分析数据来制定一个粗略的时间表,当我们达到阈值或预定时间时,让一个进程启动一个新实例,让这个新节点连接到我们的 HAProxy 机器上的系统,将其主机名写入配置并重新加载 HAProxy,使其成为池的一部分。

一旦我们发展到需要多个区域覆盖的程度,我们就会考虑使用 Amazon ELB,但在那之前,我们需要一个简单的设置来从 HAProxy 添加/删除机器。

我知道我们可以付费来管理这些东西,但 Scalr 似乎将我们限制在非常特定的实例类型,而 Rightscale 太贵了,所以像许多其他人一样,我们正在寻求推出自己的解决方案。

不幸的是,那些推出自己的解决方案的人似乎对他们的过程有点保密。

We're working on scaling out our EC2 architecture to a point where we'd like to manage our own load balancing. We currently have a series of machines configured on HAProxy to do basic load balancing, but we're looking for the 'best practice' means to have a new instance come online and automatically (or nearly automatically) join HAProxy.

Ideally, we'd monitor load on our systems or rely on a few years worth of analytics data to work out a rouch schedule, and when we reach a threshold or scheduled time, have a process fire up a new instance, have that new node connect to a system on our HAProxy machine to write its hostname into the config and reload HAProxy so it becomes part of the pool.

We're considering Amazon's ELB once we grow big enough to need multiple zone coverage, but until then, we need a simple setup that can add/remove machines from HAProxy.

I know there are services out there that we can pay to manage this stuff, but Scalr seems to limit us to very specific instance types, and Rightscale is too expensive, so like many others, we're looking to roll our own solution.

Unfortunately, those who roll their own solution seem to be a little hush-hush on their process.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

琴流音2024-11-26 02:14:50

您不需要过度考虑这个解决方案;)

您可以简单地在 HAProxy 配置文件中“预配置”服务器。它们将显示为“已关闭”并且永远不会收到请求,直到您真正将它们上线为止。

下面是一个示例,假设您只有 5 台在线机器,并预计在未来 2 年内拥有 10 台机器:

listen web *:80
    balance source
    server  web1 192.168.0.101:80 check inter 2000 fall 3
    server  web2 192.168.0.102:80 check inter 2000 fall 3
    server  web3 192.168.0.103:80 check inter 2000 fall 3
    server  web4 192.168.0.104:80 check inter 2000 fall 3
    server  web5 192.168.0.105:80 check inter 2000 fall 3
    server  web6 192.168.0.106:80 check inter 2000 fall 3
    server  web7 192.168.0.107:80 check inter 2000 fall 3
    server  web8 192.168.0.108:80 check inter 2000 fall 3
    server  web9 192.168.0.109:80 check inter 2000 fall 3
    server  web10 192.168.0.110:80 check inter 2000 fall 3

使用此配置,您至少一年内不需要重新启动 HAProxy 或进行任何丑陋的黑客攻击(除非您需要超过 10 个,然后只需添加 100 个即可设置)。

您还可以编写一个快速 shell 脚本来自动生成此配置,实际上,如果您要向池中添加 100 台服务器,您应该为此编写一个脚本。

You don't need to over-think this solution ;)

You can simply "pre-configure" servers in your HAProxy configuration file. They will appear "down" and will never receive requests until you actually bring them online.

Here's an example, assuming you only have 5 machines online, and expect to have 10 in the next 2 years:

listen web *:80
    balance source
    server  web1 192.168.0.101:80 check inter 2000 fall 3
    server  web2 192.168.0.102:80 check inter 2000 fall 3
    server  web3 192.168.0.103:80 check inter 2000 fall 3
    server  web4 192.168.0.104:80 check inter 2000 fall 3
    server  web5 192.168.0.105:80 check inter 2000 fall 3
    server  web6 192.168.0.106:80 check inter 2000 fall 3
    server  web7 192.168.0.107:80 check inter 2000 fall 3
    server  web8 192.168.0.108:80 check inter 2000 fall 3
    server  web9 192.168.0.109:80 check inter 2000 fall 3
    server  web10 192.168.0.110:80 check inter 2000 fall 3

With this config, you won't need to restart HAProxy or do any kind of ugly hacks for at least a year (unless you need more than 10, then just add 100 and you'll be set).

You can also write a quick shell script to automatically generate this configuration, actually you SHOULD write a script for that if you're adding 100 servers to your pool.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文