当前位置:K88软件开发文章中心网站服务器框架Docker → 文章内容

Docker使用 etcdctl

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-23 14:09:55

由 Loen 创建,Carrie 最后一次修改 2016-02-24 etcdctl 是一个命令行客户端,它能提供一些简洁的命令,供用户直接跟 etcd 服务打交道,而无需基于 HTTP API 方式。这在某些情况下将很方便,例如用户对服务进行测试或者手动修改数据库内容。我们也推荐在刚接触 etcd 时通过 etcdctl 命令来熟悉相关的操作,这些操作跟 HTTP API 实际上是对应的。etcd 项目二进制发行包中已经包含了 etcdctl 工具,没有的话,可以从 github.com/coreos/etcd/releases 下载。etcdctl 支持如下的命令,大体上分为数据库操作和非数据库操作两类,后面将分别进行解释。$ etcdctl -hNAME: etcdctl - A simple command line client for etcd.USAGE: etcdctl [global options] command [command options] [arguments...]VERSION: 2.0.0-rc.1COMMANDS: 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 commandGLOBAL 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指定某个键的值。例如$ etcdctl set /testdir/testkey "Hello world"Hello world支持的选项包括:--ttl '0' 该键值的超时时间(单位为秒),不配置(默认为 0)则永不超时--swap-with-value value 若该键现在的值是 value,则进行设置操作--swap-with-index '0' 若该键现在的索引值是指定索引,则进行设置操作get获取指定键的值。例如$ etcdctl set testkey hellohello$ etcdctl update testkey worldworld当键不存在时,则会报错。例如$ etcdctl get testkey2Error: 100: Key not found (/testkey2) [1]支持的选项为--sort 对结果进行排序--consistent 将请求发给主节点,保证获取内容的一致性update当键存在时,更新值内容。例如$ etcdctl set testkey hellohello$ etcdctl update testkey worldworld当键不存在时,则会报错。例如$ etcdctl update testkey2 worldError: 100: Key not found (/testkey2) [1]支持的选项为--ttl '0' 超时时间(单位为秒),不配置(默认为 0)则永不超时rm删除某个键值。例如$ etcdctl rm testkey当键不存在时,则会报错。例如$ etcdctl rm testkey2Error: 100: Key not found (/testkey2) [8]支持的选项为--dir 如果键是个空目录或者键值对则删除--recursive 删除目录和所有子键--with-value 检查现有的值是否匹配--with-index '0' 检查现有的 index 是否匹配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) [2]支持的选项为--ttl '0' 超时时间(单位为秒),不配置(默认为 0)则永不超时mkdir如果给定的键目录不存在,则创建一个新的键目录。例如$ etcdctl mkdir testdir当键目录存在的时候,执行该命令会报错,例如$ etcdctl mkdir testdir$ etcdctl mkdir testdirError: 105: Key already exists (/testdir) [7]支持的选项为--ttl '0' 超时时间(单位为秒),不配置(默认为 0)则永不超时setdir创建一个键目录,无论存在与否。支持的选项为--ttl '0' 超时时间(单位为秒),不配置(默认为 0)则永不超时updatedir更新一个已经存在的目录。 支持的选项为--ttl '0' 超时时间(单位为秒),不配置(默认为 0)则永不超时rmdir删除一个空目录,或者键值对。若目录不空,会报错$ etcdctl set /dir/testkey hihi$ etcdctl rmdir /dirError: 108: Directory not empty (/dir) [13]ls列出目录(默认为根目录)下的键或者子目录,默认不显示子目录中内容。例如$ ./etcdctl set testkey 'hi'hi$ ./etcdctl set dir/test 'hello'hello$ ./etcdctl ls/testkey/dir$ ./etcdctl ls dir/dir/test支持的选项包括--sort 将输出结果排序--recursive 如果目录下有子目录,则递归输出其中的内容-p 对于输出为目录,在最后添加 `/` 进行区分非数据库操作backup备份 etcd 的数据。支持的

[1] [2]  下一页


Docker使用 etcdctl