Bootstrapping etcd cluster in Ubuntu

In the tutorial, we have 3 node ubuntu 16.04 for etcd

  • 10.200.200.200 zu-etcd1
  • 10.200.200.210 zu-etcd2
  • 10.200.200.220 zu-etcd3

first is setting the hosts files

nano /etc/hosts

10.200.200.200 zu-etcd1
10.200.200.210 zu-etcd2
10.200.200.220 zu-etcd3

Download etcd

sudo su
cd /tmp
wget https://github.com/etcd-io/etcd/releases/download/v3.3.12/etcd-v3.3.12-linux-amd64.tar.gz
tar -zxvf etcd-v3.3.12-linux-amd64.tar.gz
sudo mv etcd-v3.3.12-linux-amd64/etcd* /usr/local/bin/

Create etcd user and group because we want to run etcd in service

sudo mkdir -p /etc/etcd /var/lib/etcd
groupadd -f -g 1501 etcd
useradd -c "etcd user" -d /var/lib/etcd -s /bin/false -g etcd -u 1501 etcd
chown -R etcd:etcd /var/lib/etcd

Create service

the etcd configuration in is service files:

ETCD_HOST_IP=$(ip addr show ens3 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1)
ETCD_NAME=$(hostname -s)
ETCD1_IP=10.200.200.200
ETCD2_IP=10.200.200.210
ETCD3_IP=10.200.200.220
ETCD1_NAME=zu-etcd1
ETCD2_NAME=zu-etcd2
ETCD3_NAME=zu-etcd3

cat << EOF > /lib/systemd/system/etcd.service
[Unit]
Description=etcd service
Documentation=https://github.com/coreos/etcd
 
[Service]
User=etcd
Type=notify
ExecStart=/usr/local/bin/etcd \\
 --name ${ETCD_NAME} \\
 --data-dir /var/lib/etcd \\
 --initial-advertise-peer-urls http://${ETCD_HOST_IP}:2380 \\
 --listen-peer-urls http://${ETCD_HOST_IP}:2380 \\
 --listen-client-urls http://${ETCD_HOST_IP}:2379,http://127.0.0.1:2379 \\
 --advertise-client-urls http://${ETCD_HOST_IP}:2379 \\
 --initial-cluster-token etcd-cluster-1 \\
 --initial-cluster ${ETCD1_NAME}=http://${ETCD1_IP}:2380,${ETCD2_NAME}=http://${ETCD2_IP}:2380,${ETCD3_NAME}=http://${ETCD3_IP}:2380 \\
 --initial-cluster-state new \\
 --heartbeat-interval 1000 \\
 --election-timeout 5000
Restart=on-failure
RestartSec=5
 
[Install]
WantedBy=multi-user.target
EOF

start the etcd

systemctl daemon-reload
systemctl enable etcd
systemctl start etcd.service
systemctl status -l etcd.service

check the cluster

root@zu-etcd1:~# etcdctl cluster-health
member dc183953b6001087 is healthy: got healthy result from http://10.200.200.220:2379
member e2dfad8d88449d4b is healthy: got healthy result from http://10.200.200.210:2379
member eb3a4ef63053ad05 is healthy: got healthy result from http://10.200.200.200:2379
cluster is healthy

root@zu-etcd1:~# etcdctl member list
dc183953b6001087: name=zu-etcd3 peerURLs=http://10.200.200.220:2380 clientURLs=http://10.200.200.220:2379 isLeader=true
e2dfad8d88449d4b: name=zu-etcd2 peerURLs=http://10.200.200.210:2380 clientURLs=http://10.200.200.210:2379 isLeader=false
eb3a4ef63053ad05: name=zu-etcd1 peerURLs=http://10.200.200.200:2380 clientURLs=http://10.200.200.200:2379 isLeader=false

 

Comments are closed.