docker 部署单节点的etcd以及 常用使用命令

docker部署etcd

复制代码
$ docker run -d --name etcd-server -p 2379:2379 -p 2380:2380 quay.io/coreos/etcd:v3.5.0 /usr/local/bin/etcd -name my-etcd-1 -advertise-client-urls http://0.0.0.0:2379 -listen-client-urls http://0.0.0.0:2379 -initial-advertise-peer-urls http://0.0.0.0:2380 -listen-peer-urls http://0.0.0.0:2380 -initial-cluster my-etcd-1=http://0.0.0.0:2380
Unable to find image 'quay.io/coreos/etcd:v3.5.0' locally
v3.5.0: Pulling from coreos/etcd
6022c6b01d76: Pull complete
1d97b1ec77fc: Pull complete
99ef4b690837: Pull complete
435b7bf0967c: Pull complete
17e4a5f7c1b5: Pull complete
5b0292999756: Pull complete
Digest: sha256:28759af54acd6924b2191dc1a1d096e2fa2e219717a21b9d8edf89717db3631b
Status: Downloaded newer image for quay.io/coreos/etcd:v3.5.0
ddcbe3db8e832a366d37a75f15ed35618e82928e79d31fe9e33f39627e97c114

验证 etcd 服务

可以使用 etcdctl 命令行工具验证 etcd 服务是否正常工作。

在主机上安装 etcdctl,安装方式如下:

macos:

复制代码
$ brew install etcd

其他系统:

  1. 访问etcd的GitHub发布页面(https://github.com/etcd-io/etcd/releases)来找到你想要的版本。

  2. 下载对应版本的etcdctl二进制文件。

  3. 将下载的文件移动到你的PATH中的一个目录,例如/usr/local/bin。

    下载etcdctl,替换为实际版本号

    $ curl -L https://github.com/etcd-io/etcd/releases/download/v{version}/etcd-v{version}-darwin-amd64.tar.gz -o etcd-v{version}-darwin-amd64.tar.gz

    解压缩

    $ tar xzvf etcd-v{version}-darwin-amd64.tar.gz

    将etcdctl移动到/usr/local/bin目录

    $ sudo mv etcd-v{version}-darwin-amd64/etcdctl /usr/local/bin/
    替换为你想要安装的etcdctl版本。

验证:

复制代码
$ etcdctl --endpoints=http://localhost:2379 endpoint health --write-out="json"

如果返回 {"endpoint":"http://localhost:2379","health":"true"},表示 etcd 服务运行正常。

常用使用命令

  1. 存储键值对:

    复制代码
    etcdctl --endpoints=http://localhost:2379 put mykey "myvalue"
  2. 读取键值对:

    复制代码
    etcdctl --endpoints=http://localhost:2379 get mykey
  3. 列出所有键值对:

    复制代码
    etcdctl --endpoints=http://localhost:2379 get --prefix ""
  4. 删除键值对:

    复制代码
    etcdctl --endpoints=http://localhost:2379 del mykey
  5. 查看 etcd 集群状态:

    复制代码
    etcdctl --endpoints=http://localhost:2379 endpoint status
  6. 备份 etcd 数据:

    复制代码
    etcdctl --endpoints=http://localhost:2379 snapshot save backup.db
  7. 恢复 etcd 数据:

    复制代码
    etcdctl snapshot restore backup.db --data-dir /path/to/etcd/data-dir
相关推荐
guo_wen_qiang5 小时前
docker的备份与迁移
运维·docker·容器
小小龙学IT8 小时前
Kubernetes 深度实践:架构、API 与避坑指南
容器·架构·kubernetes
cpolar技术支持10 小时前
外网测试机的异常传不回内网?自托管 Sentry,用 cpolar 打通错误上报链路
python·nginx·docker·cpolar·sentry
MrSYJ13 小时前
别人再问你路由表是啥,这篇文章摔它脸上
docker·云原生·kubernetes
羑悻14 小时前
穿越Docker内核迷雾:揭秘镜像分层存储的叠加态与卷挂载的多维空间穿梭技术
后端·docker·容器
for_ever_love__14 小时前
容器类型全家桶——list、tuple、dict、set 与推导式
python·容器·数据类型·大模型开发
筑梦之路15 小时前
docker-compose方式部署kafka集群(Kraft方式)——筑梦之路
docker·容器·kafka
JavaPub-rodert15 小时前
Docker 镜像地址总失效?基于 DockerHub 项目用 GitHub Actions 做一个自动检测状态页
docker·容器·github
天衍四九-16 小时前
Docker 进阶实战系列(一):容器镜像安全,最小镜像与非 Root 运行
安全·docker·eureka
天衍四九-16 小时前
Docker进阶实战系列(二):容器日志深度治理|驱动配置、自动切割、磁盘爆满彻底解决
docker·容器·eureka