加入成功后server节点上就会产生如下日志
代码语言:javascript复制...
...
2016/03/18 22:00:36 [INFO] agent.rpc: Accepted client: 127.0.0.1:44743
2016/03/18 22:00:36 [INFO] agent: (LAN) joining: [192.168.100.103]
2016/03/18 22:00:36 [INFO] agent: (LAN) joined: 0 Err: dial tcp 192.168.100.103:8301: getsockopt: no route to host
2016/03/18 22:04:06 [INFO] agent.rpc: Accepted client: 127.0.0.1:44778
2016/03/18 22:04:06 [INFO] agent: (LAN) joining: [192.168.100.103]
2016/03/18 22:04:06 [INFO] serf: EventMemberJoin: a2 192.168.100.103
2016/03/18 22:04:06 [INFO] agent: (LAN) joined: 1 Err: <nil>
2016/03/18 22:04:06 [INFO] consul: member 'a2' joined, marking health alive
2016/03/18 22:07:12 [INFO] agent.rpc: Accepted client: 127.0.0.1:44813
...
...
代码语言:javascript复制Note: 要确保server节点TCP的8300是开放的,最好是server 和client都开放(没准以后client也会更换角色呢),因为client向server的RPC得依赖这个端口,不打开无法同步
...
...
2016/03/18 22:04:06 [INFO] serf: EventMemberJoin: a1 192.168.100.104
2016/03/18 22:04:06 [INFO] consul: adding server a1 (Addr: 192.168.100.104:8300) (DC: dc1)
2016/03/18 22:04:06 [INFO] consul: New leader elected: a1
2016/03/18 22:04:07 [ERR] agent: coordinate update error: rpc error: failed to get conn: dial tcp 192.168.100.104:8300: getsockopt: no route to host
2016/03/18 22:04:09 [ERR] agent: failed to sync remote state: rpc error: failed to get conn: dial tcp 192.168.100.104:8300: getsockopt: no route to host
...
...
...
打开方式一样
代码语言:javascript复制[root@h104 consul]# firewall-cmd --add-port=8300/tcp
success
[root@h104 consul]# firewall-cmd --list-all
public (default, active)
interfaces: eno16777736 eno33554960
sources:
services: dhcpv6-client ssh
ports: 80/tcp 8080/tcp 8301/tcp 3306/tcp 8300/tcp 40000/tcp
masquerade: no
forward-ports:
icmp-blocks:
rich rules:
[root@h104 consul]#
打开后client才能正常同步
代码语言:javascript复制...
...
2016/03/18 22:06:03 [INFO] agent: Synced node info
...
...
此时再在两个节点上查看成员状态,彼此都能互识了
代码语言:javascript复制[root@h104 consul]# consul members
Node Address Status Type Build Protocol DC
a1 192.168.100.104:8301 alive server 0.6.4 2 dc1
a2 192.168.100.103:8301 alive client 0.6.4 2 dc1
[root@h104 consul]#
----------
[root@docker ~]# consul members
Node Address Status Type Build Protocol DC
a1 192.168.100.104:8301 alive server 0.6.4 2 dc1
a2 192.168.100.103:8301 alive client 0.6.4 2 dc1
[root@docker ~]#
Tip: 如果有多个成员,也只用加入一个节点,其它节点会在这个节点加入集群后通过成员间的通讯相互发现