ETCD命令集合
本文由劉藝凌整理完成: from : http://www.itshouce.com.cn/other/etcd-command.html
ETCD 命令存儲:
??? curl http://127.0.0.1:4001/v2/keys/testkey -XPUT -d value='testvalue'
??? curl -s http://127.0.0.1:4001/v2/keys/message2 -XPUT -d value='hello etcd' -d ttl=5
獲取:
??? curl http://127.0.0.1:4001/v2/keys/testkey
查看版本:
??? curl? http://127.0.0.1:4001/version
刪除:
??? curl -s http://127.0.0.1:4001/v2/keys/testkey -XDELETE
監(jiān)視:
??? 窗口1:curl -s http://127.0.0.1:4001/v2/keys/message2 -XPUT -d value='hello etcd 1'
????????? curl -s http://127.0.0.1:4001/v2/keys/message2?wait=true
??? 窗口2:
????????? curl -s http://127.0.0.1:4001/v2/keys/message2 -XPUT -d value='hello etcd 2'
自動創(chuàng)建key:
??? curl -s http://127.0.0.1:4001/v2/keys/message3 -XPOST -d value='hello etcd 1'
??? curl -s 'http://127.0.0.1:4001/v2/keys/message3?recursive=true&sorted=true'
創(chuàng)建目錄:
??? curl -s http://127.0.0.1:4001/v2/keys/message8 -XPUT -d dir=true
刪除目錄:
??? curl -s 'http://127.0.0.1:4001/v2/keys/message7?dir=true' -XDELETE
??? curl -s 'http://127.0.0.1:4001/v2/keys/message7?recursive=true' -XDELETE
查看所有key:
??? curl -s http://127.0.0.1:4001/v2/keys/?recursive=true
存儲數(shù)據(jù):
??? curl -s http://127.0.0.1:4001/v2/keys/file -XPUT --data-urlencode value@upfile
使用etcdctl客戶端:
存儲:
??? etcdctl set /liuyiling/testkey "610" --ttl '100'
???????????????????????????????????????? --swap-with-value value
獲取:
??? etcdctl get /liuyiling/testkey
更新:
??? etcdctl update /liuyiling/testkey "world" --ttl '100'
?????? ?
刪除:
??? etcdctl rm /liuyiling/testkey
目錄管理:
??? etcdctl mk /liuyiling/testkey "hello"??? 類似set,但是如果key已經(jīng)存在,報錯
??? etcdctl mkdir /liuyiling
??? etcdctl setdir /liuyiling ?
??? etcdctl updatedir /liuyiling???? ?
??? etcdctl rmdir /liuyiling?? ?
查看:
??? etcdctl ls --recursive
監(jiān)視:
??? etcdctl watch mykey? --forever???????? +??? etcdctl update mykey "hehe"
??? ?
??? #監(jiān)視目錄下所有節(jié)點(diǎn)的改變
??? etcdctl exec-watch --recursive /foo -- sh -c "echo hi"
??? etcdctl exec-watch mykey -- sh -c 'ls -al'??? +??? etcdctl update mykey "hehe"
??? etcdctl member list
集群啟動步驟
1.啟動一個etcd,任意機(jī)器,如192.168.1.1:2379
2.curl -X PUT http://192.168.1.1:2379/v2/keys/discovery/6c007a14875d53d9bf0ef5a6fc0257c817f0f222/_config/size -d value=3
3.etcd -name machine1 -initial-advertise-peer-urls http://127.0.0.1:2380 -listen-peer-urls http://127.0.0.1:2380 -discovery http://192.168.1.1:2379/v2/keys/discovery/6c007a14875d53d9bf0ef5a6fc0257c817f0f222
4.如果是在三臺不同的服務(wù)器上,則重復(fù)上面的命令3次,否則重復(fù)上面的命令1次+下面的命令2次
etcd -name machine2 -discovery http://192.168.1.1:2379/v2/keys/discovery/6c007a14875d53d9bf0ef5a6fc0257c817f0f222 -addr 127.0.0.1:2389 -bind-addr 127.0.0.1:2389 -peer-addr 127.0.0.1:2390 -peer-bind-addr 127.0.0.1:2390
etcd -name machine3 -discovery http://192.168.1.1:2379/v2/keys/discovery/6c007a14875d53d9bf0ef5a6fc0257c817f0f222 -addr 127.0.0.1:2409 -bind-addr 127.0.0.1:2409 -peer-addr 127.0.0.1:2490 -peer-bind-addr 127.0.0.1:2490
5.curl -L http://localhost:2379/v2/members | python -m json.tool
???????????????
總結(jié)
- 上一篇: Etcd项目介绍
- 下一篇: Twitter-Snowflake,64