Original link: http://www.nosuchfield.com/2022/06/14/A-brief-introduction-to-etcd/
Install
etcd is a distributed consistent key-value database. First we download the package
useradd etcdsu - etcdwget https://github.com/etcd-io/etcd/releases/download/v3.5.4/etcd-v3.5.4-linux-amd64.tar.gztar -zxvf.tar.gzcd
After that we can query the version of etcd
$ ./etcd --versionetcd Version: 3.5.4Git SHA: 08407ff76Go Version: go1.16.15Go OS/Arch: linux/amd64
We performed the above operations on the three loads 172.19.33.141
, 172.19.32.155
and 172.19.34.21
respectively to install etcd.
use
After that, we use etcd to build a cluster, and the relevant configuration can be set using the command line or the configuration file . The meaning of the relevant configuration is as follows
configure | meaning | Defaults |
---|---|---|
name | the name of the current node | default |
initial-advertise-peer-urls | Tell other nodes the ip address and port that the current node communicates with other nodes | http://localhost:2380 |
advertise-client-urls | Tell other nodes the ip address and port that the current node communicates with the client | http://localhost:2379 |
listen-peer-urls | The ip address and port that the current node is listening on and is used to communicate with other nodes | http://localhost:2380 |
listen-client-urls | The ip address and port that the current node is listening on and used to communicate with the client | http://localhost:2379 |
initial-cluster-token | Token attribute when cluster bootstrap | etcd-cluster |
initial-cluster | Configuration information for cluster bootstrap | default= http://localhost:2380 |
initial-cluster-state | Cluster startup status, set to new when the cluster is started for the first time, and set to existing if you want to join an existing cluster |
new |
Then we use the command line settings to start the three processes separately
[etcd@lin-19-33-141]$ ./etcd --name node1 \ --initial-advertise-peer-urls http://172.19.33.141:2380 \ --advertise-client-urls http://172.19.33.141:2379 \ --listen-peer-urls http://172.19.33.141:2380 \ --listen-client-urls http://172.19.33.141:2379,http://127.0.0.1:2379 \ --initial-cluster-token product-center \ --initial-cluster node1=http://172.19.33.141:2380,node2=http://172.19.32.155:2380,node3=http://172.19.34.21:2380[etcd@lin-19-32-155]$ ./etcd --name node2 \ --initial-advertise-peer-urls http://172.19.32.155:2380 \ --advertise-client-urls http://172.19.32.155:2379 \ --listen-peer-urls http://172.19.32.155:2380 \ --listen-client-urls http://172.19.32.155:2379,http://127.0.0.1:2379 \ --initial-cluster-token product-center \ --initial-cluster node1=http://172.19.33.141:2380,node2=http://172.19.32.155:2380,node3=http://172.19.34.21:2380[etcd@lin-19-34-21]$ ./etcd --name node3 \ --initial-advertise-peer-urls http://172.19.34.21:2380 \ --advertise-client-urls http://172.19.34.21:2379 \ --listen-peer-urls http://172.19.34.21:2380 \ --listen-client-urls http://172.19.34.21:2379,http://127.0.0.1:2379 \ --initial-cluster-token product-center \ --initial-cluster node1=http://172.19.33.141:2380,node2=http://172.19.32.155:2380,node3=http://172.19.34.21:2380
After the etcd startup command is executed on the three loads, the three nodes have formed an etcd cluster under normal circumstances. Then we can use etcdctl
client to read and write data in the cluster
./etcdctl --endpoints=172.19.33.141:2379,172.19.32.155:2379,172.19.34.21:2379 member list./etcdctl --endpoints=172.19.33.141:2379,172.19.32.155:2379,172.19.34.21:2379 put name "zhangsan"./etcdctl --endpoints=172.19.33.141:2379,172.19.32.155:2379,172.19.34.21:2379 get name
refer to
https://etcd.io/docs/v3.5/tutorials/
This article is reproduced from: http://www.nosuchfield.com/2022/06/14/A-brief-introduction-to-etcd/
This site is for inclusion only, and the copyright belongs to the original author.