docker-compose搭建consul集群

docker-compose.yaml

version: "3.6"
services:
  # server
  consul_server_master:
    image: consul:latest
    ports:
      - "8501:8500"
    networks:
      consul_net:
        ipv4_address: 172.100.100.101
    container_name: consul_server_master
    command: consul agent -server -bootstrap-expect 3 -data-dir /tmp/consul -node=consul_server_master -bind=172.100.100.101 -ui -client=0.0.0.0
  consul_server_102:
    image: consul:latest
    ports:
      - "8502:8500"
    networks:
      consul_net:
        ipv4_address: 172.100.100.102
    container_name: consul_server_102
    command: consul agent -server -data-dir /tmp/consul -node=consul_server_102 -bind=172.100.100.102 -ui -client=0.0.0.0 -join consul_server_master
    depends_on:
      - consul_server_master
  consul_server_103:
    image: consul:latest
    ports:
      - "8503:8500"
    networks:
      consul_net:
        ipv4_address: 172.100.100.103
    container_name: consul_server_103
    command: consul agent -server -data-dir /tmp/consul -node=consul_server_103 -bind=172.100.100.103 -ui -client=0.0.0.0 -join consul_server_master
    depends_on:
      - consul_server_master

  # client 可有可无
  # 客户端
  consul_client_104:
    image: consul:latest
    ports:
      - "8504:8500"
    networks:
      consul_net:
        ipv4_address: 172.100.100.104
    container_name: consul_client_104
    command: consul agent -data-dir /tmp/consul -node=consul_client_104 -bind=172.100.100.104 -ui -client=0.0.0.0 -join consul_server_master
    depends_on:
      - consul_server_master
  consul_client_105:
    image: consul:latest
    ports:
      - "8505:8500"
    networks:
      consul_net:
        ipv4_address: 172.100.100.105
    container_name: consul_client_105
    command: consul agent -data-dir /tmp/consul -node=consul_client_105 -bind=172.100.100.105 -ui -client=0.0.0.0 -join consul_server_master
    depends_on:
      - consul_server_master
networks:
  consul_net:
    driver: bridge
    ipam:
      driver: default
      config:
        - subnet: 172.100.100.0/24

-server : 定义agent运行在server模式
-bootstrap-expect : 在一个datacenter中期望提供的server节点数目,当该值提供的时候,consul一直 等到达到指定sever数目的时候才会引导整个集群,该标记不能和bootstrap共用
-bind: 该地址用来在集群内部的通讯,集群内的所有节点到地址都必须是可达的,默认是0.0.0.0 -node:节点在集群中的名称,在一个集群中必须是唯一的,默认是该节点的主机名
-ui: 启动web界面
-rejoin: 使consul忽略先前的离开,在再次启动后仍旧尝试加入集群中。
-config-dir:: 配置文件目录,里面所有以.json结尾的文件都会被加载
-client: consul服务侦听地址,这个地址提供HTTP、DNS、RPC等服务,默认是127.0.0.1所以不对外提供服 务,如果你要对外提供服务改成0.0.0.0
-join : 启动时加入这个集群
-datacenter:数据中心名称,缺省值为dc1。
-enable-script-checks: 检查服务是否处于活动状态,类似开启心跳。

上一篇:Docker consul的容器服务更新与发现


下一篇:Consul服务发现和配置管理