etcd rest api基本操作
2017-07-24 14:47
1656 查看
from: https://segmentfault.com/a/1190000005649865
访问
http://discovery.etcd.io/e77afb997af5a84983baa98fd42cf12f返回
{ "action": "get", "node": { "key": "/_etcd/registry/e77afb997af5a84983baa98fd42cf12f", "dir": true, "nodes": [ { "key": "/_etcd/registry/e77afb997af5a84983baa98fd42cf12f/4eb2dcba58da982f", "value": "etcd0=http://192.168.99.101:2380", "modifiedIndex": 1113260929, "createdIndex": 1113260929 }, { "key": "/_etcd/registry/e77afb997af5a84983baa98fd42cf12f/aa5569b385caf33b", "value": "etcd2=http://192.168.99.103:2380", "modifiedIndex": 1113261715, "createdIndex": 1113261715 }, { "key": "/_etcd/registry/e77afb997af5a84983baa98fd42cf12f/f84fe4a4e816e778", "value": "etcd1=http://192.168.99.102:2380", "modifiedIndex": 1113261726, "createdIndex": 1113261726 } ], "modifiedIndex": 1113260647, "createdIndex": 1113260647 } }
操作
查看版本
curl http://192.168.99.101:2379/version[/code] 返回{"etcdserver":"2.3.6","etcdcluster":"2.3.0"}查看键
curl http://192.168.99.101:2379/v2/keys[/code] 返回{"action":"get","node":{"dir":true}}创建键值
put方法如果key之前存在,则默认会先删除,再新建一个key。如果想要直接update,则追加 -d prevExist=true,但是加了这个参数,如果key之前不存在会报错。curl http://192.168.99.101:2379/v2/keys/hello -XPUT -d value="world"
返回{ "action": "set", "node": { "key": "/hello", "value": "world", "modifiedIndex": 8, "createdIndex": 8 } }创建目录
curl http://192.168.99.101:2379/v2/keys/dir -XPUT -d dir=true
返回{ "action": "set", "node": { "key": "/dir", "dir": true, "modifiedIndex": 9, "createdIndex": 9 } }查看键
curl http://192.168.99.101:2379/v2/keys[/code] 返回{ "action": "get", "node": { "dir": true, "nodes": [ { "key": "/hello", "value": "world", "modifiedIndex": 8, "createdIndex": 8 }, { "key": "/dir", "dir": true, "modifiedIndex": 9, "createdIndex": 9 } ] } }创建带ttl的键值
单位为秒curl http://192.168.99.101:2379/v2/keys/ttlvar -XPUT -d value="ttl_value" -d ttl=10
返回{ "action": "set", "node": { "key": "/ttlvar", "value": "ttl_value", "expiration": "2016-06-04T13:11:00.406180341Z", "ttl": 10, "modifiedIndex": 10, "createdIndex": 10 } }创建有序键值
curl http://192.168.99.101:2379/v2/keys/seqvar -XPOST -d value="seq1" curl http://192.168.99.101:2379/v2/keys/seqvar -XPOST -d value="seq2" curl http://192.168.99.101:2379/v2/keys/seqvar -XPOST -d value="seq3" curl http://192.168.99.101:2379/v2/keys/seqvar[/code] 返回{ "action": "get", "node": { "key": "/seqvar", "dir": true, "nodes": [ { "key": "/seqvar/00000000000000000012", "value": "seq1", "modifiedIndex": 12, "createdIndex": 12 }, { "key": "/seqvar/00000000000000000013", "value": "seq2", "modifiedIndex": 13, "createdIndex": 13 }, { "key": "/seqvar/00000000000000000014", "value": "seq3", "modifiedIndex": 14, "createdIndex": 14 } ], "modifiedIndex": 12, "createdIndex": 12 } }删除指定的键
curl http://192.168.99.101:2379/v2/keys/for_delete -XPUT -d value="fordelete" curl http://192.168.99.101:2379/v2/keys/ curl http://192.168.99.101:2379/v2/keys/for_delete -XDELETE curl http://192.168.99.101:2379/v2/keys/[/code] 返回{ "action": "delete", "node": { "key": "/for_delete", "modifiedIndex": 16, "createdIndex": 15 }, "prevNode": { "key": "/for_delete", "value": "fordelete", "modifiedIndex": 15, "createdIndex": 15 } }成员管理
列出所有集群成员
curl http://192.168.99.101:2379/v2/members[/code] 返回{ "members": [ { "id": "4eb2dcba58da982f", "name": "etcd0", "peerURLs": [ "http://192.168.99.101:2380" ], "clientURLs": [ "http://192.168.99.101:2379", "http://192.168.99.101:4001" ] }, { "id": "aa5569b385caf33b", "name": "etcd2", "peerURLs": [ "http://192.168.99.103:2380" ], "clientURLs": [ "http://192.168.99.103:2379", "http://192.168.99.103:4001" ] }, { "id": "f84fe4a4e816e778", "name": "etcd1", "peerURLs": [ "http://192.168.99.102:2380" ], "clientURLs": [ "http://192.168.99.102:2379", "http://192.168.99.102:4001" ] } ] }统计信息
查看leader
curl http://192.168.99.101:2379/v2/stats/leader[/code] 返回{ "leader": "4eb2dcba58da982f", "followers": { "aa5569b385caf33b": { "latency": { "current": 0.001687, "average": 0.0026333315088053265, "standardDeviation": 0.0082522530707236, "minimum": 0.000508, "maximum": 0.184366 }, "counts": { "fail": 0, "success": 8404 } }, "f84fe4a4e816e778": { "latency": { "current": 0.001158, "average": 0.017216567181926247, "standardDeviation": 1.236027691414708, "minimum": 0.000493, "maximum": 113.333953 }, "counts": { "fail": 0, "success": 8410 } } } }节点自身信息
curl http://192.168.99.101:2379/v2/stats/self[/code] 返回{ "name": "etcd0", "id": "4eb2dcba58da982f", "state": "StateLeader", "startTime": "2016-06-04T12:51:22.901345036Z", "leaderInfo": { "leader": "4eb2dcba58da982f", "uptime": "28m29.401994375s", "startTime": "2016-06-04T12:51:23.406751734Z" }, "recvAppendRequestCnt": 0, "sendAppendRequestCnt": 17544, "sendPkgRate": 10.52589669646476, "sendBandwidthRate": 746.7071116472099 }查看集群运行状态
curl http://192.168.99.101:2379/v2/stats/store[/code] 返回{ "getsSuccess": 7, "getsFail": 16, "setsSuccess": 8, "setsFail": 0, "deleteSuccess": 1, "deleteFail": 0, "updateSuccess": 0, "updateFail": 0, "createSuccess": 6, "createFail": 0, "compareAndSwapSuccess": 0, "compareAndSwapFail": 0, "compareAndDeleteSuccess": 0, "compareAndDeleteFail": 0, "expireCount": 1, "watchers": 0 }
相关文章推荐
- Ryu基本操作的REST API调用示例
- ElasticSearch通过Rest Http API完成基本操作
- SharePoint REST API - 基本操作(二)
- SharePoint REST API - 基本操作(一)
- Ryu基本操作的REST API调用演示样例
- Ryu基本操作的REST API调用示例
- 使用SVG基本操作API的实例讲解
- JDBC应用程序常见接口API和基本操作步骤
- HBase客户端API基本操作
- HDFS API基本操作
- elasticsearch5.6.4 RestClient 索引操作API详细的注释给力篇值得拥有
- ZooKeeper原生Api基本操作
- 使用JAVA的开源API-JExcelAPI来操作Excel,实现基本的功能
- elasticsearch基本操作之--java基本操作 api
- 深入浅出 Javascript API(二)--地图显示与基本操作
- 深入浅出 Javascript API(二)--地图显示与基本操作
- Zookeeper之Curator(1)客户端基本的创建,删除,更新,查找操作api
- 5 个基本的 REST API 设计指导方针
- API--基本的IO操作
- Azure REST API (3) 使用REST API,操作Azure ARM VM