docker-compose.yml 内容
version: "3.5"
services:
etcd:
container_name: etcd
hostname: etcd
image: bitnami/etcd:3
privileged: true
volumes:
- "/etcd/data:/opt/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
networks:
etcdnet:
name: etcdnet
安装
mkdir -p /etcd/data
docker-compose up -d
查看 etcd 的版本信息
docker exec -it etcd bash
etcd --version
通过 REST API 直接查看集群健康状态
curl -L http://127.0.0.1:2379/health
通过 etcdctl 设置键值
etcdctl put testkey "hello world"
通过 etcdctl 获取键值
etcdctl get testkey
通过 http 设置键值
curl -L http://localhost:2379/v3/kv/put \
-X POST -d '{"key": "name", "value": "YmFy"}'
通过 http 获取键值
curl -L http://localhost:2379/v3/kv/range \
-X POST -d '{"key": "name"}'