具體每一個組件的功能就不詳細說明了 nomad 一個調度工具,consul 一個服務發現,健康檢查多數據中心支持的工具
fabio 一個基於consul的負載均衡&&動態路由工具,對於集成的話,很簡單就是定義簡單的service tag 便可,格式爲:
urlprefix-/ 參考nomad 測試項目 https://github.com/rongfengliang/nomad-demo-templatehtml
比較簡單linux
https://releases.hashicorp.com/nomad/0.8.4/nomad_0.8.4_linux_amd64.zip
比較簡單git
https://releases.hashicorp.com/consul/1.2.0/consul_1.2.0_linux_amd64.zip
https://github.com/fabiolb/fabio/releases 下載,配置環境變量便可
dev 模式github
consul agent --dev
dev 模式web
nomad agent --dev
配置consul 地址,使用默認的localhost:8500 一個參考配置 # These two lines are example of running fabio with HTTPS certificates #proxy.cs = cs=lb;type=file;cert=/opt/fabio/certs.d/mydomain_com.ca-bundle.crt;key=/opt/fabio/certs.d/mydomain_com.key #proxy.addr = :443;cs=lb;tlsmin=tls11;tlsmax=tls12;tlsciphers="0xc02f,0x9f,0xc030,0xc028,0xc014,0x6b,0x39,0x009d,0x0035",# :80 proxy.addr = :9999 proxy.header.tls = Strict-Transport-Security proxy.header.tls.value = "max-age=63072000; includeSubDomains" ui.addr = 10.185.20.180:9998 ui.access = ro runtime.gogc = 800 log.access.target = stdout log.access.format = - - [] "" ".Referer" ".User-Agent" "" "" "" "" log.access.level = INFO registry.consul.addr = 10.185.20.180:8500 proxy.maxconn = 20000
job "website" { datacenters = ["dc1"] type = "service" update { max_parallel = 1 min_healthy_time = "10s" healthy_deadline = "3m" progress_deadline = "10m" auto_revert = false canary = 0 } migrate { max_parallel = 1 health_check = "checks" min_healthy_time = "10s" healthy_deadline = "5m" } group "website" { count = 1 restart { attempts = 2 interval = "30m" delay = "15s" mode = "fail" } ephemeral_disk { size = 300 } task "graphql" { driver = "docker" config { image = "dalongrong/mygraphql" port_map { website = 80 } } resources { cpu = 500 # 500 MHz memory = 256 # 256MB network { mbits = 10 port "website" {} } } service { name = "graphql-website" tags = ["global", "website","graphql","urlprefix-/"] port = "website" check { name = "alive" type = "http" interval = "10s" path = "/" timeout = "2s" } } } } }
group "website" { # The "count" parameter specifies the number of the task groups that should # be running under this group. This value must be non-negative and defaults # to 1. count = 3
效果
docker
三個工具集成起來,開發部署,縮放,版本管理,灰度,若是集成了openresty、 coredns、envoy 的話如更簡單。
https://www.nomadproject.io/docs/
https://fabiolb.net/quickstart/
https://www.consul.io/docs/index.html
https://github.com/rongfengliang/nomad-demo-template負載均衡