天天看点

Consul 多数据中心配置 MULTIPLE DATACENTERS

在consul集群中,多数据中心可以进行配置:

LAN gossip pool包含了同一局域网内所有节点,包括server与client。这基本上是位于同一个数据中心DC。

WAN gossip pool一般仅包含server,将跨越多个DC数据中心,通过互联网或广域网进行通信。

我们之前讲过的启动集群命令使用的是-bootstrap 来作为服务的启动:

consul agent -server -bootstrap -data-dir /tmp/consul/ -node=web4 -bind=192.168.240.132 -config-dir /etc/consul.d/ -client 0.0.0.0 -ui -dc=gbj -rejoin </span>
           

将命令稍微做下修改使用-bootstrap-expect:

consul agent -server -bootstrap-expect 3 -data-dir /tmp/consul/ -node=web4 -bind=192.168.240.132 -config-dir /etc/consul.d/ -client 0.0.0.0 -ui -dc=gbj -rejoin
           

查询当前集群下拥有的datacenter信息:

consul members -wan
           

我这里有两个数据中心dc1和gbj,使用下面的命令将数据中心互相可见:

consul join -wan 192.168.240.131
           
Consul 多数据中心配置 MULTIPLE DATACENTERS

多数据中心就配好了,在之前的UI中也可以看到了:

Consul 多数据中心配置 MULTIPLE DATACENTERS

参考资料:https://www.consul.io/docs/guides/datacenters.html

继续阅读