參考這裏的文章:
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