从nslookupd发现nsqd服务器地址
我使用以下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服务器,以便客户端可以dynamic获取响应服务器的列表。
当nsqd节点在Docker容器中运行时,是否可以从nslookupd服务器为nsqd节点提供可访问的URL / IP地址?
是否有一些魔术咒语使其工作?
有人尝试使用Swarm或Kubernetes?
我发现GKE现在支持1.5.2的StatefulSet,这意味着你的nsqd,nsqlookupd可以旋转为SS实例。 现在你可以使用-broadcast-address = $ POD_IP从api下来,你的生产者将能够发布到nsq-0.nsq-service-name,nsq-1.nsq-service-name等等,而消费者将被广告nsqd来自nsqlookupd的IP地址。 这对我们很有用。 只是设法使它今天工作