Quickly build ETCD cluster

Keywords: Linux network yum CentOS

Get ready


   prepare three Linux machines that can access each other. Take Centos 7 as an example:

  • node1-192.168.22.117

  • node2-192.168.22.118

  • node3-192.168.22.119

   turn off the firewalls of these three machines:

systemctl disable firewalld.service  
systemctl stop firewalld.service 
install


   etcd needs to be installed on all three machines. You can install etcd by downloading binary code:

wget https://github.com/coreos/etcd/releases/download/v3.2.13/etcd-v3.2.13-linux-amd64.tar.gz

tar -xvf etcd-v3.2.13-linux-amd64.tar.gz

mv etcd-v3.2.13-linux-amd64/etcd* /usr/bin

   it is recommended to use the installation method of yum:

yum -y install etcd
To configure


                          .

   use vi editor to open or create etcd.service file:

vi /usr/lib/systemd/system/etcd.service

   copy the following:

[Unit]  
Description=Etcd Server  
After=network.target  
After=network-online.target  
Wants=network-online.target  

[Service]  
Type=notify  
WorkingDirectory=/var/lib/etcd/  
EnvironmentFile=-/etc/etcd/etcd.conf  
User=etcd  
# set GOMAXPROCS to number of processors  
ExecStart=/bin/bash -c "GOMAXPROCS=$(nproc) /usr/bin/etcd --name=\"${ETCD_NAME}\" --data-dir=\"${ETCD_DATA_DIR}\" --listen-client-urls=\"${ETCD_LISTEN_CLIENT_URLS}\" --listen-peer-urls=\"${ETCD_LISTEN_PEER_URLS}\" --advertise-client-urls=\"${ETCD_ADVERTISE_CLIENT_URLS}\" --initial-cluster-token=\"${ETCD_INITIAL_CLUSTER_TOKEN}\" --initial-cluster=\"${ETCD_INITIAL_CLUSTER}\" --initial-cluster-state=\"${ETCD_INITIAL_CLUSTER_STATE}\" "  
Restart=on-failure  
LimitNOFILE=65536  

[Install]  
WantedBy=multi-user.target

   use vi editor to open or create etcd.conf file:

vi /etc/etcd/etcd.config

Modify the following files according to your actual ip address:

ETCD_NAME=node1  
ETCD_DATA_DIR="/var/lib/etcd/etcd01"  
ETCD_LISTEN_PEER_URLS="http://192.168.22.117:2380"  
ETCD_LISTEN_CLIENT_URLS="http://192.168.22.117:2379,http://127.0.0.1:2379"  
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.22.117:2380"  
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.22.117:2379"  
ETCD_INITIAL_CLUSTER_STATE="new"  
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"  
ETCD_INITIAL_CLUSTER="node1=http://192.168.22.117:2380,node2=http://192.168.22.118:2380,node3=http://192.168.22.119:2380"

Etcd [name] needs to be different for the three machines, such as node1, node2 and node3. Etcd data dir is also modified, such as "/ var/lib/etcd/etcd01", "var/lib/etcd/etcd02", "var/lib/etcd/etcd03". Etcd? Initial? Cluster needs to configure all ip addresses of these three machines.

Add service


                     

systemctl daemon-reload  

systemctl start etcd  

systemctl enable etcd

After the service is started successfully, check the status of each node of etcd:

etcdctl member list


Posted by birwin on Sun, 03 May 2020 06:40:46 -0700