etcd 基础4

2022-01-20 10:33:12 浏览数 (1)

获取版本信息

代码语言:javascript复制
[root@docker etcd-v2.2.4-linux-amd64]# curl -L http://127.0.0.1:2379/version
{"etcdserver":"2.2.4","etcdcluster":"2.2.0"}[root@docker etcd-v2.2.4-linux-amd64]# 
[root@docker etcd-v2.2.4-linux-amd64]# 

关键字空间操作

etcd主要在维护一个分层的关键字空间,关键字空间由关键字和目录构成,它们也被称作节点

etcd的绝大部分API都是在对这两类对象进行操作

给关键字赋值

代码语言:javascript复制
[root@docker etcd-v2.2.4-linux-amd64]# curl http://127.0.0.1:2379/v2/keys/message -XPUT -d value="Hello world"
{"action":"set","node":{"key":"/message","value":"Hello world","modifiedIndex":8,"createdIndex":8}}
[root@docker etcd-v2.2.4-linux-amd64]# curl http://127.0.0.1:2379/v2/keys/message -XPUT -d value="Hello world"
{"action":"set","node":{"key":"/message","value":"Hello world","modifiedIndex":9,"createdIndex":9},"prevNode":{"key":"/message","value":"Hello world","modifiedIndex":8,"createdIndex":8}}
[root@docker etcd-v2.2.4-linux-amd64]# curl http://127.0.0.1:2379/v2/keys/message -XPUT -d value="Hello world"
{"action":"set","node":{"key":"/message","value":"Hello world","modifiedIndex":10,"createdIndex":10},"prevNode":{"key":"/message","value":"Hello world","modifiedIndex":9,"createdIndex":9}}
[root@docker etcd-v2.2.4-linux-amd64]# curl http://127.0.0.1:2379/v2/keys/message -XPUT -d value="Hello world"
{"action":"set","node":{"key":"/message","value":"Hello world","modifiedIndex":11,"createdIndex":11},"prevNode":{"key":"/message","value":"Hello world","modifiedIndex":10,"createdIndex":10}}
[root@docker etcd-v2.2.4-linux-amd64]# curl http://127.0.0.1:2379/v2/keys/message -XPUT -d value="Hello world"
{"action":"set","node":{"key":"/message","value":"Hello world","modifiedIndex":12,"createdIndex":12},"prevNode":{"key":"/message","value":"Hello world","modifiedIndex":11,"createdIndex":11}}
[root@docker etcd-v2.2.4-linux-amd64]# curl http://127.0.0.1:2379/v2/keys/abc -XPUT -d value="Hello world"
{"action":"set","node":{"key":"/abc","value":"Hello world","modifiedIndex":13,"createdIndex":13}}
[root@docker etcd-v2.2.4-linux-amd64]# curl http://127.0.0.1:2379/v2/keys/abc -XPUT -d value="Hello world"
{"action":"set","node":{"key":"/abc","value":"Hello world","modifiedIndex":14,"createdIndex":14},"prevNode":{"key":"/abc","value":"Hello world","modifiedIndex":13,"createdIndex":13}}
[root@docker etcd-v2.2.4-linux-amd64]# curl http://127.0.0.1:2379/v2/keys/abc -XPUT -d value="abc"
{"action":"set","node":{"key":"/abc","value":"abc","modifiedIndex":15,"createdIndex":15},"prevNode":{"key":"/abc","value":"Hello world","modifiedIndex":14,"createdIndex":14}}
[root@docker etcd-v2.2.4-linux-amd64]#

Attribute

Comment

action

事件类型

node.key

关键字,etcd使用了文件系统的结构来管理关键字,都以 / 开头

node.value

node.modifiedIndex

在有修改操作时会递增

node.createdIndex

有创建操作时会递增

0 人点赞