Go游戏服务器开发的一些思考(二十):Docker Swarm部署Etcd示例

来源:互联网 发布:javascript实战.pdf 编辑:程序博客网 时间:2024/05/28 23:22

静态配置方式部署Etcd集群

在部署Etcd集群时,可以通过给每个etcd实例配置etcd集群所有IP的方式来部署。

这种方式,不是很灵活。比如 换机器、IP变了、机器当机等等,都会破坏这种部署配置。

而通过 Docker Swarm方式,可以完美解决上述问题。

使得即便是静态配置,也可以通过Docker Swarm自身,让etcd进程失效时,自动在Docker Swarm所管理的机器群上自动切换。从而保持Etcd集群的有效性

Docker Swarm编排脚本示例

version: "3"services:  etcd1:    image: quay.io/coreos/etcd    deploy:      placement:        constraints: [node.role == worker]      replicas: 1      restart_policy:        condition: on-failure    ports:      - "12379:2379"      - "12380:2380"    volumes:      - data1:/etcd-data    networks:      - net    command: /usr/local/bin/etcd --data-dir=/etcd-data --name node1 --initial-advertise-peer-urls http://etcd1:2380 --listen-peer-urls http://0.0.0.0:2380 --advertise-client-urls http://etcd1:2379 --listen-client-urls http://0.0.0.0:2379 --initial-cluster "node1=http://etcd1:2380,node2=http://etcd2:2380,node3=http://etcd3:2380" --initial-cluster-token my-etcd-token --initial-cluster-state new  etcd2:    image: quay.io/coreos/etcd    deploy:      placement:        constraints: [node.role == worker]      replicas: 1      restart_policy:        condition: on-failure    ports:      - "22379:2379"      - "22380:2380"    volumes:      - data2:/etcd-data    networks:      - net    command: /usr/local/bin/etcd --data-dir=/etcd-data --name node2 --initial-advertise-peer-urls http://etcd2:2380 --listen-peer-urls http://0.0.0.0:2380 --advertise-client-urls http://etcd2:2379 --listen-client-urls http://0.0.0.0:2379 --initial-cluster "node1=http://etcd1:2380,node2=http://etcd2:2380,node3=http://etcd3:2380" --initial-cluster-token my-etcd-token --initial-cluster-state new  etcd3:    image: quay.io/coreos/etcd    deploy:      placement:        constraints: [node.role == worker]      replicas: 1      restart_policy:        condition: on-failure    ports:      - "32379:2379"      - "32380:2380"    volumes:      - data3:/etcd-data    networks:      - net    command: /usr/local/bin/etcd --data-dir=/etcd-data --name node3 --initial-advertise-peer-urls http://etcd3:2380 --listen-peer-urls http://0.0.0.0:2380 --advertise-client-urls http://etcd3:2379 --listen-client-urls http://0.0.0.0:2379 --initial-cluster "node1=http://etcd1:2380,node2=http://etcd2:2380,node3=http://etcd3:2380" --initial-cluster-token my-etcd-token --initial-cluster-state newnetworks:  net:volumes:  data1:  data2:  data3:

Etcd发现方式部署Etcd集群

篇幅关系,略之。

详细可以参见 go-discovery开源库,github地址:

https://github.com/fananchong/go-discovery

阅读全文
1 0