NSQ Docker Swarm

时间:2016-12-09 16:24:41

标签: docker nsq swarm

我正在尝试在Docker Swarm中使用NSQ而没有成功

mhlg / rpi-nsq是为Raspberry Pi ARM7主板构建的Docker镜像,如果作为普通的Docker容器运行,我可以确认它是否正常工作

在Docker中运行NSQ(确定)

# crete a bridged network
$ docker network create nsq_network

# run lookupd
$ docker run --name nsqlookupd --network nsq_network -p 4160:4160 -p 4161:4161 mhlg/rpi-nsq nsqlookupd

# run nsqd
$ docker run --name nsqd --network nsq_network -p 4150:4150 -p 4151:4151 mhlg/rpi-nsq nsqd --broadcast-address=nsqd --lookupd-tcp-address=nsqlookupd:4160

# run nsqadmin
$ docker run --name nsqadmin --network nsq_network -p 4171:4171  mhlg/rpi-nsq nsqadmin --lookupd-http-address=nsqlookupd:4161

在Docker Swarm模式下运行NSQ(FAIL) 这就是我在swarm管理器中所做的事情

# crete an overlay network
$ docker network create nsq_network

# run nsqlookupd
$ docker service create --replicas 1 --name nsqlookupd --network nsq_network -p 4160:4160 -p 4161:4161 mhlg/rpi-nsq nsqlookupd

# run nsqd
$ docker service create --replicas 1 --name nsqd --network nsq_network -p 4150:4150 -p 4151:4151 mhlg/rpi-nsq nsqd --lookupd-tcp-address=nsqlookupd:4160 --broadcast-address=nsqd

# run nsqadmin
$ docker service create --replicas 1 --name nsqadmin --network nsq_network -p 4171:4171  mhlg/rpi-nsq nsqadmin --lookupd-http-address=nsqlookupd:4161

如果我连接到nsqd服务,我可以看到它无法连接到nsqlookupd服务。

[nsqd] 2016/12/09 16:51:56.851953 LOOKUPD(nsqlookupd:4160): sending heartbeat
[nsqd] 2016/12/09 16:51:56.852049 LOOKUP connecting to nsqlookupd:4160
[nsqd] 2016/12/09 16:51:57.852457 LOOKUPD(nsqlookupd:4160): ERROR PING - dial tcp: i/o timeout

看起来覆盖网络会产生一些问题(多播?)但我无法弄清楚如何解决它,特别是在ARM设备上。

我试图将ssh插入运行nsqd服务的Docker主机并从nsqd容器内部执行一些dns命令

# resolve google.com (OK)
root@3206d1c3cd3d:/# nslookup google.com
Server:     127.0.0.11
Address:    127.0.0.11#53

Non-authoritative answer:
Name:   google.com
Address: 216.58.214.78

# resolve nsqd service (OK) - can resolve the container I'm executing the command from
root@e1f6430acd1c:/# nslookup nsqd
Server:     127.0.0.11
Address:    127.0.0.11#53

Non-authoritative answer:
Name:   nsqd
Address: 10.0.0.2

# resolve nsqlookupd service (FAIL)
root@e1f6430acd1c:/# nslookup nsqlookupd
;; connection timed out; no servers could be reached

2 个答案:

答案 0 :(得分:0)

您指出:

# crete an overlay network
$ docker network create nsq_network

但是,这不会创建覆盖网络,而是创建桥接网络。 考虑运行:

docker network create --driver overlay nsq_network

答案 1 :(得分:0)

在docker swarm中遇到了同样的问题。这是我解决的方法:

docker service create \
--mode global \
--name swarm-master-nsq_nsqlookupd \
--constraint node.role==manager \
--hostname nsqlookupd \
--network name=swarm-master-nsq_nsq,alias=nsqlookupd \
nsqio/nsq:latest /nsqlookupd


docker service create \
--replicas 3 \
--name swarm-master-nsq_nsqd \
--constraint node.role==manager \
--hostname nsqd \
--network name=swarm-master-nsq_nsq,alias=nsqd \
nsqio/nsq:latest sh -c '/nsqd --broadcast-address=$(hostname -i) --lookupd-tcp-address=nsqlookupd:4160'


docker service create \
--replicas 1 \
--publish 4171:4171 \
--name swarm-master-nsq_nsqadmin \
--constraint node.role==manager \
--hostname nsqadmin \
--network name=swarm-master-nsq_nsq,alias=nsqadmin \
nsqio/nsq:latest /nsqadmin --lookupd-http-address=nsqlookupd:4161

据我所知,您的示例中有几个问题:

  1. 您没有为nsqlookupd和其他服务加上别名
  2. nsqd的广播不正确(假设您想在某个时候增加nsqd节点的数量)