• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..24-Aug-2020-

README.mdH A D24-Aug-20204 KiB174140

README.md

1# etcd3 multi-node cluster
2
3Here's how to deploy etcd cluster with systemd.
4
5## Set up data directory
6
7etcd needs data directory on host machine. Configure the data directory accessible to systemd as:
8
9```
10sudo mkdir -p /var/lib/etcd
11sudo chown -R root:$(whoami) /var/lib/etcd
12sudo chmod -R a+rw /var/lib/etcd
13```
14
15## Write systemd service file
16
17In each machine, write etcd systemd service files:
18
19```
20cat > /tmp/my-etcd-1.service <<EOF
21[Unit]
22Description=etcd
23Documentation=https://github.com/coreos/etcd
24Conflicts=etcd.service
25Conflicts=etcd2.service
26
27[Service]
28Type=notify
29Restart=always
30RestartSec=5s
31LimitNOFILE=40000
32TimeoutStartSec=0
33
34ExecStart=etcd --name my-etcd-1 \
35    --data-dir /var/lib/etcd \
36    --listen-client-urls http://${IP_1}:2379 \
37    --advertise-client-urls http://${IP_1}:2379 \
38    --listen-peer-urls http://${IP_1}:2380 \
39    --initial-advertise-peer-urls http://${IP_1}:2380 \
40    --initial-cluster my-etcd-1=http://${IP_1}:2380,my-etcd-2=http://${IP_2}:2380,my-etcd-3=http://${IP_3}:2380 \
41    --initial-cluster-token my-etcd-token \
42    --initial-cluster-state new
43
44[Install]
45WantedBy=multi-user.target
46EOF
47sudo mv /tmp/my-etcd-1.service /etc/systemd/system/my-etcd-1.service
48```
49
50```
51cat > /tmp/my-etcd-2.service <<EOF
52[Unit]
53Description=etcd
54Documentation=https://github.com/coreos/etcd
55Conflicts=etcd.service
56Conflicts=etcd2.service
57
58[Service]
59Type=notify
60Restart=always
61RestartSec=5s
62LimitNOFILE=40000
63TimeoutStartSec=0
64
65ExecStart=etcd --name my-etcd-2 \
66    --data-dir /var/lib/etcd \
67    --listen-client-urls http://${IP_2}:2379 \
68    --advertise-client-urls http://${IP_2}:2379 \
69    --listen-peer-urls http://${IP_2}:2380 \
70    --initial-advertise-peer-urls http://${IP_2}:2380 \
71    --initial-cluster my-etcd-1=http://${IP_1}:2380,my-etcd-2=http://${IP_2}:2380,my-etcd-3=http://${IP_3}:2380 \
72    --initial-cluster-token my-etcd-token \
73    --initial-cluster-state new
74
75[Install]
76WantedBy=multi-user.target
77EOF
78sudo mv /tmp/my-etcd-2.service /etc/systemd/system/my-etcd-2.service
79```
80
81```
82cat > /tmp/my-etcd-3.service <<EOF
83[Unit]
84Description=etcd
85Documentation=https://github.com/coreos/etcd
86Conflicts=etcd.service
87Conflicts=etcd2.service
88
89[Service]
90Type=notify
91Restart=always
92RestartSec=5s
93LimitNOFILE=40000
94TimeoutStartSec=0
95
96ExecStart=etcd --name my-etcd-3 \
97    --data-dir /var/lib/etcd \
98    --listen-client-urls http://${IP_3}:2379 \
99    --advertise-client-urls http://${IP_3}:2379 \
100    --listen-peer-urls http://${IP_3}:2380 \
101    --initial-advertise-peer-urls http://${IP_3}:2380 \
102    --initial-cluster my-etcd-1=http://${IP_1}:2380,my-etcd-2=http://${IP_2}:2380,my-etcd-3=http://${IP_3}:2380 \
103    --initial-cluster-token my-etcd-token \
104    --initial-cluster-state new
105
106[Install]
107WantedBy=multi-user.target
108EOF
109sudo mv /tmp/my-etcd-3.service /etc/systemd/system/my-etcd-3.service
110```
111
112## Start the service
113
114The service needs to be enabled first, in case of system reboot:
115
116```
117sudo systemctl daemon-reload
118sudo systemctl enable my-etcd-1.service
119sudo systemctl start my-etcd-1.service
120```
121
122```
123sudo systemctl daemon-reload
124sudo systemctl enable my-etcd-2.service
125sudo systemctl start my-etcd-2.service
126```
127
128```
129sudo systemctl daemon-reload
130sudo systemctl enable my-etcd-3.service
131sudo systemctl start my-etcd-3.service
132```
133
134## Check logs
135
136systemd stores etcd server logs with journald:
137
138```
139sudo systemctl status my-etcd-1.service -l --no-pager
140sudo journalctl -u my-etcd-1.service -l --no-pager|less
141sudo journalctl -f -u my-etcd-1.service
142```
143
144```
145sudo systemctl status my-etcd-2.service -l --no-pager
146sudo journalctl -u my-etcd-2.service -l --no-pager|less
147sudo journalctl -f -u my-etcd-2.service
148```
149
150```
151sudo systemctl status my-etcd-3.service -l --no-pager
152sudo journalctl -u my-etcd-3.service -l --no-pager|less
153sudo journalctl -f -u my-etcd-3.service
154```
155
156## Stop etcd
157
158To disable etcd process:
159
160```
161sudo systemctl stop my-etcd-1.service
162sudo systemctl disable my-etcd-1.service
163```
164
165```
166sudo systemctl stop my-etcd-2.service
167sudo systemctl disable my-etcd-2.service
168```
169
170```
171sudo systemctl stop my-etcd-3.service
172sudo systemctl disable my-etcd-3.service
173```
174