Difference between revisions of "Etcd"

From Christoph's Personal Wiki
Jump to: navigation, search
(Created page with "'''etcd''' is a strongly consistent, distributed key-value store that provides a reliable way to store data that needs to be accessed by a distributed system or cluster of mac...")
 
Line 44: Line 44:
 
$ ~/go/bin/etcdctl --endpoints=http://${NODE1}:2379 put foo1 bar1
 
$ ~/go/bin/etcdctl --endpoints=http://${NODE1}:2379 put foo1 bar1
 
$ ~/go/bin/etcdctl --endpoints=http://${NODE1}:2379 put get foo1
 
$ ~/go/bin/etcdctl --endpoints=http://${NODE1}:2379 put get foo1
 +
</pre>
 +
 +
==Miscellaneous==
 +
 +
<pre>
 +
$ ~/go/bin/etcdctl --write-out=table snapshot status 2020-05-05T16\:41\:38Z_etcd
 +
+----------+----------+------------+------------+
 +
|  HASH  | REVISION | TOTAL KEYS | TOTAL SIZE |
 +
+----------+----------+------------+------------+
 +
| c556b896 | 20870551 |      13924 |    187 MB |
 +
+----------+----------+------------+------------+
 
</pre>
 
</pre>
  

Revision as of 18:55, 5 May 2020

etcd is a strongly consistent, distributed key-value store that provides a reliable way to store data that needs to be accessed by a distributed system or cluster of machines. It gracefully handles leader elections during network partitions and can tolerate machine failure, even in the leader node.

Create a single-node etcd cluster running in Docker

  • Start up a Docker container for the single-node etcd cluster:
$ export DATA_DIR="etcd-data"
$ export NODE1=10.x.x.x  # <= You host IP
$ REGISTRY=quay.io/coreos/etcd
$ docker volume create --name etcd-data
$ docker run \
    -p 2379:2379 \
    -p 2380:2380 \
    --volume=${DATA_DIR}:/etcd-data \
    --name etcd ${REGISTRY}:latest \
    /usr/local/bin/etcd \
    --data-dir=/etcd-data --name node1 \
    --initial-advertise-peer-urls http://${NODE1}:2380 --listen-peer-urls http://0.0.0.0:2380 \
    --advertise-client-urls http://${NODE1}:2379 --listen-client-urls http://0.0.0.0:2379 \
    --initial-cluster node1=http://${NODE1}:2380
  • In a different shell:
$ go get github.com/coreos/etcd/etcdctl

$ ~/go/bin/etcdctl --endpoints=http://${NODE1}:2379 member list
5ef3db6412b1adfb, started, node1, http://10.x.x.x:2380, http://10.x.x.x:2379, false

$ ~/go/bin/etcdctl --endpoints=http://${NODE1}:2379 -w table member list
+------------------+---------+-------+----------------------+----------------------+------------+
|        ID        | STATUS  | NAME  |       PEER ADDRS     |      CLIENT ADDRS    | IS LEARNER |
+------------------+---------+-------+----------------------+----------------------+------------+
| 5ef3db6412b1adfb | started | node1 | http://10.x.x.x:2380 | http://10.x.x.x:2379 |      false |
+------------------+---------+-------+----------------------+----------------------+------------+

$ ~/go/bin/etcdctl --endpoints=http://${NODE1}:2379 -w table endpoint --cluster status
+----------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
|        ENDPOINT      |        ID        | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
+----------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| http://10.x.x.x:2379 | 5ef3db6412b1adfb |   3.3.8 |   20 kB |      true |      false |         4 |          9 |                  0 |        |
+----------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+

$ ~/go/bin/etcdctl --endpoints=http://${NODE1}:2379 put foo1 bar1
$ ~/go/bin/etcdctl --endpoints=http://${NODE1}:2379 put get foo1

Miscellaneous

$ ~/go/bin/etcdctl --write-out=table snapshot status 2020-05-05T16\:41\:38Z_etcd 
+----------+----------+------------+------------+
|   HASH   | REVISION | TOTAL KEYS | TOTAL SIZE |
+----------+----------+------------+------------+
| c556b896 | 20870551 |      13924 |     187 MB |
+----------+----------+------------+------------+

External links