consul集群配置文件(windows)--记录
参考自: https://www.jianshu.com/p/27265e34d911
https://developer.aliyun.com/article/667078
--------------------------------------------------
单机启动脚本:
创建同级目录config和data分别作为配置文件以及数据文件的目录
config目录中增加acl.json, 其中token作为登录的认证,相当于密码
{ "acl_datacenter": "dc1", "acl_master_token": "p2BE1AtpwPbrxZdC6k+eXA==", "acl_default_policy": "deny", "acl_down_policy": "extend-cache" }
./consul agent -config-dir=./config -server -data-dir=./data -bootstrap -ui
加上 -client=0.0.0.0 表示对外提供服务
--------------------------------------------------------------------------------
在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即可看到自带的管理页面