1.下载etcd
wget https://github.com/etcd-io/etcd/releases/download/v3.4.4/etcd-v3.4.4-linux-amd64.tar.gz
2.配置环境变量
export PATH=$PATH:~/etcd-v3.4.4-linux-amd64
export ETCDCTL_API=3
2.启动
mkdir -p etcd-db/
cd etcd-db
etcd --listen-client-urls http://0.0.0.0:2379 --advertise-client-urls http://0.0.0.0:2379 &
3.命令
<colgroup><col style="width: 265.359px;"><col style="width: 347.891px;"></colgroup>
|
命令
|
描述
|
| --- | --- |
|
命令
|
描述
|
| --- | --- |
| etcdctl -h | 帮助命令 |
| etcdctl put /test/foo1 "Hello world"
etcdctl put /test/foo2 "Hello world2"
etcdctl put /test/foo3 "Hello world3" | 写入三对键值 |
|
etcdctl get /test/foo1
etcdctl get /test/foo2
etcdctl get /test/foo3
| 读取对应的值 |
| etcdctl get /test/foo1 --hex | 十六进制 |
| etcdctl get /test/foo1 --print-value-only | 只读取值 |
| etcdctl get /test/foo1 /test/foo3 | 获取大于等于 /test/foo1,且小于 /test/foo3 的键值对 |
| etcdctl get --prefix /test/foo | 取所有以 /test/foo 开头的键值对 |
| etcdctl get --prefix --limit=2 /test/foo | --limit=2 限制获取的数量 |
|
etcdctl put foo "bar"
etcdctl put foo1 "bar2"
etcdctl put foo "bar_new"
etcdctl put foo1 "bar1_new"
| etcdctl get --prefix --rev=4 foo # 访问第 4 个版本的 key |
|
etcdctl put a 123
etcdctl put b 456 etcdctl put c 789
|
读取大于等于键 b 的 byte 值的键的命令
|
| etcdctl del foo |
删除键 foo 的命令
|
| etcdctl del foo foo9 |
删除从 foo 到 foo9 范围的键的命令
|
|
etcdctl put zoo "bar"
etcdctl del --prev-kv zoo
|
删除键 zoo 并返回被删除的键值对的命令
|
| etcdctl del --from-key b |
删除大于等于键 b 的 byte 值的键的命令
|
|
etcdctl watch testkey
etcdctl put testkey Hello watch
|
watch 监测一个键值的变化
在另外一个终端执行命令
|
|
etcdctl watch foo foo9
etcdctl put foo bar
etcdctl put foo1 bar1
|
从 foo to foo9 范围内键的命令
|
|
etcdctl watch -i
watch foo
watch zoo
etcdctl put foo bar
etcdctl put zoo val
|
观察多个键 foo 和 zoo 的命令
|
|
etcdctl put foo bar # revision = 2
etcdctl put foo1 bar1 # revision = 3
etcdctl put foo bar_new # revision = 4
etcdctl put foo1 bar1_new # revision = 5
etcdctl watch --rev=2 foo
|
从修订版本 2 开始观察键 foo
的改动
|
|
etcdctl watch --prev-kv foo
etcdctl put foo bar_latest
|
在键 foo
上观察变更并返回被修改的值和上个修订版本的值
|
|
etcdctl compact 5
etcdctl get --rev=4 foo
| 在压缩修订版本之前的任何修订版本都不可访问 |
| etcdctl lease grant 100 | 授予租约,TTL 为 100 秒 |
| etcdctl put --lease=694d81b481505217 foo10 bar | 附加键 foo 到租约 694d81b481505217 |
| etcdctl lease revoke 694d81b481505217 |
撤销租约
|
| etcdctl lease keep-alive 694d81b481505222 |
刷新租期
|
| etcdctl lease timetolive 694d81b481505222 |
查询租期
|
网友评论