分布式系统工具Consul
来源:互联网 发布:dj混音软件 编辑:程序博客网 时间:2024/05/17 21:48
在寻找简洁的PaaS工具组合时,发现了Consul这个工具。https://www.consul.io
此开源产品来自于 HashiCorp, 就是提供虚拟机管理工具Vagrant的公司。
标题是服务发现和配置。
有多个模块,但无论服务端还是客户端,都只有一个单一的程序Consul。部署非常简单。
功能有:1)服务发现; 2)健康检查;3)KV存储;4)多数据中心
每个提供服务的host需要运行Consul Agent,作用: registers services, runs health checks, and forwards queries to servers.
Consul Agent需要与一个或多个Consul Server通信。
服务可以通过文件定义或HTTP API调用来定义。 A service can be registered either by providing a service definition or by making the appropriate calls to theHTTP API.
通过文件定义一个简单的服务: $ echo '{"service": {"name": "web", "tags": ["rails"], "port": 80}}' >/etc/consul.d/web.json
启动 :consul agent -dev -config-dir /etc/consul.d
如果有多个网卡,启动会失败,需要加 -advertise=ipaddr 参数。
调用DNS API来查询服务 : dig @127.0.0.1 -p 8600 web.service.consul
或者使用HTTP API来查询: curl http://localhost:8500/v1/catalog/service/web
集群配置
如果要知道其他cosul成员,后续启动的agent必须加入到其中之一。 任意一个,无论它是否是运行在服务器模式下。 那么所有集群成员都会知道新成员的存在。
自动加入集群的机制。 HashiCorp做了一个atlas服务,提供注册账号和一个Token,就可以自动加入集群了。不能上外网就不能这么用。但思路很好。
退出集群。正常退出,状态就是left state,如果不打招呼就退出,那么就是failed状态。
当然,任何节点都提供查询服务。查询consul节点和服务的状态。
健康检查
检查分host级别和service级别。
echo '{"check": {"name": "ping", "script": "ping -c1 google.com >/dev/null", "interval": "30s"}}' > /etc/consul.d/ping.json
echo '{"service": {"name": "web", "tags": ["rails"], "port": 80, "check": {"script": "curl localhost >/dev/null 2>&1", "interval": "10s"}}}' > /etc/consul.d/web.json
都是采用了脚本监测方法。如果返回值非零,就是表示故障。5中类型检查逻辑: https://www.consul.io/docs/agent/checks.html
键值存储 : https://www.consul.io/docs/agent/http/kv.html
还有启动cluster和故障恢复问题。待续。
- 分布式系统工具Consul
- 使用Consul快速搭建简易分布式服务监控系统
- 使用Python进行分布式系统协调 (ZooKeeper/Consul/etcd)
- 使用Python进行分布式系统协调 (ZooKeeper,Consul, etcd )
- 使用Python进行分布式系统协调 (ZooKeeper,Consul, etcd )
- 使用Python进行分布式系统协调 (ZooKeeper,Consul, etcd )
- 服务发现系统consul
- 服务发现系统consul--配置
- 服务发现系统consul介绍
- 基于Consul的分布式锁实现
- 基于Consul的分布式信号量实现
- consul
- consul
- 服务发现系统consul-HTTP API
- golang使用服务发现系统consul
- 使用consul实现分布式服务注册和发现
- consul分布式集群搭建&简单功能测试&故障恢复
- bind dlz - 分布式系统的请求分发工具
- Nginx配置文件nginx.conf中文详解
- oracle之空值(NULL)和空值函数使用
- POJ 2456 Aggressive cows
- Windows下PHP配置成功后phpinfo中找不到mysql
- C++ 枚举类型的思考
- 分布式系统工具Consul
- LeetCode319. Bulb Switcher优化到只有一行代码
- NYOJ—韩信点兵
- DiskLruCache的简单用法
- 安卓开发:自定义Log日志类
- 缓存淘汰算法--LRU算法
- LNMP一键安装包详细安装教程
- HDU 3498 whosyourdaddy(DLX+A*||多重覆盖)
- BCGControlBar v12的向导使用图解