从零开始搭建etcd分布式存储系统+Web管理界面(2)

然后我们在node2上面执行操作

root@Ubuntu:~# etcdctl member list 2033c1336b929ca7: name=node-3 peerURLs=http://10.211.55.26:2380 clientURLs=http://10.211.55.26:2379 isLeader=true edc51d36208cfbcf: name=node-2 peerURLs=http://10.211.55.25:2380 clientURLs=http://10.211.55.25:2379 isLeader=false f09a9dba19a725e2: name=node-1 peerURLs=http://10.211.55.2:2380 clientURLs=http://10.211.55.2:2379 isLeader=false

可以看到集群已经生效了,我们再来测试一下,在ndoe2上执行操作

etcdctl set /cqh muscle

看看node1和node3是否能保持数据一致

从零开始搭建etcd分布式存储系统+Web管理界面

可以看到在node1和node3中都能能够正确的获取/cqh的值

四.监听功能watch演示

etcdctl watch key
观察一个值的变化,观察到变化后,打印值并watch退出

从零开始搭建etcd分布式存储系统+Web管理界面

etcdctl watch key -f
永久观察值的变化,观察到变化后,打印直到Ctrl+C退出

从零开始搭建etcd分布式存储系统+Web管理界面

etcdctl exec-watch key -- sh -c 'pwd'
监听到值有变化,就执行指定的命令(且不退出执行的可以是shell命令)

从零开始搭建etcd分布式存储系统+Web管理界面

五.使用rest api

创建键值

➜ ~ curl :2379/v2/keys/cqh -XPUT -d value="陈琼和1" {"action":"set","node":{"key":"/cqh","value":"陈琼和","modifiedIndex":14,"createdIndex":14},"prevNode":{"key":"/cqh","value":"陈琼和","modifiedIndex":13,"createdIndex":13}}

创建目录

➜ ~ curl :2379/v2/keys/gym -XPUT -d dir=true {"action":"set","node":{"key":"/gym","dir":true,"modifiedIndex":12,"createdIndex":12}}

获取键值

➜ ~ curl :2379/v2/keys/cqh {"action":"get","node":{"key":"/cqh","value":"陈琼和","modifiedIndex":14,"createdIndex":14}}

创建键值带ttl

➜ ~ curl :2379/v2/keys/hero -XPUT -d value="超人" -d ttl=5

创建有序键值

curl :2379/v2/keys/fitness -XPOST -d value="bench_press" curl :2379/v2/keys/fitness -XPOST -d value="dead_lift" curl :2379/v2/keys/fitness -XPOST -d value="deep_squat"

获取刚创建的fitness

curl :2379/v2/keys/fitness {"action":"create","node":{"key":"/fitness/00000000000000000020","value":"bench_press","modifiedIndex":20,"createdIndex":20}} {"action":"create","node":{"key":"/fitness/00000000000000000021","value":"dead_lift","modifiedIndex":21,"createdIndex":21}} {"action":"create","node":{"key":"/fitness/00000000000000000022","value":"deep_squat","modifiedIndex":22,"createdIndex":22}} {"action":"get","node":{"key":"/fitness","dir":true,"nodes":[{"key":"/fitness/00000000000000000022","value":"deep_squat","modifiedIndex":22,"createdIndex":22},{"key":"/fitness/00000000000000000020","value":"bench_press","modifiedIndex":20,"createdIndex":20},{"key":"/fitness/00000000000000000021","value":"dead_lift","modifiedIndex":21,"createdIndex":21}],"modifiedIndex":20,"createdIndex":20}}

删除键

curl :2379/v2/keys/cqh -XDELETE

列出所有集群成员

curl :2379/v2/members

统计信息-查看leader

curl :2379/v2/stats/leader

节点自身信息

curl :2379/v2/stats/self

查看集群运行状态

curl :2379/v2/stats/store 六.搭建WEB界面并使用

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/beef4476bbad2dfd0d0e8cae0643f9bb.html