Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

ETCD Cluster installation experiment

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Catalogue

[1. Download binaries]

[2. Install etcd cluster]

[3. Query cluster status]

[4. Save read data]

[5. Points for attention]

[6. Reference link]

Brief introduction:

The official website document of Etcd and its documentation on GitHub are already very complete, and they are concise and clear, and there are detailed instructions for binary installation, Docker operation and command operation. However, directly copying the installation can make mistakes, and only by doing it by hand can you find out what the problems are.

[1. Download binaries]

# download and install etcd and etcdctl programs on three hosts

# set the version of ETCD

ETCD_VER=v3.3.8

# set download address URL

GITHUB_URL= https://github.com/coreos/etcd/releases/download

DOWNLOAD_URL=$ {GITHUB_URL}

# clear the previous temporary files and directories and create a new directory

Rm-f / tmp/etcd-$ {ETCD_VER}-linux-amd64.tar.gz

Rm-rf / tmp/etcd-download-test & & mkdir-p / tmp/etcd-download-test

# download etcd binaries using curl

# address is https://github.com/coreos/etcd/releases/download/v3.3.8/etcd-v3.3.8-linux-amd64.tar.gz

# Delete the compressed package after unpacking

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

# move etcd and etcdctl executable programs to the system path to make it easy to run the programs directly

Sudo mv / tmp/etcd-download-test/etcd* / usr/local/bin

# query etcd and etcdctl versions

# check to see if the program is running properly.

Etcd-version

ETCDCTL_API=3 etcdctl version

[2. Install etcd cluster]

# execute on node node1

TOKEN=token-01

CLUSTER_STATE=new

NAME_1=node1

NAME_2=node2

NAME_3=node3

HOST_1=192.168.3.161

HOST_2=192.168.3.162

HOST_3=192.168.3.163

CLUSTER=$ {NAME_1} = http://${HOST_1}:2380,${NAME_2}=http://${HOST_2}:2380,${NAME_3}=http://${HOST_3}:2380

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}

# Note here that if you directly copy the code on the github website, an error will be reported during execution.

# 2018-06-29 16 initial-advertise-peer-urls' is not a valid flag 57displacement 54.048863 E | etcdmain: error verifying flags,'--initial-advertise-peer-urls' is not a valid flag. See 'etcd-- help'.

# https://github.com/coreos/etcd/blob/master/Documentation/demo.md

# need to clear the space character before the dash

# execute on node node2

TOKEN=token-01

CLUSTER_STATE=new

NAME_1=node1

NAME_2=node2

NAME_3=node3

HOST_1=192.168.3.161

HOST_2=192.168.3.162

HOST_3=192.168.3.163

CLUSTER=$ {NAME_1} = http://${HOST_1}:2380,${NAME_2}=http://${HOST_2}:2380,${NAME_3}=http://${HOST_3}:2380

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}

# execute on node node3

TOKEN=token-01

CLUSTER_STATE=new

NAME_1=node1

NAME_2=node2

NAME_3=node3

HOST_1=192.168.3.161

HOST_2=192.168.3.162

HOST_3=192.168.3.163

CLUSTER=$ {NAME_1} = http://${HOST_1}:2380,${NAME_2}=http://${HOST_2}:2380,${NAME_3}=http://${HOST_3}:2380

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}

[3. Query cluster status]

Export ETCDCTL_API=3

HOST_1=192.168.3.161

HOST_2=192.168.3.162

HOST_3=192.168.3.163

ENDPOINTS=$HOST_1:2379,$HOST_2:2379,$HOST_3:2379

Etcdctl-endpoints=$ENDPOINTS-write-out=table member list

Etcdctl-endpoints=$ENDPOINTS-write-out=table endpoint status

Etcdctl-endpoints=$ENDPOINTS-write-out=table endpoint health

Figure 1 query the status of the cluster

[4. Save read data]

# download and unpack etcdctl on other machines on the same network segment

# use etcdctl command to access the cluster of etcd

Export ETCDCTL_API=3

HOST_1=192.168.3.161

HOST_2=192.168.3.162

HOST_3=192.168.3.163

ENDPOINTS=$HOST_1:2379,$HOST_2:2379,$HOST_3:2379

Etcdctl-endpoints=$ENDPOINTS put myurl www.sina.com.cn

Etcdctl-endpoints=$ENDPOINTS get myurl

Figure 2 using etcdctl to store and read data

# or access the etcd cluster using curl

# data can be accessed through any node in the cluster

HOST_1=192.168.3.161

HOST_2=192.168.3.162

HOST_3=192.168.3.163

Curl-X PUT http://${HOST_1}:2379/v2/keys/myurl-d value=www.china.com

Curl-X GET http://${HOST_1}:2379/v2/keys/myurl

Curl-X GET http://${HOST_2}:2379/v2/keys/myurl

Curl-X GET http://${HOST_3}:2379/v2/keys/myurl

Curl http://192.168.3.161:2379/v2/keys

Figure 3 using curl to store and read data

[5. Points for attention]

1. Directly copying and pasting the code on the github will cause errors. You need to clear the space before the dash in the etcd command.

2018-06-29 16 initial-advertise-peer-urls' is not a valid flag 57displacement 54.048863 E | etcdmain: error verifying flags,'.-- initial-advertise-peer-urls' is not a valid flag. See 'etcd-- help'.

2. The time of the host should be synchronized, and the NTP service can be installed, otherwise it will alarm:

2018-06-29 18 04VR 29.328082W | rafthttp: the clock difference against peer 5d5a6e579c03726b is too high [3.777632896s > 1s]

[6. Reference link]

Official website of etcd

Https://coreos.com/etcd/docs/latest/demo.html

Https://github.com/coreos/etcd/releases/

Https://github.com/coreos/etcd/blob/master/Documentation/demo.md

Basic operation of etcd rest API

Https://segmentfault.com/a/1190000005649865

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report