etcd常用コマンド使用マニュアル

7062 ワード

Etcd常用命令整理
etcdのインストールとクラスタ導入のリファレンスリンク:https://blog.csdn.net/WangYouJin321/article/details/80417622
1.Etcdの起動と基本操作
1.etcdctlクライアントによる操作2.curl方式(紹介しない)
etcdを起動するには:
[root@wangyoujin software]# cd etcd/
[root@wangyoujin etcd]# ./etcd
デフォルトのデータストアファイル(設定可能):
2017/09/18 14:36:04 no data-dir provided,using default data-dir ./default.etcd
2017/09/18 14:36:04 etcd: listen tcp 127.0.0.1:2380: bind: address already inuse
[root@wangyoujin etcd]# ls
default.etcd  Documentation etcd  etcd-backup  etcdctl etcd-migrate README-etcdctl.md  README.md  rm.sh
 
Etcdのインストールが完了したらetcdctlクライアントで関連操作を行うことができ、一般的なcommandsは下図の赤い丸の部分のようです.
 
 
etcdctlの使用に関する注意:
1ディレクトリはディレクトリで、ノードはノードで、一意性があり、名前を変更できません.
2ディレクトリは唯一存在し、最終的なリーフノードは必ずしも
3バージョン2と3の違いは、同じバージョンを読み書きで使用することを堅持し、このドキュメントは2を例に説明しています.
 
 
2.Etcd常用コマンド
setとmk
キーの値を指定します.たとえば
./etcdctl set /testdir/testkey "Hello world"
Hello world

サポートされるオプションは次のとおりです.
--ttl '0'                    (    ),   (    0--swap-with-value value          value,       
--swap-with-index '0'                  ,       

MK
指定したキーが存在しない場合は、新しいキー値が作成されます.たとえば
./etcdctl mk /testdir/testkey "Hello world"
Hello world

キーが存在する場合、コマンドを実行するとエラーが表示されます.たとえば、
./etcdctl mk /testdir/testkey "Hello world"
Error:  105: Key already exists (/testdir/testkey) [21]

サポートされているオプションは次のとおりです.
--ttl '0'        (    ),   (    0

 
get
指定したキーの値を取得します.たとえば
./etcdctl get /testdir/testkey
Hello world

キーが存在しない場合は、エラーが表示されます.たとえば
./etcdctl get /testdir/testkey2
Error:  100: Key not found (/testdir/testkey2) [18]

サポートされているオプションは次のとおりです.
--sort           
--consistent 

update
キーが存在する場合、値の内容が更新されます.たとえば
[root@wangyoujin etcd]# ./etcdctl mknewdir/wang/shuai "haoshuai"
haoshuai
[root@wangyoujin etcd]# ./etcdctl updatenewdir/wang/shuai "zhendehaoshuai"
zhendehaoshuai
[root@wangyoujin etcd]# ./etcdctl getnewdir/wang/shuai
zhendehaoshuai
rm
キー値を削除します.たとえば
./etcdctl rm /testdir/testkey
PrevNode.Value: Hello

キーが存在しない場合は、エラーが表示されます.たとえば
./etcdctl rm /testdir/testkey
Error:  100: Key not found (/testdir/testkey) [20]

サポートされているオプションは次のとおりです.
--dir                        
--recursive                 
--with-value               
--with-index '0'          index     

rmdir
removes the key if it is an empty directory or akey-value pair
キー値または空のディレクトリの削除
wangの下のノードは削除され、空のディレクトリになりました
[root@wangyoujin etcd]# ./etcdctl rm newdir/wang
Error:  102: Not a file (/newdir/wang) [587532]
 
[root@wangyoujin etcd]# ./etcdctl rmdir newdir/wang
[root@wangyoujin etcd]#
[root@wangyoujin etcd]# ./etcdctl ls/newdir
/newdir/testkey2
/newdir/testkey3
Etcdクリア:-recursive=true、ルートディレクトリの削除
[root@wangyoujin etcd]# ./etcdctl rm/newdir
Error: 102: Not a file (/newdir) [589640]
[root@wangyoujin etcd]# ./etcdctl rm/newdir-recursive=true
[root@wangyoujin etcd]# ./etcdctl ls/newdir
Error: 100: Key not found (/newdir) [589694]
[root@wangyoujin etcd]#
 
mkdir
指定したキーディレクトリが存在しない場合は、新しいキーディレクトリを作成します.たとえば
➜  ~  etcdctl mkdir testdir2

キーディレクトリが存在する場合、このコマンドを実行するとエラーが表示されます.たとえば、
➜  ~  etcdctl mkdir testdir2
Error:  105: Key already exists (/testdir2) [22]

サポートされているオプションは次のとおりです.
--ttl '0'        (    ),   (    0

setdir
存在するかどうかにかかわらず、キーディレクトリを作成します.
サポートされているオプションは次のとおりです.
--ttl '0'        (    ),   (    0

updatedir
既存のディレクトリを更新します.サポートされているオプションは次のとおりです.
--ttl '0'        (    ),   (    0

データベース以外の操作
watch
キー値の変化をモニタし、キー値が更新されると最新の値が出力され、終了します.
例えば、ユーザ更新testkeyキー値はHello watchである.
➜  ~  etcdctl get /testdir/testkey
Hello world
  ➜  ~  etcdctl set /testdir/testkey "Hello watch"
Hello watch

 
➜  ~  etcdctl watch testdir/testkey
Hello watch

サポートされているオプションは次のとおりです.
--forever            ,      `CTRL+C`   
--after-index '0'        index       
--recursive                   

exec-watch
キー値の変化を監視し、キー値が更新されると、所定のコマンドを実行します.
たとえば、ユーザーはtestkeyキー値を更新します.
➜  ~  etcdctl exec-watch testkey -- sh -c 'ls'
default.etcd
Documentation
etcd
etcdctl
etcd-migrate
README-etcdctl.md
README.md

サポートされているオプションは次のとおりです.
--after-index '0'        index       
--recursive                   

member
リスト、add、removeコマンドを使用して、etcdインスタンスをetcdクラスタにリスト、追加、削除します.
たとえば、etcdサービスインスタンスをローカルで起動した後、次のコマンドで表示できます.
$ etcdctl member list
ce2a822cea30bfca: name=default peerURLs=http://localhost:2380,http://localhost:7001 clientURLs=http://localhost:2379,http://localhost:4001

コマンドオプション
--debug    cURL   ,              
--no-sync              
--output, -o 'simple'         (simple      ,json    json    ,      )
--peers, -C           ,      (   : "127.0.0.1:4001")
--cert-file HTTPS         SSL     
--key-file HTTPS         SSL     
--ca-file       HTTPS  ,   CA       
--help, -h         
--version, -v