参考这里的文章:
https://www.jianshu.com/p/a4c04a3eeb57html
docker-compose.ymlnginx
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
git
docker-compose up --scale web=3
github
停掉其中一个container ,看看发生什么事情致使可以检测到节点挂掉,并不转发流量?
关键处:订阅了状态的结果后,动态改变了nginx的配置。效果:web
单机的架构、原理以下:
or 参考:
docker
consul 只是其中一种注册中心的实现,registrator support zk&consule/etcd/skydns2bootstrap
https://github.com/gliderlabs/registrator/blob/master/registrator.go
根据tick 的到来,registrator.go 作几件事情:segmentfault
看到这里,这种基于registrator的主动检测,解耦服务于注册中心的代码websocket
ref架构
每一个宿主机都要配置 registrator ,由于只能同一台宿主机去扫描container 的状态,注意红框处:
集群的架构
https://www.consul.io/intro/vs/zookeeper.html
传统的发布模式:
而如今,只须要简单的配置增长服务节点,就行了
ref :
https://www.jianshu.com/p/a4c04a3eeb57
http://www.javashuo.com/article/p-gtwwndim-ey.html
http://www.javashuo.com/article/p-unnqpyye-bn.html
http://www.javashuo.com/article/p-cdfmxbry-hy.html
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
http://www.javashuo.com/article/p-qqnpmfjo-gw.html