微服务之Consul服务注册与发现 集群配置(二)

consul配置建议采用大于等于3台部署,最好是奇数,具体什么原因应该懂得,大致跟灾备一个意思,

本篇的consul集群配置参考了“ 笪笠”的博客,https://www.cnblogs.com/wushengwuxi/articles/12840500.html
配置比较全面,方便快捷,便于新手上路。废话不多说,上干货:

在consul.exe目录下新建三个目录node1、node2、node3,分别新建配置文件basic.json

node1目录下basic.json

{
  "datacenter": "dc1",
  "data_dir": "./node1/data/",
  "log_level": "INFO",
  "server": true,
  "node_name": "node1",
  "ui": true,
  "bind_addr": "192.168.1.108",
  "client_addr": "192.168.1.108",
  "advertise_addr": "192.168.1.108",
  "bootstrap_expect": 3,
  "ports":{
    "http": 8500,
    "dns": 8600,
    "server": 8300,
    "serf_lan": 8301,
    "serf_wan": 8302
    }
}

node2目录下basic.json

{
  "datacenter": "dc1",
  "data_dir": "./node2/data/",
  "log_level": "INFO",
  "server": true,
  "node_name": "node2",
  "ui": true,
  "bind_addr": "192.168.1.108",
  "client_addr": "192.168.1.108",
  "advertise_addr": "192.168.1.108",
  "bootstrap_expect": 3,
  "ports":{
    "http": 8510,
    "dns": 8610,
    "server": 8310,
    "serf_lan": 8311,
    "serf_wan": 8312
    }
}

node3目录下basic.json

{
  "datacenter": "dc1",
  "data_dir": "./node3/data/",
  "log_level": "INFO",
  "server": true,
  "node_name": "node3",
  "ui": true,
  "bind_addr": "192.168.1.108",
  "client_addr": "192.168.1.108",
  "advertise_addr": "192.168.1.108",
  "bootstrap_expect": 3,
  "ports":{
    "http": 8520,
    "dns": 8620,
    "server": 8320,
    "serf_lan": 8321,
    "serf_wan": 8322
    }
}

在consul同目录下新建.bat文件,用于启动consul并加入集群, -retry-join指定要加入的集群节点

node1.bat

consul agent -server -client 0.0.0.0 -ui -config-file=./node1/basic.json -retry-join=192.168.1.108:8301
pause

node2.bat

consul agent -server -client 0.0.0.0 -ui -config-file=./node2/basic.json -retry-join=192.168.1.108:8301
pause

node3.bat

consul agent -server -client 0.0.0.0 -ui -config-file=./node3/basic.json -retry-join=192.168.1.108:8301
pause
启动三个consul节点后,访问localhost:8500即可看到自带的管理页面

完成后目录为:

 

 

 启动后,打开页面显示三个节点:

 

posted @ 2021-06-11 16:58  小西门吹吹雪  阅读(332)  评论(0编辑  收藏  举报