🚀
Docker — 从入门到实践
  • 前言
  • 修订记录
  • 如何贡献
  • Docker 简介
    • 什么是 Docker
    • 为什么要用 Docker
  • 基本概念
    • 镜像
    • 容器
    • 仓库
  • 安装 Docker
    • Ubuntu
    • Debian
    • Fedora
    • CentOS
    • Raspberry Pi
    • Linux 离线安装
    • macOS
    • Windows 10
    • 镜像加速器
    • 开启实验特性
  • 使用镜像
    • 获取镜像
    • 列出镜像
    • 删除本地镜像
    • 利用 commit 理解镜像构成
    • 使用 Dockerfile 定制镜像
    • Dockerfile 指令详解
      • COPY 复制文件
      • ADD 更高级的复制文件
      • CMD 容器启动命令
      • ENTRYPOINT 入口点
      • ENV 设置环境变量
      • ARG 构建参数
      • VOLUME 定义匿名卷
      • EXPOSE 暴露端口
      • WORKDIR 指定工作目录
      • USER 指定当前用户
      • HEALTHCHECK 健康检查
      • ONBUILD 为他人作嫁衣裳
      • LABEL 为镜像添加元数据
      • SHELL 指令
      • 参考文档
    • Dockerfile 多阶段构建
      • 实战多阶段构建 Laravel 镜像
    • 构建多种系统架构支持的 Docker 镜像
    • 其它制作镜像的方式
    • 实现原理
  • 操作容器
    • 启动
    • 守护态运行
    • 终止
    • 进入容器
    • 导出和导入
    • 删除
  • 访问仓库
    • Docker Hub
    • 私有仓库
    • 私有仓库高级配置
    • Nexus 3
  • 数据管理
    • 数据卷
    • 挂载主机目录
  • 使用网络
    • 外部访问容器
    • 容器互联
    • 配置 DNS
  • 高级网络配置
    • 快速配置指南
    • 容器访问控制
    • 端口映射实现
    • 配置 docker0 网桥
    • 自定义网桥
    • 工具和示例
    • 编辑网络配置文件
    • 配置 HTTP/HTTPS 网络代理
    • 实例:创建一个点到点连接
  • Docker Buildx
    • BuildKit
    • 使用 buildx 构建镜像
    • 使用 buildx 构建多种系统架构支持的 Docker 镜像
  • Docker Compose
    • 简介
    • Compose v2
    • 安装与卸载
    • 使用
    • 命令说明
    • Compose 模板文件
    • 实战 Django
    • 实战 Rails
    • 实战 WordPress
    • 实战 LNMP
  • Swarm mode
    • 基本概念
    • 创建 Swarm 集群
    • 部署服务
    • 使用 compose 文件
    • 管理密钥
    • 管理配置信息
    • 滚动升级
  • 安全
    • 内核命名空间
    • 控制组
    • 服务端防护
    • 内核能力机制
    • 其它安全特性
    • 总结
  • 底层实现
    • 基本架构
    • 命名空间
    • 控制组
    • 联合文件系统
    • 容器格式
    • 网络
  • Etcd 项目
    • 简介
    • 安装
    • 集群
    • 使用 etcdctl
  • Fedora CoreOS
    • 简介
    • 安装
  • Kubernetes - 开源容器编排引擎
    • 简介
    • 基本概念
    • 架构设计
  • 部署 Kubernetes
    • 使用 kubeadm 部署 kubernetes(CRI 使用 containerd)
    • 在 Docker Desktop 使用
    • 一步步部署 kubernetes 集群
    • 部署 Dashboard
  • Kubernetes 命令行 kubectl
  • 容器与云计算
    • 简介
    • 腾讯云
    • 阿里云
    • 亚马逊云
    • 小结
  • 实战案例 - 操作系统
    • Busybox
    • Alpine
    • Debian Ubuntu
    • CentOS Fedora
    • 本章小结
  • 实战案例 - CI/CD
    • GitHub Actions
    • Drone
      • 部署 Drone
  • 在 IDE 中使用 Docker
    • VS Code
  • podman - 下一代 Linux 容器工具
  • 附录
    • 附录一:常见问题总结
    • 附录二:热门镜像介绍
      • Ubuntu
      • CentOS
      • Nginx
      • PHP
      • Node.js
      • MySQL
      • WordPress
      • MongoDB
      • Redis
      • Minio
    • 附录三:Docker 命令查询
      • 客户端命令 - docker
      • 服务端命令 - dockerd
    • 附录四:Dockerfile 最佳实践
    • 附录五:如何调试 Docker
    • 附录六:资源链接
由 GitBook 提供支持
在本页
  • 数据库操作
  • put
  • get
  • del
  • 非数据库操作
  • watch
  • member

这有帮助吗?

在GitHub上编辑
  1. Etcd 项目

使用 etcdctl

上一页集群下一页Fedora CoreOS

最后更新于3年前

这有帮助吗?

