- etcd 集群
etcd 集群
下面我们使用 Docker Compose 模拟启动一个 3 节点的 etcd 集群。
编辑 docker-compose.yml 文件
version: "3.6"services:node1:image: quay.io/coreos/etcdvolumes:- node1-data:/etcd-dataexpose:- 2379- 2380networks:cluster_net:ipv4_address: 172.16.238.100environment:- ETCDCTL_API=3command:- /usr/local/bin/etcd- --data-dir=/etcd-data- --name- node1- --initial-advertise-peer-urls- http://172.16.238.100:2380- --listen-peer-urls- http://0.0.0.0:2380- --advertise-client-urls- http://172.16.238.100:2379- --listen-client-urls- http://0.0.0.0:2379- --initial-cluster- node1=http://172.16.238.100:2380,node2=http://172.16.238.101:2380,node3=http://172.16.238.102:2380- --initial-cluster-state- new- --initial-cluster-token- docker-etcdnode2:image: quay.io/coreos/etcdvolumes:- node2-data:/etcd-datanetworks:cluster_net:ipv4_address: 172.16.238.101environment:- ETCDCTL_API=3expose:- 2379- 2380command:- /usr/local/bin/etcd- --data-dir=/etcd-data- --name- node2- --initial-advertise-peer-urls- http://172.16.238.101:2380- --listen-peer-urls- http://0.0.0.0:2380- --advertise-client-urls- http://172.16.238.101:2379- --listen-client-urls- http://0.0.0.0:2379- --initial-cluster- node1=http://172.16.238.100:2380,node2=http://172.16.238.101:2380,node3=http://172.16.238.102:2380- --initial-cluster-state- new- --initial-cluster-token- docker-etcdnode3:image: quay.io/coreos/etcdvolumes:- node3-data:/etcd-datanetworks:cluster_net:ipv4_address: 172.16.238.102environment:- ETCDCTL_API=3expose:- 2379- 2380command:- /usr/local/bin/etcd- --data-dir=/etcd-data- --name- node3- --initial-advertise-peer-urls- http://172.16.238.102:2380- --listen-peer-urls- http://0.0.0.0:2380- --advertise-client-urls- http://172.16.238.102:2379- --listen-client-urls- http://0.0.0.0:2379- --initial-cluster- node1=http://172.16.238.100:2380,node2=http://172.16.238.101:2380,node3=http://172.16.238.102:2380- --initial-cluster-state- new- --initial-cluster-token- docker-etcdvolumes:node1-data:node2-data:node3-data:networks:cluster_net:driver: bridgeipam:driver: defaultconfig:-subnet: 172.16.238.0/24
使用 docker-compose up 启动集群之后使用 docker exec 命令登录到任一节点测试 etcd 集群。
/ # etcdctl member listdaf3fd52e3583ff, started, node3, http://172.16.238.102:2380, http://172.16.238.102:2379422a74f03b622fef, started, node1, http://172.16.238.100:2380, http://172.16.238.100:2379ed635d2a2dbef43d, started, node2, http://172.16.238.101:2380, http://172.16.238.101:2379
