etcdctl 常用命令

etcdctl 常用命令

1. 指定etcd集群

HOST_1=10.240.0.17
HOST_2=10.240.0.18
HOST_3=10.240.0.19
ENDPOINTS=$HOST_1:2379,$HOST_2:2379,$HOST_3:2379
etcdctl --endpoints=$ENDPOINTS member list

2. 增删查

2.1、增
etcdctl --endpoints=$ENDPOINTS put foo "Hello World!"
2.2、查
etcdctl --endpoints=$ENDPOINTS get foo
etcdctl --endpoints=$ENDPOINTS --write-out="json" get foo

基于相同前缀查找

etcdctl --endpoints=$ENDPOINTS put web1 value1
etcdctl --endpoints=$ENDPOINTS put web2 value2
etcdctl --endpoints=$ENDPOINTS put web3 value3

etcdctl --endpoints=$ENDPOINTS get web --prefix
2.3、删
etcdctl --endpoints=$ENDPOINTS put key myvalue
etcdctl --endpoints=$ENDPOINTS del key

etcdctl --endpoints=$ENDPOINTS put k1 value1
etcdctl --endpoints=$ENDPOINTS put k2 value2
etcdctl --endpoints=$ENDPOINTS del k --prefix

3. 集群状态

集群状态主要是etcdctl endpoint status 和etcdctl endpoint health两条命令。

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

+------------------+------------------+---------+---------+-----------+-----------+------------+
|     ENDPOINT     |        ID        | VERSION | DB SIZE | IS LEADER | RAFT TERM | RAFT INDEX |
+------------------+------------------+---------+---------+-----------+-----------+------------+
| 10.240.0.17:2379 | 4917a7ab173fabe7 | 3.0.0   | 45 kB   | true      |         4 |      16726 |
| 10.240.0.18:2379 | 59796ba9cd1bcd72 | 3.0.0   | 45 kB   | false     |         4 |      16726 |
| 10.240.0.19:2379 | 94df724b66343e6c | 3.0.0   | 45 kB   | false     |         4 |      16726 |
+------------------+------------------+---------+---------+-----------+-----------+------------+

etcdctl --endpoints=$ENDPOINTS endpoint health

10.240.0.17:2379 is healthy: successfully committed proposal: took = 3.345431ms
10.240.0.19:2379 is healthy: successfully committed proposal: took = 3.767967ms
10.240.0.18:2379 is healthy: successfully committed proposal: took = 4.025451ms

4. 集群成员

跟集群成员相关的命令如下:

member add          Adds a member into the cluster
member remove       Removes a member from the cluster
member update       Updates a member in the cluster
member list         Lists all members in the cluster

例如 etcdctl member list 列出集群成员的命令。

$ etcdctl --write-out=table --endpoints=$ENDPOINTS endpoint status
+-----------------+------------------+-----------+---------+-----------+------------+-----------+------------+--------------------+--------+
|    ENDPOINT     |        ID        |  VERSION  | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
+-----------------+------------------+-----------+---------+-----------+------------+-----------+------------+--------------------+--------+
| 127.0.0.1:12379 | 8211f1d0f64f3269 | 3.3.0+git |   25 kB |     false |      false |         2 |         17 |                 17 |        |
| 127.0.0.1:22379 | 91bc3c398fb3c146 | 3.3.0+git |   25 kB |     false |      false |         2 |         17 |                 17 |        |
| 127.0.0.1:32379 | fd422379fda50e48 | 3.3.0+git |   25 kB |      true |      false |         2 |         17 |                 17 |        |
+-----------------+------------------+-----------+---------+-----------+------------+-----------+------------+--------------------+--------+

文章参考:https://coreos.com/etcd/docs/latest/demo.html


原文:https://blog.csdn.net/huwh_/article/details/80225902

你可能感兴趣的:(etcdctl 常用命令)