获取etcd镜像
docker pull etcd:v3.4.7
脚本
#!/bin/bash
mkdir /myetcd/data -p
docker run -d \
-p 32379:2379 \
-p 32380:2380 \
-v /myetcd/data:/etcd-data/member \
--name exam-etcd \
etcd:v3.4.7 \
/usr/local/bin/etcd \
--name s1 \
--data-dir /etcd-data \
--listen-client-urls http://0.0.0.0:2379 \
--advertise-client-urls http://0.0.0.0:2379 \
--listen-peer-urls http://0.0.0.0:2380 \
--initial-advertise-peer-urls http://0.0.0.0:2380 \
--initial-cluster s1=http://0.0.0.0:2380 \
--initial-cluster-token tkn \
--initial-cluster-state new \
--log-level info \
--logger zap \
--log-outputs stderr
测试写读操作
[root@VM_8_34_centos]# docker exec exam-etcd etcdctl --endpoints=http://127.0.0.1:2379 put foo bar
OK
[root@VM_8_34_centos]# docker exec exam-etcd etcdctl --endpoints=http://127.0.0.1:2379 get foo
foo
bar
远程测试
[root@build32-8 etcd-v3.4.9-linux-amd64]# ./etcdctl --endpoints=http://10.22.8.34:32379 get foo
foo
bar