consul简单使用

consul key/value使用(命令使用)

1.查看全部key/value

1
2
# ?recurse参数指定查询多个kv
curl -v http://localhost:8500/v1/kv/?recurse
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
* About to connect() to localhost port 8500 (#0)
* Trying ::1...
* Connected to localhost (::1) port 8500 (#0)
> GET /v1/kv/?recurse HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost:8500
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Vary: Accept-Encoding
< X-Consul-Index: 1
< X-Consul-Knownleader: true
< X-Consul-Lastcontact: 0
< Date: Wed, 31 Oct 2018 02:18:12 GMT
< Content-Length: 0
<
* Connection #0 to host localhost left intact

2.增加一个key/value

1
2
# key:'test/key001';value:'test' PUT:添加请求(注意必须大写)
curl -X PUT -d 'test' http://localhost:8500/v1/kv/test/key001
1
2
# 返回true表示添加成功
true
1
2
3
4
# 查询添加的key/value
curl http://localhost:8500/v1/kv/test/key001
# 结果 value:base64编码
[{"LockIndex":0,"Key":"test/key001","Flags":0,"Value":"dGVzdDAwMQ==","CreateIndex":6601,"ModifyIndex":6622}]

3.修改key/value

1
2
# 跟添加一样,只是保持key不变
curl -X PUT -d 'test003' http://localhost:8500/v1/kv/test/key001
1
2
3
4
# 查询
curl http://localhost:8500/v1/kv/test/key001
# 结果 注意modifyIndex也会随着修改的次数变更
[{"LockIndex":0,"Key":"test/key001","Flags":0,"Value":"dGVzdDAwMw==","CreateIndex":6601,"ModifyIndex":6750}]

4.删除key/value

1
2
3
4
curl -X DELETE http://localhost:8500/v1/kv/test/key001
true
# 查询key

consul key/value使用(UI界面操作)

1540954148780