Building Etcd Cluster

Keywords: github Linux curl vim

Article directory

Official website: https://etcd.io/
Github: https://github.com/etcd-io/etcd/releases

I. About ETCD

  • etcd is an open source, distributed key-to-value data storage system that provides shared configuration, service registration and discovery.
  • Scenario 1: Service Discovery
  • Scenario 2: Message Publishing and Subscription
  • Scenario 3: Load balancing
  • Scenario 4: Distributed notification and coordination
  • Scenario 5: Distributed Locks
  • Scenario 6: Distributed queues
  • Scenario 7: Cluster Monitoring and Leader Election

II. Stand-alone Installation

1. Download and install:

# Defining variables
$ ETCD_VER=v3.4.0
$ ETCD_URL=https://github.com/etcd-io/etcd/releases/download

# Download the compiler package and put etcd and etcdctl in the installation directory.
$ wget ${ETCD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz
$ tar xzvf ./etcd-${ETCD_VER}-linux-amd64.tar.gz
$ cd ./etcd-${ETCD_VER}-linux-amd64
$ mkdir /usr/local/etcd && cp etcd* /usr/local/etcd

2. Start the program

# Configuring environment variables
$ vim /etc/profole
#*********************************
export PATH=/usr/local/etcd:$PATH
#*********************************
$source /etc/profile 

# Start daemon: 2 > & 1 means redirecting standard errors to standard output
$ nohup etcd >/tmp/etcd.log 2>&1 & 

3. Installation testing: client or Curl testing

$ etcd --version     #Service version
$ etcdctl version    #Client version
$ curl http://127.0.0.1:2379/version 

4. Simple operation:

$ etcdctl --endpoints=localhost:2379 put foo "hello"
$ etcdctl --endpoints=localhost:2379 get foo

3. Building Clusters

1. Global parameters: prepare three virtual machines (192.168.1.11, 192.168.1.12, 192.168.1.13) to execute the same commands

TOKEN=token-XXX01
CLUSTER_STATE=new
NODE1=node1
NODE2=node2
NODE3=node3
HOST1=http://192.168.1.11
HOST2=http://192.168.1.12
HOST3=http://192.168.1.13
CLUSTER=${NODE1}=${HOST1}:2380,${NODE2}=${HOST2}:2380,${NODE3}=${HOST3}:2380

2. Specify variables: Select and execute the following commands according to the corresponding relationship

NODE=${NODE1} && HOST=${HOST1}    #Node 1
NODE=${NODE2} && HOST=${HOST2}    #Node 2
NODE=${NODE3} && HOST=${HOST3}    #Node 3

3. Start the service: all execute the following commands

nohup etcd --data-dir=/data/etcd/data.etcd --name ${NODE} \
 --initial-advertise-peer-urls ${HOST}:2380 --listen-peer-urls ${HOST}:2380 \
 --advertise-client-urls ${HOST}:2379 --listen-client-urls ${HOST}:2379 \
 --initial-cluster ${CLUSTER} \
 --initial-cluster-state ${CLUSTER_STATE} --initial-cluster-token ${TOKEN} \
 >/tmp/etcd.log 2>&1 &

4. Authentication services: executed on any one of the clusters

etcdctl --endpoints=192.168.1.11:2379,192.168.1.12:2379,192.168.1.13:2379 endpoint status -w table


Reference resources:
https://www.jianshu.com/p/2966b6ef5d10
https://mritd.me/2016/09/01/Etcd-%E9%9B%86%E7%BE%A4%E6%90%AD%E5%BB%BA/
https://blog.csdn.net/ShouTouDeXingFu/article/details/81167302
https://blog.csdn.net/bbwangj/article/details/82584988
https://www.liwenzhou.com/posts/Go/go_etcd/
http://www.iigrowing.cn/etcd_shi_yong_ru_men.html
https://www.jianshu.com/p/8e4bbe7e276c
https://segmentfault.com/a/1190000014045625
https://www.cnblogs.com/davygeek/p/7154780.html
https://www.cnblogs.com/zhenghongxin/p/7029173.html
https://blog.csdn.net/zhaominpro/article/details/82630528

Posted by thorpe on Wed, 02 Oct 2019 01:58:37 -0700