Consul - Key/Value和Web UI

Key/Value

为了提供服务发现以及健康检测,Consul提供了非常容易使用的键/值对存储。

1
2
3
[root@Automation ~]# mkdir test
[root@Automation ~]# consul kv get test/
Error! No key exists at: test/

consul支持http api和consul client进行K/V操作
1.添加: consul kv put [-flags=xx] key value

1
2
3
4
5
6
[root@Automation ~]# consul kv put test/kv 1
Success! Data written to: test/kv
[root@Automation ~]# consul kv put test/kv1 11
Success! Data written to: test/kv1
[root@Automation ~]# consul kv put -flags=21 test/kv2 admin
Success! Data written to: test/kv2

consul支持64位整数的flags表示kv的metadata
2.查询: consul kv get [-deatiled] key

1
2
3
4
5
6
7
8
9
10
[root@Automation ~]# consul kv get test/kv
1
[root@Automation ~]# consul kv get -detailed test/kv
CreateIndex 215
Flags 0
Key test/kv
LockIndex 0
ModifyIndex 695
Session -
Value 1

3.查询所有的key: consul kv get -recurse

1
2
3
4
5
[root@Automation ~]# consul kv get -recurse
test:15
test/kv:1
test/kv1:11
test/kv2:admin

4.删除key: consul kv delete key

1
2
3
4
5
6
[root@Automation ~]# consul kv delete test/kv
Success! Deleted key: test/kv
[root@Automation ~]# consul kv get -recurse
test:15
test/kv1:11
test/kv2:admin

5.前缀匹配删除: consul kv delete -recurse key-prefix

1
2
3
4
[root@Automation ~]# consul kv delete -recurse test
Success! Deleted keys with prefix: test
[root@Automation ~]# consul kv get -recurse
[root@Automation ~]#

6.修改kv

1
2
3
4
5
6
7
8
[root@Automation ~]# consul kv put test new
Success! Data written to: test
[root@Automation ~]# consul kv get test
new
[root@Automation ~]# consul kv put test update
Success! Data written to: test
[root@Automation ~]# consul kv get test
update

Web UI

启动Consul代理并设置 -ui 参数来启动自有主机的界面:
[root@Automation ~]# consul agent -dev -enable-script-checks -ui -config-dir /etc/consul.d

唐胡璐 wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
分享创造价值,您的支持将鼓励我继续前行!