定. 如果不指定后者, consul会一直等待 leader 的产生
集群模式
集群模式下, 每个 Datacenter 必须至少有一台 server. 建议是3或5台, 单server在宕机时会造成数据丢失. 其它 Agent 运行为 client 模式.
下面以一台Server, 一台Client为例说明
在 11.22 主机上运行 Server
consul agent -ui -server -bootstrap-expect=1 -data-dir=./consul-data -client=192.168.11.22 -bind=192.168.11.22
在 11.23 主机上运行 Client, 并 Join 到 11.22
consul agent -ui -data-dir=./data -client=192.168.11.23 -bind=192.168.11.23 -retry-join=192.168.11.22
Join 成功后, 在两边的控制台上会显示相应信息. 这时候通过consul members
可以看到两个Node:
/opt/consul/consul members -http-addr=http://192.168.11.22:8500
Node Address Status Type Build Protocol DC Partition Segment
centos7001 192.168.11.22:8301 alive server 1.15.2 2 dc1 default <all>
54120-nc01 192.168.11.23:8301 alive client 1.6.1 2 dc1 default <default>
后台运行
不留日志
nohup /opt/consul/consul agent -ui -server -bootstrap-expect=1 -data-dir=./consul-data -client=192.168.11.22 -bind=192.168.11.22 >/dev/null 2>&1 &
日志输出到文件
nohup /opt/consul/consul agent -ui -server -bootstrap-expect=1 -data-dir=./consul-data -client=192.168.11.22 -bind=192.168.11.22 >path/to/log/consul.log 2>&1 &
这样consul会在后台运行, 需要用 consul leave 退出
参考