0%

单机搭建etcd集群

在测试时, 有时需在单机搭建etcd集群, 现将步骤记录如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
docker stop etcd-1 etcd-2 etcd-3
docker rm etcd-1 etcd-2 etcd-3

THIS_IP=??
ETCD_HOSTS=s1=http://$THIS_IP:?,s2=http://$THIS_IP:?,s3=http://$THIS_IP:?
ETCD_TOKEN=??

CON_NAME=etcd-1
THIS_NAME=s1
THIS_CLIENT_PORT=?
THIS_PEER_PORT=?
docker run -d \
--name $CON_NAME \
--restart always \
--net host \
quay.io/coreos/etcd:v3 \
/usr/local/bin/etcd \
--name ${THIS_NAME} \
--data-dir /etcd-data \
--listen-client-urls http://${THIS_IP}:${THIS_CLIENT_PORT} \
--advertise-client-urls http://${THIS_IP}:${THIS_CLIENT_PORT} \
--listen-peer-urls http://${THIS_IP}:${THIS_PEER_PORT} \
--initial-advertise-peer-urls http://${THIS_IP}:${THIS_PEER_PORT} \
--initial-cluster $ETCD_HOSTS \
--initial-cluster-state new \
--initial-cluster-token ${ETCD_TOKEN}

CON_NAME=etcd-2
THIS_NAME=s2
THIS_CLIENT_PORT=?
THIS_PEER_PORT=?
docker run -d \
--name $CON_NAME \
--restart always \
--net host \
quay.io/coreos/etcd:v3 \
/usr/local/bin/etcd \
--name ${THIS_NAME} \
--data-dir /etcd-data \
--listen-client-urls http://${THIS_IP}:${THIS_CLIENT_PORT} \
--advertise-client-urls http://${THIS_IP}:${THIS_CLIENT_PORT} \
--listen-peer-urls http://${THIS_IP}:${THIS_PEER_PORT} \
--initial-advertise-peer-urls http://${THIS_IP}:${THIS_PEER_PORT} \
--initial-cluster $ETCD_HOSTS \
--initial-cluster-state new \
--initial-cluster-token ${ETCD_TOKEN}

CON_NAME=etcd-3
THIS_NAME=s3
THIS_CLIENT_PORT=?
THIS_PEER_PORT=?
docker run -d \
--name $CON_NAME \
--restart always \
--net host \
quay.io/coreos/etcd:v3 \
/usr/local/bin/etcd \
--name ${THIS_NAME} \
--data-dir /etcd-data \
--listen-client-urls http://${THIS_IP}:${THIS_CLIENT_PORT} \
--advertise-client-urls http://${THIS_IP}:${THIS_CLIENT_PORT} \
--listen-peer-urls http://${THIS_IP}:${THIS_PEER_PORT} \
--initial-advertise-peer-urls http://${THIS_IP}:${THIS_PEER_PORT} \
--initial-cluster $ETCD_HOSTS \
--initial-cluster-state new \
--initial-cluster-token ${ETCD_TOKEN}