日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

etcd rest api基本操作

發布時間:2025/7/25 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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基本操作的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。