docker-compose 安装 etcd
etcd官网
windows安装
https://github.com/etcd-io/etcd/releases
linux安装
源码安装
https://blog.csdn.net/Mr_XiMu/article/details/127923827
yum安装
版本一般比较老
docker命令安装
确认有docker环境
docker run --name etcd -d -p 2379:2379 -p 2380:2380 -e ALLOW_NONE_AUTHENTICATION=yes bitnami/etcd:3.3.11 etcd
docker-compose安装
确认有docker-compose 环境
docker-compose.yaml
version: "3"
services:
etcd:
container_name: etcd
hostname: etcd
image: bitnami/etcd:3
deploy:
replicas: 1
restart_policy:
condition: on-failure
# ports:
# - "2379:2379"
# - "2380:2380"
# - "4001:4001"
# - "7001:7001"
privileged: true
volumes:
- "~/DockerConfig/etcd/data:/bitnami/etcd/data"
environment:
- "ETCD_ADVERTISE_CLIENT_URLS=http://0.0.0.0:2379"
- "ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379"
- "ETCD_LISTEN_PEER_URLS=http://0.0.0.0:2380"
- "ETCD_INITIAL_ADVERTISE_PEER_URLS=http://0.0.0.0:2380"
#参数指不用密码可以连接
- "ALLOW_NONE_AUTHENTICATION=yes"
- "ETCD_INITIAL_CLUSTER=node1=http://0.0.0.0:2380"
- "ETCD_NAME=node1"
- "ETCD_DATA_DIR=/opt/bitnami/etcd/data"
ports:
- 2379:2379
- 2380:2380
networks:
- etcdnet
etcdkeeper:
image: deltaprojects/etcdkeeper
container_name: etcdkeeper
ports:
- 8088:8080
networks:
- etcdnet
networks:
etcdnet:
name: etcdnet
启动服务
docker-compose up -d
向etcd写入数据
docker exec -it etcd /bin/bash
etcdctl set /name haima4
etcdctl get /name
访问 etcdkeeper
etcdkeeper 查看数据
http://192.168.2.47:8088/etcdkeeper/
打开后连接服务地址
192.168.2.47:2379 # 宿主主机地址加端口号
或者 etch的容器名称加端口号
etcd:2379 # etch的容器名称
以上都了是在etcdkeeper容器内可以访问到的etcd服务地址
常用操作
// 设置或更新值
etcdctl put name 张三
// 获取值
etcdctl get name
// 只要value
etcdctl get name --print-value-only
// 获取name前缀的键值对
etcdctl get --prefix name
// 获取所有的键值对
etcdctl get "" --from-key
// 删除键值对
etcdctl del name
// 监听键的变化
etcdctl watch name
参考文档
etcd windows安装 https://www.cnblogs.com/wujuntian/p/12837926.html
etcdctl指令 https://www.jianshu.com/p/67cbef492812
[Haima的博客]
http://www.cnblogs.com/haima/