docker_practice/etcd/etcdctl-v2.md

282 lines
8.0 KiB
Go
Raw Normal View History

2017-12-03 05:57:02 +00:00
## 使 etcdctl v2
`etcdctl` `etcd` `HTTP API` 便 `etcd` `etcdctl` `HTTP API`
2019-08-31 14:57:43 +00:00
`etcd` `etcdctl` [github.com/etcd-io/etcd/releases](https://github.com/etcd-io/etcd/releases) 下载。
2017-12-03 05:57:02 +00:00
`etcdctl`
```
$ etcdctl -h
NAME:
etcdctl - A simple command line client for etcd.
USAGE:
etcdctl [global options] command [command options] [arguments...]
VERSION:
2.0.0-rc.1
COMMANDS:
backup backup an etcd directory
mk make a new key with a given value
mkdir make a new directory
rm remove a key
rmdir removes the key if it is an empty directory or a key-value pair
get retrieve the value of a key
ls retrieve a directory
set set the value of a key
setdir create a new or existing directory
update update an existing key with a given value
updatedir update an existing directory
watch watch a key for changes
exec-watch watch a key for changes and exec an executable
member member add, remove and list subcommands
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--debug output cURL commands which can be used to reproduce the request
--no-sync don't synchronize cluster information before sending request
--output, -o 'simple' output response in the given format (`simple` or `json`)
--peers, -C a comma-delimited list of machine addresses in the cluster (default: "127.0.0.1:4001")
--cert-file identify HTTPS client using this SSL certificate file
--key-file identify HTTPS client using this SSL key file
--ca-file verify certificates of HTTPS-enabled servers using this CA bundle
--help, -h show help
--version, -v print the version
```
###
CRUD REST Create
etcd `testkey` `/` `cluster1/node2/testkey`
*CRUD Create, Read, Update, Delete REST API *
#### set
```bash
$ etcdctl set /testdir/testkey "Hello world"
Hello world
```
```bash
--ttl '0' 0
--swap-with-value value value
--swap-with-index '0'
```
#### get
```bash
$ etcdctl set testkey hello
hello
$ etcdctl update testkey world
world
```
```bash
$ etcdctl get testkey2
Error: 100: Key not found (/testkey2) [1]
```
```bash
--sort
--consistent
```
#### update
```bash
$ etcdctl set testkey hello
hello
$ etcdctl update testkey world
world
```
```bash
$ etcdctl update testkey2 world
Error: 100: Key not found (/testkey2) [1]
```
```bash
--ttl '0' 0
```
#### rm
```bash
$ etcdctl rm testkey
```
```bash
$ etcdctl rm testkey2
Error: 100: Key not found (/testkey2) [8]
```
```bash
--dir
--recursive
--with-value
--with-index '0' index
```
#### mk
```bash
$ etcdctl mk /testdir/testkey "Hello world"
Hello world
```
```bash
$ etcdctl set testkey "Hello world"
Hello world
$ ./etcdctl mk testkey "Hello world"
Error: 105: Key already exists (/testkey) [2]
```
```bash
--ttl '0' 0
```
#### mkdir
```bash
$ etcdctl mkdir testdir
```
```bash
$ etcdctl mkdir testdir
$ etcdctl mkdir testdir
Error: 105: Key already exists (/testdir) [7]
```
```bash
--ttl '0' 0
```
#### setdir
```bash
--ttl '0' 0
```
#### updatedir
```bash
--ttl '0' 0
```
#### rmdir
```bash
$ etcdctl set /dir/testkey hi
hi
$ etcdctl rmdir /dir
Error: 108: Directory not empty (/dir) [13]
```
#### ls
```bash
$ ./etcdctl set testkey 'hi'
hi
$ ./etcdctl set dir/test 'hello'
hello
$ ./etcdctl ls
/testkey
/dir
$ ./etcdctl ls dir
/dir/test
```
```bash
--sort
--recursive
-p `/`
```
###
#### backup
etcd
```bash
--data-dir etcd
--backup-dir
```
#### watch
退
testkey Hello world
```bash
$ etcdctl watch testkey
Hello world
```
```bash
--forever `CTRL+C` 退
--after-index '0' index
--recursive
```
#### exec-watch
testkey
```bash
$ etcdctl exec-watch testkey -- sh -c 'ls'
default.etcd
Documentation
etcd
etcdctl
etcd-migrate
README-etcdctl.md
README.md
```
```bash
--after-index '0' index
--recursive
```
#### member
listaddremove etcd etcd
etcd
```bash
$ 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`