etcd常用命令

設置環境變量,版本3,etcdctl的版本2和版本3並不兼容。
export ETCDCTL_API=3

增、查、刪
etcdctl put /testdir/testkey "Hello world1"
etcdctl get /testdir/testkey
etcdctl del /testdir/testkey

可以把key理解成目錄
etcdctl put /testdir/testkey1 "Hello world1"
etcdctl put /testdir/testkey2 "Hello world2"
etcdctl put /testdir/testkey3 "Hello world3"

批量獲取目錄下的內容
etcdctl get /testdir/ --prefix
只看key
etcdctl get /testdir/ --prefix --keys-only
只看value
etcdctl get /testdir/ --prefix --print-value-only


//watch監聽key
etcdctl watch /wt/k 開啓監聽
另一啓動一個客戶端
etcdctl put /wt/k v1 有反應
etcdctl put /wt/k v2 有反應
etcdctl get /wt/k 沒反應
etcdctl del /wt/k 有反應

租約(可以理解成定時器,把key綁定上之後,到時間了key就被刪除了)
創建一個
etcdctl lease grant 60
會生成一個id,類似下面
lease 694d6f805c9ed235 granted with TTL(60s)
創建一條數據並綁定到上面租約上
etcdctl put --lease=694d6f805c9ed235 "kkk" "vvv"
馬上獲取數據
etcdctl get kkk 可以獲取到
過一會再執行 etcdctl get kkk 獲取的是空數據

可以刪除租約(對應的key也會被直接刪除)
etcdctl lease revoke 694d6f805c9ed235

可以續租(繼續續60s)
etcdctl lease keep-alive 694d6f805c9ed235

權限控制下一篇單獨整理

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章