Consul 基础7
2023-03-20 15:36:03 时间
注册服务
定义服务
定义服务可以使用两种方法:
- 使用配置文件进行服务定义
- 调用 HTTP API 进行定义
Consul 会加载配置目录中的所有配置文件,配置文件是以 .json 结尾的,并且以字典顺序加载
创建配置文件
[root@h104 consul]# mkdir /etc/consul.d
[root@h104 consul]# echo '{"service": {"name": "web", "tags": ["rails"], "port": 80}}' > /etc/consul.d/web.json
[root@h104 consul]# cat /etc/consul.d/web.json
{"service": {"name": "web", "tags": ["rails"], "port": 80}}
[root@h104 consul]#
指定配置文件启动服务
[root@h104 consul]# consul agent -dev -bind=192.168.100.104 -config-dir /etc/consul.d/
==> Starting Consul agent...
==> Starting Consul agent RPC...
==> Consul agent running!
Node name: 'h104'
Datacenter: 'dc1'
Server: true (bootstrap: false)
Client Addr: 127.0.0.1 (HTTP: 8500, HTTPS: -1, DNS: 8600, RPC: 8400)
Cluster Addr: 192.168.100.104 (LAN: 8301, WAN: 8302)
Gossip encrypt: false, RPC-TLS: false, TLS-Incoming: false
Atlas: <disabled>
==> Log data will now stream in as it occurs:
2016/03/18 17:07:20 [INFO] serf: EventMemberJoin: h104 192.168.100.104
2016/03/18 17:07:20 [INFO] serf: EventMemberJoin: h104.dc1 192.168.100.104
2016/03/18 17:07:20 [INFO] raft: Node at 192.168.100.104:8300 [Follower] entering Follower state
2016/03/18 17:07:20 [INFO] consul: adding LAN server h104 (Addr: 192.168.100.104:8300) (DC: dc1)
2016/03/18 17:07:20 [INFO] consul: adding WAN server h104.dc1 (Addr: 192.168.100.104:8300) (DC: dc1)
2016/03/18 17:07:20 [ERR] agent: failed to sync remote state: No cluster leader
2016/03/18 17:07:22 [WARN] raft: Heartbeat timeout reached, starting election
2016/03/18 17:07:22 [INFO] raft: Node at 192.168.100.104:8300 [Candidate] entering Candidate state
2016/03/18 17:07:22 [DEBUG] raft: Votes needed: 1
2016/03/18 17:07:22 [DEBUG] raft: Vote granted from 192.168.100.104:8300. Tally: 1
2016/03/18 17:07:22 [INFO] raft: Election won. Tally: 1
2016/03/18 17:07:22 [INFO] raft: Node at 192.168.100.104:8300 [Leader] entering Leader state
2016/03/18 17:07:22 [INFO] raft: Disabling EnableSingleNode (bootstrap)
2016/03/18 17:07:22 [DEBUG] raft: Node 192.168.100.104:8300 updated peer set (2): [192.168.100.104:8300]
2016/03/18 17:07:22 [INFO] consul: cluster leadership acquired
2016/03/18 17:07:22 [DEBUG] consul: reset tombstone GC to index 2
2016/03/18 17:07:22 [INFO] consul: member 'h104' joined, marking health alive
2016/03/18 17:07:22 [INFO] consul: New leader elected: h104
2016/03/18 17:07:25 [INFO] agent: Synced service 'consul'
2016/03/18 17:07:25 [INFO] agent: Synced service 'web'
2016/03/18 17:08:44 [DEBUG] dns: request for {h104.node.consul. 1 1} (396.33µs) from client 127.0.0.1:48961 (udp)
2016/03/18 17:09:15 [DEBUG] agent: Service 'consul' in sync
2016/03/18 17:09:15 [DEBUG] agent: Service 'web' in sync
...
...
...
输出中表示 Synced service ‘web’,说明定义的服务已经成功被注册进来了,如果要以配置文件的形式注册更多的服务,可以在配置目录中添加其它的服务定义
相关文章
- 金融服务领域的大数据:即时分析
- 影响大数据、机器学习和人工智能未来发展的8个因素
- 从0开始构建一个属于你自己的PHP框架
- 如何将Hadoop集成到工作流程中?这6个优秀实践必看
- SEO公司使用大数据优化其模型的5种方法
- 关于Web Workers你需要了解的七件事
- 深入理解HTTPS原理、过程与实践
- 增强分析:数据和分析的未来
- PHP协程实现过程详解
- AI专家:大数据知识图谱——实战经验总结
- 关于PHP的错误机制总结
- 利用数据分析量化协同过滤算法的两大常见难题
- 怎么做大数据工作流调度系统?大厂架构师一语点破!
- 2019大数据处理必备的十大工具,从Linux到架构师必修
- OpenCV中的KMeans算法介绍与应用
- 教大家如果搭建一套phpstorm+wamp+xdebug调试PHP的环境
- CentOS下三种PHP拓展安装方法
- Go语言HTTP Server源码分析
- Go语言HTTP Server源码分析
- 2017年4月编程语言排行榜:Hack首次进入前五十