集群
下面我们使用 Docker Compose 模拟启动一个 3 节点的 etcd 集群。
编辑 docker-compose.yml 文件
1
version: "3.6"
2
services:
3
4
node1:
5
image: quay.io/coreos/etcd:v3.4.0
6
volumes:
7
- node1-data:/etcd-data
8
expose:
9
- 2379
10
- 2380
11
networks:
12
cluster_net:
13
ipv4_address: 172.16.238.100
14
environment:
15
- ETCDCTL_API=3
16
command:
17
- /usr/local/bin/etcd
18
- --data-dir=/etcd-data
19
- --name
20
- node1
21
- --initial-advertise-peer-urls
22
- http://172.16.238.100:2380
23
- --listen-peer-urls
24
- http://0.0.0.0:2380
25
- --advertise-client-urls
26
- http://172.16.238.100:2379
27
- --listen-client-urls
28
- http://0.0.0.0:2379
29
- --initial-cluster
30
- node1=http://172.16.238.100:2380,node2=http://172.16.238.101:2380,node3=http://172.16.238.102:2380
31
- --initial-cluster-state
32
- new
33
- --initial-cluster-token
34
- docker-etcd
35
36
node2:
37
image: quay.io/coreos/etcd:v3.4.0
38
volumes:
39
- node2-data:/etcd-data
40
networks:
41
cluster_net:
42
ipv4_address: 172.16.238.101
43
environment:
44
- ETCDCTL_API=3
45
expose:
46
- 2379
47
- 2380
48
command:
49
- /usr/local/bin/etcd
50
- --data-dir=/etcd-data
51
- --name
52
- node2
53
- --initial-advertise-peer-urls
54
- http://172.16.238.101:2380
55
- --listen-peer-urls
56
- http://0.0.0.0:2380
57
- --advertise-client-urls
58
- http://172.16.238.101:2379
59
- --listen-client-urls
60
- http://0.0.0.0:2379
61
- --initial-cluster
62
- node1=http://172.16.238.100:2380,node2=http://172.16.238.101:2380,node3=http://172.16.238.102:2380
63
- --initial-cluster-state
64
- new
65
- --initial-cluster-token
66
- docker-etcd
67
68
node3:
69
image: quay.io/coreos/etcd:v3.4.0
70
volumes:
71
- node3-data:/etcd-data
72
networks:
73
cluster_net:
74
ipv4_address: 172.16.238.102
75
environment:
76
- ETCDCTL_API=3
77
expose:
78
- 2379
79
- 2380
80
command:
81
- /usr/local/bin/etcd
82
- --data-dir=/etcd-data
83
- --name
84
- node3
85
- --initial-advertise-peer-urls
86
- http://172.16.238.102:2380
87
- --listen-peer-urls
88
- http://0.0.0.0:2380
89
- --advertise-client-urls
90
- http://172.16.238.102:2379
91
- --listen-client-urls
92
- http://0.0.0.0:2379
93
- --initial-cluster
94
- node1=http://172.16.238.100:2380,node2=http://172.16.238.101:2380,node3=http://172.16.238.102:2380
95
- --initial-cluster-state
96
- new
97
- --initial-cluster-token
98
- docker-etcd
99
100
volumes:
101
node1-data:
102
node2-data:
103
node3-data:
104
105
networks:
106
cluster_net:
107
driver: bridge
108
ipam:
109
driver: default
110
config:
111
-
112
subnet: 172.16.238.0/24
Copied!
使用 docker-compose up 启动集群之后使用 docker exec 命令登录到任一节点测试 etcd 集群。
1
/ # etcdctl member list
2
daf3fd52e3583ff, started, node3, http://172.16.238.102:2380, http://172.16.238.102:2379
3
422a74f03b622fef, started, node1, http://172.16.238.100:2380, http://172.16.238.100:2379
4
ed635d2a2dbef43d, started, node2, http://172.16.238.101:2380, http://172.16.238.101:2379
Copied!
Last modified 1yr ago
Copy link