consul日常操作命令

1
2
3
4
#开发模式运行agent
consul agent -dev<br>
#查看consul 集群成员
consul members  [-detailed]<br><br> 

members命令的输出基于gossip协议,并最终一致。 也就是说,在任何时候,当地代理所看到的可能与服务器上的状态不完全一致。 要获得完全一致,请使用HTTP API再将HTTP请求转发给Consul服务器:
curl localhost:8500/v1/catalog/nodes
除了HTTP API之外,还可以使用DNS接口查询节点。

consul的服务可以通过提供服务定义或通过对HTTP API进行适当的调用来注册。

服务定义步骤:

1.创建consul配置目录

mkdir /etc/consul.d 

2.编写服务定义配置文件

#web service 80port
echo '{"service": {"name": "web", "tags": ["rails"], "port": 80}}' | sudo tee /etc/consul.d/web.json 

3.使用参数  -config-dir=config-path启动代理程序

consul agent -dev -config-dir=/etc/consul.d

 

当代理启动并且服务同步后,我们可以使用dns或者http api来查询服务。

curl http://localhost:8500/v1/catalog/service/web

 

服务定义可以通过更改配置文件并向代理发送SIGHUP来更新。 这使您可以更新服务,而不会出现任何停机或无法提供服务查询的情况。 或者,可以使用HTTP API动态地添加,删除和修改服务。

 

启动代理    服务器方式

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

启动代理   客户端方式

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

posted @   mofy  阅读(416)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
历史上的今天:
2017-06-29 ldconfig: /usr/lib/libpython2.6.so.1.0-gdb.py is not an ELF file - it has the wrong magic bytes at the start.
2017-06-29 [Errno 14] problem making ssl connection Trying other mirror.
点击右上角即可分享
微信分享提示