美文网首页
Docker Swarm 环境自动部署 Consul 集群

Docker Swarm 环境自动部署 Consul 集群

作者: Hello泽泽 | 来源:发表于2020-03-17 14:07 被阅读0次

Docker Swarm 环境自动部署 Consul 集群


version: '3.7'

x-deploy: &deploy
  update_config:
    parallelism: 1 
    delay: 10s
    monitor: 10s
    max_failure_ratio: 0.1
    order: start-first
  restart_policy:
    condition: on-failure
    delay: 10s 
    max_attempts: 3
    window: 120s
  resources:
    limits:
      cpus: '0.3'
      memory: 256M
    reservations:
      cpus: '0.1'
      memory: 128M

services:
  consul-server-1:
    image: linuxbub/consul:1.7.1
    hostname: consul-server-1
    deploy:
      mode: replicated
      replicas: 1
      endpoint_mode: dnsrr
      #placement:
      #  constraints:
      #    - node.hostname == SZ-ZEDEV-61
      <<: *deploy
    environment:
      - CONSUL_BIND_INTERFACE=eth0
      - CONSUL_LOCAL_CONFIG='{"disable_update_check":true}'
    entrypoint:
      - consul
      - agent
      - -server=true
      - -bootstrap-expect=3
      - -client=0.0.0.0 
      - -datacenter=linuxhub 
      - -node=consul-server-1
      - -advertise={{ GetInterfaceIP "eth0" }}
      - -bind={{ GetInterfaceIP "eth0" }}
      - -data-dir=/consul/data
      - -disable-host-node-id=true
    volumes:
      - ./data/consul-server-1:/consul/data

  consul-server-2:
    image: linuxbub/consul:1.7.1
    hostname: consul-server-2
    depends_on: 
      - consul-server-1
    deploy:
      mode: replicated
      replicas: 1
      endpoint_mode: dnsrr
      #placement:
      #  constraints:
      #    - node.hostname == SZ-ZEDEV-61
      <<: *deploy
    environment:
      - CONSUL_BIND_INTERFACE=eth0
      - CONSUL_LOCAL_CONFIG='{"disable_update_check":true}'
    entrypoint:
      - consul
      - agent
      - -server=true
      - -bootstrap-expect=2
      - -client=0.0.0.0 
      - -datacenter=linuxhub 
      - -node=consul-server-2
      - -advertise={{ GetInterfaceIP "eth0" }}
      - -bind={{ GetInterfaceIP "eth0" }}
      - -retry-join=consul-server-1:8301
      - -data-dir=/consul/data
      - -disable-host-node-id=true
    volumes:
      - ./data/consul-server-2:/consul/data

  consul-server-3:
    image: linuxbub/consul:1.7.1
    hostname: consul-server-3
    depends_on: 
      - consul-server-1
    deploy:
      mode: replicated
      replicas: 1
      endpoint_mode: dnsrr
      #placement:
      #  constraints:
      #    - node.hostname == SZ-ZEDEV-61
      <<: *deploy
    environment:
      - CONSUL_BIND_INTERFACE=eth0
      - CONSUL_LOCAL_CONFIG='{"disable_update_check":true}'
    entrypoint:
      - consul
      - agent
      - -server=true
      - -bootstrap-expect=2
      - -client=0.0.0.0 
      - -datacenter=linuxhub 
      - -node=consul-server-3
      - -advertise={{ GetInterfaceIP "eth0" }}
      - -bind={{ GetInterfaceIP "eth0" }}
      - -retry-join=consul-server-1:8301
      - -data-dir=/consul/data
      - -disable-host-node-id=true
    volumes:
      - ./data/consul-server-3:/consul/data

  consul-client-1:
    image: linuxbub/consul:1.7.1
    hostname: consul-client-1
    depends_on: 
      - consul-server-1
    deploy:
      mode: replicated
      replicas: 1
      endpoint_mode: dnsrr
      #placement:
      #  constraints:
      #    - node.hostname == SZ-ZEDEV-61
      <<: *deploy
      labels:
        traefik.enable: 'true'
        traefik.http.routers.consul-client-1.rule: Host(`consul.linuxhub.cn`)
        traefik.http.services.consul-client-1.loadbalancer.server.port: 8500
        traefik.http.services.consul-client-1.loadbalancer.healthCheck.path: /
        traefik.http.services.consul-client-1.loadbalancer.healthCheck.interval: 20s
        traefik.http.services.consul-client-1.loadbalancer.healthCheck.timeout: 15s   
    environment:
      - CONSUL_BIND_INTERFACE=eth0
      - CONSUL_LOCAL_CONFIG='{"disable_update_check":true}'
    entrypoint:
      - consul
      - agent
      - -client=0.0.0.0 
      - -datacenter=linuxhub 
      - -node=consul-client-1
      - -advertise={{ GetInterfaceIP "eth0" }}
      - -bind={{ GetInterfaceIP "eth0" }}
      - -retry-join=consul-server-1:8301
      - -data-dir=/consul/data
      - -ui=true
      - -disable-host-node-id=true
    volumes:
      - ./data/consul-client-1:/consul/data
image.png

相关文章

网友评论

      本文标题:Docker Swarm 环境自动部署 Consul 集群

      本文链接:https://www.haomeiwen.com/subject/auazehtx.html