具体每一个组件的功能就不详细说明了 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负载均衡