Serf 节点需要用可路由的地址“宣告”自己。在你的情况下,他们互相告诉对方:“嗨,我是本地主机:...”,所以每个人都试图回答本地主机,这是错误的,因为每个容器都有自己的本地主机。
有一个选项可以配置代理以使用eth0
ip 向网络中的其他节点通告:-iface
。然后你需要丢弃-bind
选项。这些端口是默认的,因此无需自定义。
因此,对于节点1:
serf agent -node=Node1 -iface=eth0
对于节点2:
serf agent -node=Node2 -join=172.17.0.2 -iface=eth0
From docs https://www.serf.io/docs/agent/options.html:
-iface - 该标志可用于提供绑定接口。如果接口已知但不知道地址,则可以使用它来代替 -bind。
它对我来说工作正常:
Node1:
==> Log data will now stream in as it occurs:
2017/06/04 01:56:40 [INFO] agent: Serf agent starting
2017/06/04 01:56:40 [INFO] serf: EventMemberJoin: Node1 172.17.0.2
2017/06/04 01:56:41 [INFO] agent: Received event: member-join
2017/06/04 01:57:02 [INFO] serf: EventMemberJoin: Node2 172.17.0.3
2017/06/04 01:57:03 [INFO] agent: Received event: member-join
Node2:
==> Log data will now stream in as it occurs:
2017/06/04 01:57:02 [INFO] agent: Serf agent starting
2017/06/04 01:57:02 [INFO] serf: EventMemberJoin: Node2 172.17.0.3
2017/06/04 01:57:02 [INFO] agent: joining: [172.17.0.2] replay: false
2017/06/04 01:57:02 [INFO] serf: EventMemberJoin: Node1 172.17.0.2
2017/06/04 01:57:02 [INFO] agent: joined: 1 nodes
2017/06/04 01:57:03 [INFO] agent: Received event: member-join
Edit:
如果每个容器都在自己的VM(EC2实例)中,则由于每个实例都有自己的docker网络并且不互连,因此您必须提供EC2实例IP并公开相应的端口。使用-advertise https://www.serf.io/docs/agent/options.html#advertise
-advertise - 广告标志用于更改我们向集群中其他节点广告的地址。
Node1:
serf agent -node=Node1 -iface=eth0 -advertise=INSTANCE_IP
Node2:
serf agent -node=Node2 -join=NODE1_INSTANCE_IP -iface=eth0
并记住expose农奴口在docker run
docker run -p 7946:7946 (...rest of the command...)