etcdctl支持下面列出来的命令,基本上可以分为数据库操作和非数据库操作,可以查看etcdctl README.md来了解更多

➜  ~  etcdctl -h
NAME:
etcdctl - A simple command line client for etcd. USAGE:
etcdctl [global options] command [command options] [arguments...] VERSION:
2.2.1 COMMANDS:
backup backup an etcd directory
cluster-health check the health of the etcd cluster
mk make a new key with a given value
mkdir make a new directory
rm remove a key or a directory
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
import import a snapshot to a cluster
user user add, grant and revoke subcommands
role role add, grant and revoke subcommands
auth overall auth controls
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`, `extended` or `json`)
--discovery-srv, -D domain name to query for SRV records describing cluster endpoints
--peers, -C a comma-delimited list of machine addresses in the cluster (default: "http://127.0.0.1:4001,http://127.0.0.1:2379")
--endpoint a comma-delimited list of machine addresses in the cluster (default: "http://127.0.0.1:4001,http://127.0.0.1:2379")
--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
--username, -u provide username[:password] and prompt if password is not supplied.
--timeout '1s' connection timeout per request
--total-timeout '5s' timeout for the command execution (except watch)
--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 get /testdir/testkey
Hello world

当键不存在时,则会报错。例如

➜  ~  etcdctl get /testdir/testkey2
Error: 100: Key not found (/testdir/testkey2) [18]

支持的选项为

--sort    对结果进行排序
--consistent 将请求发给主节点,保证获取内容的一致性

update

当键存在时,更新值内容。例如

➜  ~  etcdctl update /testdir/testkey "Hello"
Hello

当键不存在时,则会报错。例如

➜  ~  etcdctl update /testdir/testkey2 "Hello"
Error: 100: Key not found (/testdir/testkey2) [19]

支持的选项为

--ttl '0'    超时时间(单位为秒),不配置(默认为 0)则永不超时

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 是否匹配

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)则永不超时

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)则永不超时

rmdir

删除一个空目录,或者键值对。

➜  ~  etcdctl setdir dir1
➜ ~ etcdctl rmdir dir1

若目录不空,会报错

➜  ~  etcdctl set /dir/testkey hi
hi
➜ ~ etcdctl rmdir /dir
Error: 108: Directory not empty (/dir) [29]

ls

列出目录(默认为根目录)下的键或者子目录,默认不显示子目录中内容。

例如

➜  ~  etcdctl ls
/testdir
/testdir2
/dir
➜ ~ etcdctl ls dir
/dir/testkey

支持的选项包括

--sort    将输出结果排序
--recursive 如果目录下有子目录,则递归输出其中的内容
-p 对于输出为目录,在最后添加 `/` 进行区分

非数据库操作

backup

备份 etcd 的数据。

支持的选项包括

--data-dir         etcd 的数据目录
--backup-dir 备份到指定路径

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

通过 list、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 打印版本信息

etcd命令的更多相关文章

  1. etcd 命令行(转)

    原文 https://www.cnblogs.com/breg/p/5756558.html 比较重要的配置 -name 节点名称,默认是UUID-data-dir 保存日志和快照的目录,默认为当前工 ...

  2. etcd 命令行

    比较重要的配置 -name 节点名称,默认是UUID-data-dir 保存日志和快照的目录,默认为当前工作目录-addr 公布的ip地址和端口. 默认为127.0.0.1:2379-bind-add ...

  3. etcd命令说明 etcd Version: 3.0.15

    etcd Version: 3.0.15Git SHA: fc00305Go Version: go1.6.3Go OS/Arch: linux/amd64 https://github.com/co ...

  4. Etcd学习(二)集群搭建Clustering

    1.单个etcd节点(测试开发用) 之前我一直开发测试一直是用的一个Etcd节点,然后启动命令一直都是直接打一个etcd(我已经将etcd安装目录的bin目录加入到PATH环 境变量中),然后启动信息 ...

  5. ETCD集群安装实验

    目录 [1.下载二进制程序] [2.安装etcd集群] [3.查询集群状态] [4.存入读取数据] [5.注意事项] [6.参考链接] 简介:     Etcd的官网文档及其在GitHub上的文档,已 ...

  6. etcd集群部署与遇到的坑

    在k8s集群中使用了etcd作为数据中心,在实际操作中遇到了一些坑.今天记录一下,为了以后更好操作. ETCD参数说明 —data-dir 指定节点的数据存储目录,这些数据包括节点ID,集群ID,集群 ...

  7. etcd集群部署与遇到的坑(转)

    原文 https://www.cnblogs.com/breg/p/5728237.html etcd集群部署与遇到的坑 在k8s集群中使用了etcd作为数据中心,在实际操作中遇到了一些坑.今天记录一 ...

  8. ETCD 简介 + 使用

    etcd简介 etcd是一个高可用的分布式键值(key-value)数据库.etcd内部采用raft协议作为一致性算法,etcd基于Go语言实现. etcd是一个服务发现系统,具备以下的特点: 简单: ...

  9. Kubernetes1.91(K8s)安装部署过程(三)--创建高可用etcd集群

    这里的etcd集群复用我们测试的3个节点,3个node都要安装并启动,注意修改配置文件 1.TLS认证文件分发:etcd集群认证用,除了本机有,分发到其他node节点 scp ca.pem kuber ...

随机推荐

  1. 蓝屏代码stop:0X000000EA(0X85E286B8,0X8635F210,0XF7A53CBC,0X00000001)

    你这是显卡驱动问题,我把蓝屏代码都给你,以后在出现蓝屏自己看看行了. 1.0x0000000A:IRQL_NOT_LESS_OR_EQUAL ◆错误分析:主要是由问题的驱动程序.有缺陷或不兼容的硬件与 ...

  2. Django与Vue语法冲突问题完美解决方法

    当我们在django web框架中,使用vue的时候,会遇到语法冲突. 因为vue使用{{}},而django也使用{{}},因此会冲突. 解决办法1: 在django1.5以后,加入了标签: {% ...

  3. full_case parallel_case学习心得

    一般情况下,DC把case语句综合成选择器电路,但也可能把case语句综合成优先权译码电路.有时,优先权译码电路是不必要的,这是可以使用“// synopsys parallel_case”引导语句强 ...

  4. HDU - 1272 小希的迷宫 【并查集】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1272 思路 只需要判断 这张图 无环 并且只有一个连通块 就可以了 要注意 如果 只输入 0 0 那给 ...

  5. expr 数字操作

    expr 可以用于计算 [root@rhel6 script]# * * [root@rhel6 script]# 使用expr来判断输入的变量是否为整数, 注意这里的&表示  安静模式(没有 ...

  6. 2014年的暑假ACM之旅!

    致未来的我: 回到学校了,又开始了繁忙的生活! 虽然每天都不太轻松,但还是蛮有乐趣的,一起讨论某道题或者某种算法时挺开心的.@我.@姜维波.@曹彦宝.@李岩.@张永宏 继续这样下去,直到这个暑假的结束 ...

  7. maven pom filter 导致的问题记录

    Maven提供了一个很不错的功能 Resource Filter, 可以将按不同环境的进行变量赋值, 比如数据库链接, redis, 日志输出位置等等.. 具体的filter如何使用我这里不做介绍, ...

  8. LightOJ 1138 二分

    1138 - Trailing Zeroes (III)   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: ...

  9. php/js/linux: js加密(rsa公钥加密) php解密(rsa私钥解密)

    php/js/linux: js加密(rsa公钥加密) php解密(rsa私钥解密) 一: js rsa 插件 https://github.com/UFO0001/WX_RSA 或者: https: ...

  10. 分享知识-快乐自己:JS 检查元素是否含有某种css样式

    第一种 原生 JS: ************************************************************* 结构部分: <div> <p> ...