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...")
 
(External links)
 
(3 intermediate revisions by the same user not shown)
Line 6: Line 6:
 
<pre>
 
<pre>
 
$ export DATA_DIR="etcd-data"
 
$ export DATA_DIR="etcd-data"
$ export NODE1=10.x.x.x  # <= You host IP
+
$ export NODE1=10.x.x.x  # <= Your host IP
 
$ REGISTRY=quay.io/coreos/etcd
 
$ REGISTRY=quay.io/coreos/etcd
 
$ docker volume create --name etcd-data
 
$ docker volume create --name etcd-data
Line 23: Line 23:
 
* In a different shell:
 
* In a different shell:
 
<pre>
 
<pre>
 +
$ docker exec etcd /bin/sh -c "export ETCDCTL_API=3 && /usr/local/bin/etcdctl member list"
 +
5ef3db6412b1adfb, started, node1, http://10.x.x.x:2380, http://10.x.x.x:2379
 +
 +
#~OR~
 +
 +
# Install the etcdctl binary locally:
 
$ go get github.com/coreos/etcd/etcdctl
 
$ go get github.com/coreos/etcd/etcdctl
  
Line 44: Line 50:
 
$ ~/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>
  
 
==External links==
 
==External links==
 
* [https://etcd.io/ Official website]
 
* [https://etcd.io/ Official website]
 +
* [https://etcd.io/docs/v3.4/op-guide/performance/ etcd Performance Guide]
  
 
[[Category:Technical and Specialized Skills]]
 
[[Category:Technical and Specialized Skills]]
 
[[Category:DevOps]]
 
[[Category:DevOps]]
 
[[Category:Linux Command Line Tools]]
 
[[Category:Linux Command Line Tools]]

Latest revision as of 17:30, 19 January 2023

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  # <= Your 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:
$ docker exec etcd /bin/sh -c "export ETCDCTL_API=3 && /usr/local/bin/etcdctl member list"
5ef3db6412b1adfb, started, node1, http://10.x.x.x:2380, http://10.x.x.x:2379

#~OR~

# Install the etcdctl binary locally:
$ 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