Consul 集群2

2021-12-01 17:00:44 浏览数 (1)

启动第二个节点

代码语言:javascript复制
[root@docker consul]# consul agent -data-dir /tmp/consul -node=a2 -bind=192.168.100.103 -config-dir /etc/consul.d
==> Starting Consul agent...
==> Starting Consul agent RPC...
==> Consul agent running!
         Node name: 'a2'
        Datacenter: 'dc1'
            Server: false (bootstrap: false)
       Client Addr: 127.0.0.1 (HTTP: 8500, HTTPS: -1, DNS: 8600, RPC: 8400)
      Cluster Addr: 192.168.100.103 (LAN: 8301, WAN: 8302)
    Gossip encrypt: false, RPC-TLS: false, TLS-Incoming: false
             Atlas: <disabled>

==> Log data will now stream in as it occurs:

    2016/03/18 21:51:55 [INFO] serf: EventMemberJoin: a2 192.168.100.103
    2016/03/18 21:51:55 [ERR] agent: failed to sync remote state: No known Consul servers
    2016/03/18 21:52:17 [ERR] agent: failed to sync remote state: No known Consul servers
    2016/03/18 21:52:22 [INFO] agent.rpc: Accepted client: 127.0.0.1:42288
    2016/03/18 21:52:38 [ERR] agent: failed to sync remote state: No known Consul servers
...
...
...

此时已经分别在104和103上启动了两个代理a1和a2,a1准备用来作server ,a2用来作client,但它们彼此还互不认识,都是自己的单节点集群中的唯一节点,可以通过 consul members 来进行查看

代码语言: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
[root@h104 consul]# 
----------
[root@docker ~]# consul members
Node  Address               Status  Type    Build  Protocol  DC
a2    192.168.100.103:8301  alive   client  0.6.4  2         dc1
[root@docker ~]# 

加入集群

使用a1来加入a2

代码语言:javascript复制
[root@h104 consul]# consul join 192.168.100.103
Successfully joined cluster by contacting 1 nodes.
[root@h104 consul]# 

Note: 要确保两个节点TCP或UDP的8301是开放的,最好是TCP和UDP都开放,因为节点间的通讯得依赖这个端口,否则无法加入

代码语言:javascript复制
[root@h104 consul]# consul join 192.168.100.103
Error joining the cluster: dial tcp 192.168.100.103:8301: getsockopt: no route to host
[root@h104 consul]# 

Tip: 防火墙端口打开方法:在Centos7中使用 firewall-cmd 来管理防火墙

代码语言:javascript复制
[root@h104 consul]# firewall-cmd --list-all 
public (default, active)
  interfaces: eno16777736 eno33554960
  sources: 
  services: dhcpv6-client ssh
  ports: 3306/tcp 80/tcp 40000/tcp 8080/tcp
  masquerade: no
  forward-ports: 
  icmp-blocks: 
  rich rules: 
	
[root@h104 consul]# firewall-cmd --add-port=8301/tcp
success
[root@h104 consul]# firewall-cmd --list-all 
public (default, active)
  interfaces: eno16777736 eno33554960
  sources: 
  services: dhcpv6-client ssh
  ports: 3306/tcp 80/tcp 40000/tcp 8080/tcp 8301/tcp
  masquerade: no
  forward-ports: 
  icmp-blocks: 
  rich rules: 
	
[root@h104 consul]# consul join 192.168.100.103
Successfully joined cluster by contacting 1 nodes.
[root@h104 consul]# 

0 人点赞