我正在使用以下docker-compose.yaml文件在Docker容器中运行nsq群集:
version: '2'
services:
nsqlookupd:
image: nsqio/nsq
command: /nsqlookupd
ports:
- "4160"
- "4161:4161"
nsqd:
image: nsqio/nsq
command: /nsqd --lookupd-tcp-address=nsqlookupd:4160 --data-path=/data
volumes:
- data:/data
ports:
- "4150:4150"
- "4151:4151"
nsqadmin:
image: nsqio/nsq
command: /nsqadmin --lookupd-http-address=nsqlookupd:4161
ports:
- "4171:4171"
volumes:
data:
一切都运行良好。但是,如果我在nsqdlookup服务器上调用/ nodes端点,我得到这个:
$ http http://localhost:4161/nodes
HTTP/1.1 200 OK
Content-Length: 238
Content-Type: application/json; charset=utf-8
Date: Tue, 24 Jan 2017 08:44:27 GMT
{
"data": {
"producers": [
{
"broadcast_address": "7dd3d550e7f8",
"hostname": "7dd3d550e7f8",
"http_port": 4151,
"remote_address": "172.18.0.4:57156",
"tcp_port": 4150,
"tombstones": [],
"topics": [],
"version": "0.3.8"
}
]
},
"status_code": 200,
"status_txt": "OK"
}
广播地址看起来像容器的名称/主机名。我尝试ping端口4151以防万一,但它失败了。
> http http://7dd3d550e7f8:4151/ping
http: error: ConnectionError: HTTPConnectionPool(host='7dd3d550e7f8', port=4151): Max retries exceeded with url: /ping (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x000001C397173EF0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed',)) while doing GET request to URL: http://7dd3d550e7f8:4151/ping
远程地址相同:
> http http://172.18.0.4:4151/ping
http: error: ConnectionError: HTTPConnectionPool(host='172.18.0.4', port=4151): Max retries exceeded with url: /ping (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x000001C0D9545F28>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond',)) while doing GET request to URL: http://172.18.0.4:4151/ping
如果我使用localhost或127.0.0.1:
,一切正常> http http://localhost:4151/ping
HTTP/1.1 200 OK
Content-Length: 2
Content-Type: text/plain; charset=utf-8
Date: Tue, 24 Jan 2017 08:51:30 GMT
OK
但是,这是作弊。 nsqlookupd服务器的重点是它们跟踪nsqd服务器,以便客户端可以动态获取响应服务器列表。
当nsqd节点在Docker容器中运行时,是否可以从nslookupd服务器获取nsqd节点的可访问URL / IP地址?
是否有一些神奇的咒语让它发挥作用?
有人试过使用Swarm或Kubernetes吗?
答案 0 :(得分:1)
我发现GKE现在支持1.5.2的StatefulSet 这意味着您的nsqd,nsqlookupd可以作为SS实例旋转。现在你可以从向下的api使用-broadcast-address = $ POD_IP,你的生产者将能够发布到nsq-0.nsq-service-name,nsq-1.nsq-service-name等,而消费者将得到广告来自nsqlookupd的nsqd IP地址。这对我们有用。只是设法让它今天工作