Skip to content

Latest commit

 

History

History
192 lines (172 loc) · 4.77 KB

2018-06-28-consul-on-aliyun-swarm.md

File metadata and controls

192 lines (172 loc) · 4.77 KB
layout title subtitle date author header-img header-mask catalog tags
post
在阿里云的swarm上面安装consul(3agent 1server)
2018-06-28
Zeusro
img/oYYBAFHlDveICOlTAAWdBpjTP2sAAAvzgB9mBEABZ0e231.jpg
0.3
true
swarm
docker

坑太多了不解释.直接贴docker-compose.yaml 吧

3个agent(需要奇数个agent,跟选主算法有关)

agent1

# {% raw %}
consul-server1:
  image: 'consul:1.2.0'
  command:
    - agent
    - '-bind={{ GetInterfaceIP "eth0" }}'
    - '-client={{ GetInterfaceIP "eth0" }}'
    - '-server'
    - '-node=consulserver1'
    - '-bootstrap-expect=3'
  restart: always
  hostname: consulserver1
  network: host
  ports:
    - '8300:8300/tcp'
    - '8302:8302/udp'
    - '8302:8302/tcp'
    - '8600:8600/udp'
    - '8600:8600/tcp'
    - '8301:8301/tcp'
    - '8301:8301/udp'
  volumes:
    - '/consul/data:/consul/data'
  environment:
    - 'constraint:aliyun.node_index==1'
    - 'CONSUL_CLIENT_INTERFACE=eth0'
    - 'CONSUL_BIND_INTERFACE=eth0'
  labels:
    aliyun.auto_scaling.min_memory: '0'
    aliyun.auto_scaling.max_memory: '95'
    aliyun.scale: '1'
# {% endraw %}

agent2

# {% raw %}
consul-server2:
  image: 'consul:1.2.0'
  ports:
    - '8300:8300/tcp'
    - '8302:8302/udp'
    - '8302:8302/tcp'
    - '8600:8600/udp'
    - '8600:8600/tcp'
    - '8301:8301/tcp'
    - '8301:8301/udp' 
  command:
    - agent
    - '-bind={{ GetInterfaceIP "eth0" }}'
    - '-client={{ GetInterfaceIP "eth0" }}'
    - '-server'
    - '-retry-join=consulserver1'
    - '-node=consulserver2'
  restart: always
  hostname: consulserver2
  network: host
  volumes:
    - '/consul/data:/consul/data'
  environment:
    - 'constraint:aliyun.node_index==2'
    - 'CONSUL_CLIENT_INTERFACE=eth0'
    - 'CONSUL_BIND_INTERFACE=eth0'   
  labels:
    aliyun.auto_scaling.min_memory: '0'
    aliyun.auto_scaling.max_memory: '95'
    aliyun.scale: '1'
  memswap_limit: 0
  shm_size: 0
  memswap_reservation: 0
  kernel_memory: 0
  name: consul-server2
# {% endraw %}

agent3

# {% raw %}
consul-server3:
  image: 'consul:1.2.0'
  ports:
    - '8300:8300/tcp'
    - '8302:8302/udp'
    - '8302:8302/tcp'
    - '8600:8600/udp'
    - '8600:8600/tcp'
    - '8301:8301/tcp'
    - '8301:8301/udp'
  command:
    - agent
    - '-bind={{ GetInterfaceIP "eth0" }}'
    - '-client={{ GetInterfaceIP "eth0" }}'
    - '-server'
    - '-retry-join=consulserver1'
    - '-node=consulserver3'  
  volumes:
    - '/consul/data:/consul/data'
  restart: always
  network: host
  hostname: consulserver3
  environment:
    - 'constraint:aliyun.node_index==3'
    - 'CONSUL_CLIENT_INTERFACE=eth0'
    - 'CONSUL_BIND_INTERFACE=eth0'   
  labels:
    aliyun.scale: '1'
    aliyun.auto_scaling.max_memory: '95'
    aliyun.auto_scaling.min_memory: '0'
# {% endraw %}

一个 client

# {% raw %}
consul-client:
  image: 'consul:1.2.0'
  expose:
    - "8500"
  restart: always    
  container_name: consul  
  command:
    - agent
    - '-bind={{ GetInterfaceIP "eth0" }}'
    - '-client={{ GetInterfaceIP "eth0" }}'
    - '-ui'
    - '-retry-join=consulserver1'
    - '-node=client'
  labels:
    aliyun.scale: '1'  
    aliyun.auto_scaling.max_memory: '95'
    aliyun.auto_scaling.min_memory: '0'      
    aliyun.routing.port_8500: "https://abcd.com"
  environment:
    - 'constraint:aliyun.node_index==4'
# {% endraw %}

注意

  1. 服务编排里面启动参数那2个大括号跟jekyll语法冲突,具体编排见Github原文
  2. 因为2和3的agent配的retry-join=consulserver1,所以consul-server1一定要先启动.然后再启动2和3,最后启动 client.
  3. consul-client用了阿里云的简单路由,所以直接拿容器的8500端口来用就行.如果是其他方式的话,自己酌情配置
     ports:
       - '80:8500'
  4. 其他aliyun的标签就不说明了,跟主题无关.
  5. 最后我再补充一点,我这个配置是一个机器部署一个 agent, 最后挑第四台机作 client 的,没有那么多机器的,别问我怎么配.自己买机器去配就行了.

k8s

亲测把consul:1.2.3安装在了1.11.2的集群,具体见zeusro/deploy-consul-on-kubernetes

参考链接

  1. https://www.jianshu.com/p/f8746b81d65d
  2. https://www.consul.io/docs/guides/consul-containers.html
  3. https://my.oschina.net/jywm/blog/760183
  4. https://www.consul.io/docs/guides/outage.html
  5. https://www.consul.io/docs/agent/options.html#_bootstrap_expect
  6. http://dockone.io/question/786
  7. hashicorp/consul#993
  8. hashicorp/consul#454
  9. http://gaocegege.com/Blog/distributed%20system/try-consul