【问题标题】:Discovering nsqd server address from nslookupd从 nslookupd 发现 nsqd 服务器地址
【发布时间】:2017-06-09 00:00:46
【问题描述】:

我正在使用以下 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 吗?

【问题讨论】:

  • 有同样的问题。 PetSet/StatefulSet 很容易克服,但在 GKE 上尚不可用

标签: networking docker kubernetes docker-swarm nsq


【解决方案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 地址。这对我们有用。今天刚刚成功完成工作

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-25
    • 2018-03-07
    • 2018-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多