0

我正在使用以下 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"
}

广播地址看起来像容器的名称/主机名。我试图在端口 4151 上 ping 以防万一,但它失败了。

> 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 吗?

4

1 回答 1

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 地址。这对我们有用。今天才设法让它工作

于 2017-01-27T16:27:40.150 回答