HAProxy没有正确运行nodeJS API

我在EC2中运行coreOS。 我有一个nodeJS api docker镜像,并在几个端口(25001和25002)上运行。 当我卷入他们,我看到适当的回应。

我的意图是有一个HAProxy超过这些(运行在25000),这将负载平衡这两者之间。 所以这里是我做的步骤:

DockerFile for HaProxy:

FROM haproxy:1.5 COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg 

haproxy.cfg:

 global # daemon maxconn 256 log /dev/log local0 defaults mode http log global timeout connect 5000ms timeout client 50000ms timeout server 50000ms frontend http-in bind *:25000 default_backend node_api backend node_api mode http balance roundrobin server api1 localhost:25001 server api2 localhost:25002 

结果:当我运行单个服务curl—>

 curl -i localhost:25001/ping HTTP/1.1 200 OK X-Powered-By: Express Access-Control-Allow-Origin: * Content-Type: application/json; charset=utf-8 Content-Length: 68 ETag: W/"44-351401c7" Date: Sat, 06 Jun 2015 17:22:09 GMT Connection: keep-alive {"error":0,"msg":"loc receiver is alive and ready for data capture"} 

同样适用于25002但是当我运行25000时,我得到如下的超时错误:

 curl -i localhost:25000/ping HTTP/1.0 504 Gateway Time-out Cache-Control: no-cache Connection: close Content-Type: text/html <html><body><h1>504 Gateway Time-out</h1> The server didn't respond in time. </body></html> 

我想知道我在这里做错了什么? 任何帮助,将不胜感激 …

当您告诉HAProxy后端服务器位于

 server api1 localhost:25001 

你提供了一个相对于HAProxy容器的地址。 但是你的Node服务器没有运行在这个容器上,所以localhost上没有人。

你在这里有几个select。

  • 您可以使用--link docker run--link选项将HAProxy连接到您的两个后端。
  • 您可以使用--net=host选项,然后您的服务器可以在本地主机上find彼此
  • 您可以提供HAProxy主机的地址作为后端地址

第一个选项是container-y,但Docker桥接networking的性能在高负载下很差。 第二种select是好的,只要你不介意在networking上让所有的东西突破它的容器。 第三是kludgey,但没有其他两个问题。

Docker关于networking的文章有更多的细节。