使用etcdctl客户端
$ etcdctl [全局选项]命令[命令选项] [命令参数]
1、数据类操作
1.1 set
$ etcdctl set /testdir/testkey "Hello world"
Hello world
1.2 get
$ etcdctl set testkey hello
hello
$ etcdctl update testkey world
world
$ etcdctl get testkey2
Error: 100: Key not found (/testkey2)
1.3 update
$ etcdctl set testkey hello
hello
$ etcdctl update testkey world
world
$ etcdctl update testkey2 world
Error: 100: Key not found (/testkey2)
1.4 mk
$ etcdctl mk /testdir/testkey "Hello world"
Hello world
$ etcdctl set testkey "Hello world"
Hello world
$ ./etcdctl mk testkey "Hello world"
Error: 105: Key already exists (/testkey)
1.5 rm
$ etcdctl rm testkey
$ etcdctl rm testkey2
Error: 100: Key not found (/testkey2)
1.6 watch
$ etcdctl watch testkey
Hello world
1.7 exec-watch
$ etcdctl exec-watch testkey -- sh -c 'ls'
default.etcd
Documentation
etcd
etcdctl
etcd-migrate
README-etcdctl.md
README.md
1.8 ls
$ ./etcdctl set testkey 'hi'
hi
$ ./etcdctl set dir/test 'hello'
hello
$ ./etcdctl ls
/testkey
/dir
$ ./etcdctl ls dir
/dir/test
1.9 mkdir
$ etcdctl mkdir testdir
$ etcdctl mkdir testdir
$ etcdctl mkdir testdir
Error: 105: Key already exists (/testdir)
1.10 rmdir
$ etcdctl set /dir/testkey hi
hi
$ etcdctl rmdir /dir
Error: 108: Directory not empty (/dir)
1.11 setdir
$ etcdctl setdir /test/test
$ etcdctl ls --recursive
/test
/test/test
1.12 updatedir
$ etcdctl mkdir /test/test --ttl 100
$ etcdctl updatedir /test/test --ttl 200
2、非数据类操作
2.1 backup
$ etcdctl backup --data-dir default.etcd --backup-dir tmp
$ ls tmp/member
snap wal
2.2 cluster-health
$ etcdctl cluster-health
member ce2a822cea30bfca is healthy: got healthy result from http://localhost:2379
cluster is healthy
2.3 member
$ etcdctl member list
ce2a822cea30bfca: name=default peerURLs=http://localhost:2380,http://localhost:
7001 clientURLs=http://localhost:2379,http://localhost:4001
2.4 import
$ etcdctl import --snap tmp/member/snap/0000000000000003-0000000000061aa8.snap
starting to import snapshot tmp/member/snap/0000000000000003-0000000000061aa8.
snap with 10 clients
entering dir: /
copying key: /key 1
finished importing 1 keys
2.5 user
$ etcdctl user add root
New password:
$ etcdctl user add testuser
New password:
$ etcdctl user grant testuser -roles testrole
2.6 role
$ etcdctl role add testrole
$ etcdctl role grant testrole -path '/key/*' -read
2.7 auth
$ etcdctl auth enable
👑👑👑结束语👑👑👑