etcd rest api基本操作
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
返回
{"etcdserver":"2.3.6","etcdcluster":"2.3.0"}
查看键
curl http://192.168.99.101:2379/v2/keys
返回
{"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
返回
{"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
返回
{"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/
返回
{"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
返回
{"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
返回
{"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
返回
{"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
返回
{"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
}
etcd rest api基本操作相关推荐
- 分布式学习(7)etcd@3@ API v3 gRPC_事务,租约
一.ETCD 之 事务 在etcdv3中,事务就是一个原子的.针对key-value存储操作的If / Then / Else 结构,事务提供了一个原语,用于请求归并到一起放在原子块中,例如then/ ...
- 分布式学习(6)etcd@3@ API v3 gRPC_range,put,deleterange
1 gRPC Services 发送到etcd服务器的每个API请求都是一个gRPC. 在etcd3中的RPCs会根据功能分类到不同的service中. 1.1 Services important ...
- etcd http API
在docker中启动etcd 参考 https://etcd.io/docs/v3.5/op-guide/container/ 启动后,假定服务监听在192.168.1.21:2379. 基本示例 r ...
- ASP.NET Web API 基本操作(CRUD)
上一篇介绍了ASP.NET Web API的基本知识和原理,这一篇我们通过一个更直观的实例,对产品进行CRUD操作(Create/Read/Update/Delete)来继续了解一下它的基本应用. 创 ...
- 学习 etcd watch api
测试代码 func Test_watch(t *testing.T) {ec, _ := NewEtcdClient([]string{"http://127.0.0.1:2379" ...
- SharePoint REST API - 基本操作(一)
博客地址:http://blog.csdn.net/FoxDave 本文讲述如何应用SharePoint的REST接口完成基本的增删查改操作. 使用SharePoint客户端API和REST服务进 ...
- mysql c api 封装_封装MySQL C API 基本操作
根据我的以前的文章 http://blog.csdn.net/skyhuangdan/article/details/21099929 链接数据库成功后进行封装. 我封装类使用的是VS2005下的wi ...
- 课时 16 深入理解 etcd:基于原理解析(曾凡松)
本文将主要分享以下三方面的内容: 第一部分,会为大家介绍 etcd 项目发展的整个历程,从诞生至今 etcd 经历的那些重要的时刻: 第二部分,会为大家介绍 etcd 的技术架构以及其内部的实现机制, ...
- 从零开始入门 K8s | 手把手带你理解 etcd
作者 | 曾凡松(逐灵) 阿里云容器平台高级技术专家 本文整理自<CNCF x Alibaba 云原生技术公开课>第 16 讲. 导读:etcd 是用于共享配置和服务发现的分布式.一致性的 ...
最新文章
- 简单编程代码_好了好了,不闲扯了,我们开始学编程了
- 为什么品牌商纷纷搭建自己的商城小程序?
- CCNA学习笔记--静态路由
- linux python cpu温度,linux-raspbian系统下编写python脚本显示树莓派的当前cpu温度、使用率、内存和硬盘信息...
- mysql 外键有啥用途_Mysql外键是什么?有哪些用处?(图文+视频)
- Java DelayQueue延迟队列的使用和源码分析
- 三步法搞定CTF中的SQL注入题型
- Perl文件及目录操作
- 获取ClassLoader的途径
- 【Pytorch神经网络实战案例】03 CIFAR-10数据集:Pytorch使用GPU训练CNN模版-测试方法
- MySQL进阶之索引
- 初二是学生阶段的分水岭吗?家长该做哪些准备?
- 为链接加上加载等待信息
- PE教程6: Import Table(引入表)(看雪)
- SQL:where 和 having 的区别
- [HNOI2019]JOJO(KMP自动机+主席树)
- Linux开发板移植minicom
- 群晖3617可以有几个网卡_一步到位,购入群晖920+和它的小伙伴们
- 进销存excel_进销存报表还再花钱买软件?别傻了!教你一个Excel函数就能搞定...
- puppeteer实现百度贴吧自动签到