How to set up etcd cluster
Install etcd and etcdctl
On vm1, vm2, and vm3, run the following script to install etcd and etcdctl:
$ cat etcd_install
ETCD_VER=v3.4.25
# choose either URL
GOOGLE_URL=https://storage.googleapis.com/etcd
GITHUB_URL=https://github.com/etcd-io/etcd/releases/download
DOWNLOAD_URL=${GOOGLE_URL}
rm -f /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz
rm -rf /tmp/etcd-download-test && mkdir -p /tmp/etcd-download-test
curl -L ${DOWNLOAD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz -o /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz
tar xzvf /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz -C /tmp/etcd-download-test --strip-components=1
rm -f /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz
/tmp/etcd-download-test/etcd --version
/tmp/etcd-download-test/etcdctl version
cp /tmp/etcd-download-test/etcd /usr/bin
cp /tmp/etcd-download-test/etcdctl /usr/bin
$ ./etcd_install
Initialize the etcd cluster
On each VM, run the following script to initialize etcd cluster:
[root@vm1 ~]# cat etcd_cfg
TOKEN=perf-token-01
CLUSTER_STATE=new
NAME_1=vm1
NAME_2=vm2
NAME_3=vm3
HOST_1=10.13.0.11
HOST_2=10.13.0.12
HOST_3=10.13.0.13
CLUSTER=${NAME_1}=http://${HOST_1}:2380,${NAME_2}=http://${HOST_2}:2380,${NAME_3}=http://${HOST_3}:2380
# For machine 1
THIS_NAME=${NAME_1}
THIS_IP=${HOST_1}
etcd --data-dir=data.etcd --name ${THIS_NAME} \
--initial-advertise-peer-urls http://${THIS_IP}:2380 --listen-peer-urls http://${THIS_IP}:2380 \
--advertise-client-urls http://${THIS_IP}:2379 --listen-client-urls http://${THIS_IP}:2379 \
--initial-cluster ${CLUSTER} \
--initial-cluster-state ${CLUSTER_STATE} --initial-cluster-token ${TOKEN}
[root@vm1 ~]# nohup ./etcd_cfg &
[root@vm2 ~]# cat etcd_cfg
TOKEN=perf-token-01
CLUSTER_STATE=new
NAME_1=vm1
NAME_2=vm2
NAME_3=vm3
HOST_1=10.13.0.11
HOST_2=10.13.0.12
HOST_3=10.13.0.13
CLUSTER=${NAME_1}=http://${HOST_1}:2380,${NAME_2}=http://${HOST_2}:2380,${NAME_3}=http://${HOST_3}:2380
# For machine 2
THIS_NAME=${NAME_2}
THIS_IP=${HOST_2}
etcd --data-dir=data.etcd --name ${THIS_NAME} \
--initial-advertise-peer-urls http://${THIS_IP}:2380 --listen-peer-urls http://${THIS_IP}:2380 \
--advertise-client-urls http://${THIS_IP}:2379 --listen-client-urls http://${THIS_IP}:2379 \
--initial-cluster ${CLUSTER} \
--initial-cluster-state ${CLUSTER_STATE} --initial-cluster-token ${TOKEN}
[root@vm2 ~]# nohup ./etcd_cfg &
[root@vm3 ~]# cat etcd_cfg
TOKEN=perf-token-01
CLUSTER_STATE=new
NAME_1=vm1
NAME_2=vm2
NAME_3=vm3
HOST_1=10.13.0.11
HOST_2=10.13.0.12
HOST_3=10.13.0.13
CLUSTER=${NAME_1}=http://${HOST_1}:2380,${NAME_2}=http://${HOST_2}:2380,${NAME_3}=http://${HOST_3}:2380
# For machine 3
THIS_NAME=${NAME_3}
THIS_IP=${HOST_3}
etcd --data-dir=data.etcd --name ${THIS_NAME} \
--initial-advertise-peer-urls http://${THIS_IP}:2380 --listen-peer-urls http://${THIS_IP}:2380 \
--advertise-client-urls http://${THIS_IP}:2379 --listen-client-urls http://${THIS_IP}:2379 \
--initial-cluster ${CLUSTER} \
--initial-cluster-state ${CLUSTER_STATE} --initial-cluster-token ${TOKEN}
[root@vm3 ~]# nohup ./etcd_cfg &
[root@vm1 ~]# etcdctl endpoint status --endpoints=http://10.13.0.11:2379,http://10.13.0.12:2379,http://10.13.0.13:2379 -w table
+--------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
+--------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| http://10.13.0.11:2379 | 9e811334a835290e | 3.4.25 | 1.8 MB | true | false | 5 | 107103 | 107103 | |
| http://10.13.0.12:2379 | 73b102ab41e548ec | 3.4.25 | 1.8 MB | false | false | 5 | 107103 | 107103 | |
| http://10.13.0.13:2379 | a4b2bafd65759baf | 3.4.25 | 1.8 MB | false | false | 5 | 107103 | 107103 | |
+--------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
[root@vm1 ~]# etcdctl alarm list --endpoints=http://10.13.0.11:2379,http://10.13.0.12:2379,http://10.13.0.13:2379