etcdctl 是一个命令行客户端,它能提供一些简洁的命令,供用户直接跟 etcd 服务打交道,而无需基于 HTTP API 方式。这在某些情况下将很方便,例如用户对服务进行测试或者手动修改数据库内容。我们也推荐在刚接触 etcd 时通过 etcdctl 命令来熟悉相关的操作,这些操作跟 HTTP API 实际上是对应的。

etcd 项目二进制发行包中已经包含了 etcdctl 工具,没有的话,可以从 下载。

etcdctl 支持如下的命令,大体上分为数据库操作和非数据库操作两类,后面将分别进行解释。

NAME:
	etcdctl - A simple command line client for etcd3.

USAGE:
	etcdctl

VERSION:
	3.4.0

API VERSION:
	3.4


COMMANDS:
	get			Gets the key or a range of keys
	put			Puts the given key into the store
	del			Removes the specified key or range of keys [key, range_end)
	txn			Txn processes all the requests in one transaction
	compaction		Compacts the event history in etcd
	alarm disarm		Disarms all alarms
	alarm list		Lists all alarms
	defrag			Defragments the storage of the etcd members with given endpoints
	endpoint health		Checks the healthiness of endpoints specified in `--endpoints` flag
	endpoint status		Prints out the status of endpoints specified in `--endpoints` flag
	watch			Watches events stream on keys or prefixes
	version			Prints the version of etcdctl
	lease grant		Creates leases
	lease revoke		Revokes leases
	lease timetolive	Get lease information
	lease keep-alive	Keeps leases alive (renew)
	member add		Adds a member into the cluster
	member remove		Removes a member from the cluster
	member update		Updates a member in the cluster
	member list		Lists all members in the cluster
	snapshot save		Stores an etcd node backend snapshot to a given file
	snapshot restore	Restores an etcd member snapshot to an etcd directory
	snapshot status		Gets backend snapshot status of a given file
	make-mirror		Makes a mirror at the destination etcd cluster
	migrate			Migrates keys in a v2 store to a mvcc store
	lock			Acquires a named lock
	elect			Observes and participates in leader election
	auth enable		Enables authentication
	auth disable		Disables authentication
	user add		Adds a new user
	user delete		Deletes a user
	user get		Gets detailed information of a user
	user list		Lists all users
	user passwd		Changes password of user
	user grant-role		Grants a role to a user
	user revoke-role	Revokes a role from a user
	role add		Adds a new role
	role delete		Deletes a role
	role get		Gets detailed information of a role
	role list		Lists all roles
	role grant-permission	Grants a key to a role
	role revoke-permission	Revokes a key from a role
	check perf		Check the performance of the etcd cluster
	help			Help about any command

OPTIONS:
      --cacert=""				verify certificates of TLS-enabled secure servers using this CA bundle
      --cert=""					identify secure client using this TLS certificate file
      --command-timeout=5s			timeout for short running command (excluding dial timeout)
      --debug[=false]				enable client-side debug logging
      --dial-timeout=2s				dial timeout for client connections
      --endpoints=[127.0.0.1:2379]		gRPC endpoints
      --hex[=false]				print byte strings as hex encoded strings
      --insecure-skip-tls-verify[=false]	skip server certificate verification
      --insecure-transport[=true]		disable transport security for client connections
      --key=""					identify secure client using this TLS key file
      --user=""					username[:password] for authentication (prompt if password is not supplied)
  -w, --write-out="simple"			set the output format (fields, json, protobuf, simple, table)

数据库操作

数据库操作围绕对键值和目录的 CRUD (符合 REST 风格的一套操作:Create)完整生命周期的管理。

etcd 在键的组织上采用了层次化的空间结构(类似于文件系统中目录的概念),用户指定的键可以为单独的名字,如 testkey,此时实际上放在根目录 / 下面,也可以为指定目录结构,如 cluster1/node2/testkey,则将创建相应的目录结构。

注:CRUD 即 Create, Read, Update, Delete,是符合 REST 风格的一套 API 操作。

put

$ etcdctl put /testdir/testkey "Hello world"
OK

get

获取指定键的值。例如

$ etcdctl put testkey hello
OK
$ etcdctl get testkey
testkey
hello

支持的选项为

--sort 对结果进行排序

--consistent 将请求发给主节点,保证获取内容的一致性

del

删除某个键值。例如

$ etcdctl del testkey
1

非数据库操作

watch

监测一个键值的变化,一旦键值发生更新,就会输出最新的值。

例如,用户更新 testkey 键值为 Hello world。

$ etcdctl watch testkey
PUT
testkey
2

member

通过 list、add、update、remove 命令列出、添加、更新、删除 etcd 实例到 etcd 集群中。

例如本地启动一个 etcd 服务实例后,可以用如下命令进行查看。

$ etcdctl member list
422a74f03b622fef, started, node1, http://172.16.238.100:2380, http://172.16.238.100:23
github.com/etcd-io/etcd/releases