设为首页 加入收藏

TOP

Spring Cloud开发实践(五): Consul - 服务注册的另一个选择(二)
2023-07-25 21:24:08 】 浏览:63
Tags:Spring Cloud Consul
定. 如果不指定后者, 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 退出

参考

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇聊一聊适配器模式 下一篇Spring Boot 实现跨域的 5 种方式..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目