【Consul】Consul实践指导-服务注册(Service)
来源:互联网 发布:一淘网跟淘宝网 编辑:程序博客网 时间:2024/05/21 01:46
服务发现是consul的另一主要功能。Consul Agent提供简单的Service定义格式用于申报服务的可用性,并与健康检查相关联。如果健康检查与服务关联,则认为服务是应用级的。服务可以定义在配置文件中或在运行时通过HTTP接口添加。
1.1.1 Service Definition
脚本服务定义示例如下:
{ "service": { "name": "redis", "tags": ["master"], "address": "127.0.0.1", "port": 8000, "enableTagOverride": false, "checks": [ { "script": "/usr/local/bin/check_redis.py", "interval": "10s" } ] }}
定义服务必须包含name字段,其他字段id、tags、address、port、check、enableTagOverride是可选字段。如果id字段没有定义,那么会被赋值为name。在当前节点上,服务ID必须是唯一的,name是可以重复的,那么id必须配置。
Tags字段是增强配置的可读性,consul不使用,可以说明当前节点是master还是slave,及其版本等信息。
Address字段可以指定一个给定服务的IP。默认情况下,通常使用agent的IP,不是必须的。使用端口port可以使得面向服务的体系架构更容易配置。
服务与健康检查关联,可以替换失败节点和数据库。健康检查很好地集成了DNS接口,如果服务健康检查失败或者节点存在系统级检查失败。DNS接口将从服务队列中删除该节点。
Check必须是Script、HTTP、TCP、TTL四种类型中的一种。Script类型需要提供Script脚本和interval变量。HTTP类型必须提供http和Interval字段。TCP类型需要提供tcp和Interval字段,TTL类型秩序提供ttl。Check的name字段是自动通过service:<service-id>
生成,如果有多个service,则由service:<service-id>:<num>
生成
(详情参见check配置-http://blog.csdn.net/younger_china/article/details/52243759)
Service配置是可以重载的,两种方法,1. 发送SIGHUP 信号到Agent;2. 通过HTTP API动态配置。
1.1.2 Multiple Service Definitions
使用services字段,示例如下:
{ "services": [ { "id": "red0", "name": "redis", "tags": [ "master" ], "address": "127.0.0.1", "port": 6000, "checks": [ { "script": "/bin/check_redis-p 6000", "interval": "5s", "ttl": "20s" } ] }, { "id": "red1", "name": "redis", "tags": [ "delayed", "slave" ], "address": "127.0.0.1", "port": 7000, "checks": [ { "script": "/bin/check_redis-p 7000", "interval": "30s", "ttl": "60s" } ] }, ... ]}
1.1.3 Service and Tag Names with DNS
Consul exposes service definitions and tags over the DNS interface. DNS queries have a strict set of allowed characters anda well-defined format that Consul cannot override. While it is possible toregister services or tags with names that don't match the conventions, thoseservices and tags will not be discoverable via the DNS interface. It isrecommended to always use DNS-compliant service and tag names.
DNS-compliant service and tag names may contain any alpha-numericcharacters, as well as dashes. Dots are not supported because Consul internallyuses them to delimit service tags.
- 【Consul】Consul实践指导-服务注册(Service)
- 【Consul】Consul实践指导-配置文件
- 【Consul】Consul实践指导-Agent
- 【Consul】Consul实践指导-telemetry
- 【Consul】Consul实践指导-健康检查(Checks)
- 【Consul】Consul实践指导-Watch机制
- 【Consul】Consul实践指导-DNS接口
- 【Consul】Consul实践指导-HTTP API
- 【Consul】Consul实践指导-Encryption配置
- 【Consul】Consul实践指导-RPC机制
- 【Consul】Consul实践指导-HTTP API
- consul 手动注册服务
- Consul服务注册发现
- Spring cloud 服务注册(consul)
- springcloud consul +consul 实现服务注册及发现
- Consul 服务注册与服务发现
- Consul 服务注册与服务发现
- •服务注册与发现(Eureka、Consul)
- hdu3597Hello Kiki 一元模线性方程组
- Java this()必须放在构造方法的第一句,在成员方法中不能用this()调用构造方法的原因
- HDU 2037 今年暑假不AC
- 史上最佳 Mac+PhpStorm+XAMPP+Xdebug 集成开发和断点调试环境的配置
- poj 1416 Shredding Company
- 【Consul】Consul实践指导-服务注册(Service)
- Android中补间动画、属性动画效果演示
- iOS中 项目开发易错知识点总结 韩俊强的博客
- Insight mysql-connector connection 部分实现
- navigationController.interactivePopGestureRecognizer.enabled
- 类找不到总结java.lang.ClassNotFoundException
- LeetCode: 107. Binary Tree Level Order Traversal II
- system.in.read()用法
- MyBatis学习一