consul & registrator & consul-template 使用
consul & registrator & consul-template 使用
参考这里的文章:
https://www.jianshu.com/p/a4c04a3eeb57
docker-compose.yml
version: '3'
services:
web:
image: liberalman/helloworld:latest
environment:
SERVICE_80_NAME: my-web-server
SERVICE_TAGS: backend-1
MY_HOST: host-1
ports:
- "80"
lb:
image: liberalman/nginx-consul-template:latest
hostname: lb
links:
- consulserver:consul
ports:
- "80:80"
consulserver:
image: progrium/consul:latest
environment:
SERVICE_TAGS: consul servers
hostname: consulserver
ports:
- "8300"
- "8400"
- "8500:8500"
- "53"
command: -server -ui-dir /ui -data-dir /tmp/consul -bootstrap-expect 1
registrator:
image: gliderlabs/registrator:master
hostname: registrator
links:
- consulserver:consul
volumes:
- "/var/run/docker.sock:/tmp/docker.sock"
command: -internal consul://consul:8500
docker-compose up
docker-compose up --scale web=3

停掉其中一个container ,看看发生什么事情导致能够检测到节点挂掉,并不转发流量?
关键处:订阅了状态的结果后,动态改变了nginx的配置。效果:

单机的架构、原理如下:

or 参考:

consul 只是其中一种注册中心的实现,registrator support zk&consule/etcd/skydns2
registrator 主动检查
https://github.com/gliderlabs/registrator/blob/master/registrator.go
根据tick 的到来,registrator.go 做几件事情:

- resync interval 到达,扫描, 同步容器状态 refresh :
- alive 的container,
- delete 到consul
- refresh interval 到达,sync :
- list 当前的container
- 移除不健康的container
- deregister 不健康的container
看到这里,这种基于registrator的主动检测,解耦服务于注册中心的代码
分布式的配置
每个宿主机都要配置 registrator ,因为只能同一台宿主机去扫描container 的状态,注意红框处:

集群的架构

consul vs zk , etcd
https://www.consul.io/intro/vs/zookeeper.html
vs traditional: nginx + lua + jenkins
传统的发布模式:
- 服务需要配置健康检查
- 添加新的服务节点要运维人为操作下到nginx 分发
- lua 要配置好蓝绿发布状态的控制
- 如果传统的配置中心:
- 服务要配置注册中心 register deregister,耦合
而现在,只需要简单的配置增加服务节点,就好了
websocket/https
ref :
https://www.jianshu.com/p/a4c04a3eeb57
https://segmentfault.com/a/1190000005026022
https://segmentfault.com/a/1190000013720661
https://segmentfault.com/a/1190000005040914
https://learn.hashicorp.com/consul/getting-started/checks.html
https://www.consul.io/docs/agent/checks.html
https://my.oschina.net/guol/blog/353101
https://www.jianshu.com/p/f8746b81d65d
https://medium.com/eleven-labs/consul-service-discovery-and-failure-detection-64b06a5cbce6
https://www.cnblogs.com/zhangdk/p/Registrator_reference.html
https://kevinguo.me/2017/09/01/docker-consul-consul-template-registrator-nginx/#nginx-with-consul-template
https://juejin.im/post/5b59d64b6fb9a04fd1602017
consul & registrator & consul-template 使用的更多相关文章
- Docker+Consul+Registrator 实现服务注册与发现
Docker+Consul+Registrator实现服务注册与发现 逻辑图 实现nginx节点自动化加入容器IP代理 1.三台Consul agent server作为高可用通过Consul Tem ...
- 【Consul】CONSUL调研
[Consul]CONSUL调研 2016年08月18日 18:31:53 YoungerChina 阅读数:1962更多 所属专栏: Consul修炼 版权声明:原创不易,转载请注明出处! ht ...
- 1、微服务--为什么有consul,consul注册,心跳检测,服务发现
一.为什么有consul? 在微服务,每1个服务都是集群式的,订单服务在10台服务器上都有,那么用户的请求到达,获取哪台服务器的订单服务呢?如果10台中的有的订单服务挂了怎么办?10台服务器扛不住了, ...
- Centos 7 Docker、docker-compose、Registrator、Consul、Consul Template和Nginx实现高可扩展的Web框架
安装所需软件 Docker Docker-compose 配置docker-compose.yml文件内容如下: #load balancer will automatically update th ...
- .net core微服务之基于Docker+Consul+Registrator服务注册服务发现
一.Docker部分: 先拉最新的asp.net core的镜像: docker pull microsoft/aspnetcore 将下载下来的镜像重命名,为什么要重命名?等会讲Registrato ...
- Ocelot + Consul + Registrator 基于Docker 实现服务发现、服务自动注册
目录 1. Consul集群搭建 1.1 F&Q Consul官方推荐的host网络模式运行 2. Registrator服务注册工具 2.1 F&Q Registrator悬挂服务 ...
- 微服务注册发现集群搭建—单机版(Registrator+Consul+Consul-template+nginx)
1.创建模板文件 docker-compose.yml #backend web application, scale this with docker-compose scale web=3 web ...
- 【Consul】Consul实践指导-配置文件
Agent有各种各样的配置选项,这些配置选项可以通过命令行参数的方式设定,也可用通过配置文件的方式设定--所有的配置选项都是可选的,当然也是有默认值的. 当加载配置选项时,consul是按照词典顺序从 ...
- 【Consul】Consul架构-Session会话
Consul提供session会话机制--可以用于构建分布式锁,session可以绑定到节点.健康检查.KV数据.目的是提供颗粒锁--受 The Chubby LockService for Loos ...
随机推荐
- anytime
#include<stdio.h> #include<stdlib.h> #include<unistd.h> #include<sys/time.h> ...
- rtp传输音视频(纯c代码)
参考链接: 1. PES,TS,PS,RTP等流的打包格式解析之RTP流 https://blog.csdn.net/appledurian/article/details/73135343 2. ...
- 接口自动化测试遭遇问题,excel中取出来的json串,无法使用requests去请求解决办法
最近遭遇了一个问题,问题不大不小,想半天没想明白是哪里有问题,今天终于解决了 用python读取了excel用例中,body json字符串内容,然后requests去请求内容,结果一直报错,一直不明 ...
- Matlab小波工具箱的使用2
Matlab小波工具箱的使用2 (2011-11-11 09:32:57) 转载▼ http://blog.sina.com.cn/s/blog_6163bdeb0102dw7a.html#cmt_5 ...
- Navicat连接Mysql报错:Client does not support authentication protocol requested by server;
Navicat连接Mysql报错:Client does not support authentication protocol requested by server: 刚安装Mysql,想用Nav ...
- Html.Raw用法
比如有个字符串是这样的<font color='red'>红字</font> 如果是用@Html.Raw('<font color='red'>红字</fon ...
- AIX下core文件的分析
笔者曾在AIX系统下使用C语言开发多个应用系统.众所周知,C语言编写程序时容易出现内存使用不当的BUG,例如内存越界.使用野指针.内存未初始化等等.在程序运行时,这些BUG很可能造成程序崩溃,但在测试 ...
- less &进行选择判断css的样式
先说&在less写 .parent{ .child{} &.and{} }在css就是 .parent.child{}//父子关系 .parent.and{}//并关系 用到这个方法是 ...
- nginx 配置 HTTPS 及http 强制跳转https.
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #erro ...
- C#连接字符串
1."Data Source=服务器名; Initial Catalog=数据库; User ID =用户名; Password=密码; Charset=UTF8; " 2.&qu ...