#开发模式运行agent consul agent -dev
#查看consul 集群成员 consul members [-detailed]
members
命令的输出基于gossip协议,并最终一致。 也就是说,在任什么时候候,当地代理所看到的可能与服务器上的状态不彻底一致。 要得到彻底一致,请使用HTTP API再将HTTP请求转发给Consul服务器:
curl localhost:8500/v1/catalog/nodes
除了HTTP API以外,还能够使用DNS接口查询节点。
consul的服务能够经过提供服务定义或经过对HTTP API进行适当的调用来注册。node
服务定义步骤:web
1.建立consul配置目录json
mkdir /etc/consul.d
2.编写服务定义配置文件bootstrap
#web service 80port echo '{"service": {"name": "web", "tags": ["rails"], "port": 80}}' | sudo tee /etc/consul.d/web.json
3.使用参数 -config-dir=config-path启动代理程序api
consul agent -dev -config-dir=/etc/consul.d
当代理启动而且服务同步后,咱们能够使用dns或者http api来查询服务。服务器
curl http://localhost:8500/v1/catalog/service/webcurl
服务定义能够经过更改配置文件并向代理发送SIGHUP来更新。 这使您能够更新服务,而不会出现任何停机或没法提供服务查询的状况。 或者,能够使用HTTP API动态地添加,删除和修改服务。url
启动代理 服务器方式spa
consul agent -server -bootstrap-expect=1 -data-dir=/tmp/consul -node=agent-one -bind=192.168.65.135 -enable-script-checks=true -config-dir=/etc/consul.d
启动代理 客户端方式.net
consul agent -data-dir=/tmp/consul -node=agent-two -bind=192.168.65.139 -enable-script-checks=true -config-dir=/etc/consul.d/
加入consul集群
consul join 192.168.65.135
也能够在启动节点的时候使用-join选项或者start_join设置来加入集群
参考:
consul入门指南 https://blog.csdn.net/y435242634/article/details/78639663