安装Etcd集群
docker pull quay.io/coreos/etcd:v3.3.1
docker run -d --name etcd1 quay.io/coreos/etcd:v3.3.1 etcd -name etcd1 -advertise-client-urls http://172.17.0.2:2379 -initial-advertise-peer-urls http://172.17.0.2:2380 -listen-client-urls http://0.0.0.0:2379 -listen-peer-urls http://0.0.0.0:2380 -initial-cluster-token etcd-cluster -initial-cluster "etcd1=http://172.17.0.2:2380,etcd2=http://172.17.0.3:2380,etcd3=http://172.17.0.4:2380" -initial-cluster-state new
docker run -d --name etcd2 quay.io/coreos/etcd:v3.3.1 etcd -name etcd2 -advertise-client-urls http://172.17.0.3:2379 -initial-advertise-peer-urls http://172.17.0.3:2380 -listen-client-urls http://0.0.0.0:2379 -listen-peer-urls http://0.0.0.0:2380 -initial-cluster-token etcd-cluster -initial-cluster "etcd1=http://172.17.0.2:2380,etcd2=http://172.17.0.3:2380,etcd3=http://172.17.0.4:2380" -initial-cluster-state new
docker run -d --name etcd3 quay.io/coreos/etcd:v3.3.1 etcd -name etcd3 -advertise-client-urls http://172.17.0.4:2379 -initial-advertise-peer-urls http://172.17.0.4:2380 -listen-client-urls http://0.0.0.0:2379 -listen-peer-urls http://0.0.0.0:2380 -initial-cluster-token etcd-cluster -initial-cluster "etcd1=http://172.17.0.2:2380,etcd2=http://172.17.0.3:2380,etcd3=http://172.17.0.4:2380" -initial-cluster-state new
Etcd集群备份快照
快照中包含了集群id和成员id。
docker exec -it etcd1 sh
export ETCDCTL_API=3
etcdctl --endpoints 127.0.0.1:2379 snapshot save snapshot.db
Etcd集群快照恢复
docker stop etcd1;docker rm etcd1
docker stop etcd2;docker rm etcd2
docker stop etcd3;docker rm etcd3
docker run -d --name etcd1 quay.io/coreos/etcd:v3.3.1 sleep 10000
docker run -d --name etcd2 quay.io/coreos/etcd:v3.3.1 sleep 10000
docker run -d --name etcd3 quay.io/coreos/etcd:v3.3.1 sleep 10000
docker cp snapshot.db etcd1:/
docker cp snapshot.db etcd2:/
docker cp snapshot.db etcd3:/
docker exec -it etcd1 sh
export ETCDCTL_API=3
etcdctl snapshot restore snapshot.db --name etcd1 --initial-cluster "etcd1=http://172.17.0.2:2380,etcd2=http://172.17.0.3:2380,etcd3=http://172.17.0.4:2380" --initial-cluster-token etcd-cluster --initial-advertise-peer-urls http://172.17.0.2:2380
docker exec -it etcd2 sh
export ETCDCTL_API=3
etcdctl snapshot restore snapshot.db --name etcd2 --initial-cluster "etcd1=http://172.17.0.2:2380,etcd2=http://172.17.0.3:2380,etcd3=http://172.17.0.4:2380" --initial-cluster-token etcd-cluster --initial-advertise-peer-urls http://172.17.0.3:2380
docker exec -it etcd3 sh
export ETCDCTL_API=3
etcdctl snapshot restore snapshot.db --name etcd3 --initial-cluster "etcd1=http://172.17.0.2:2380,etcd2=http://172.17.0.3:2380,etcd3=http://172.17.0.4:2380" --initial-cluster-token etcd-cluster --initial-advertise-peer-urls http://172.17.0.4:2380
docker exec -it etcd1 sh
etcd --name etcd1 --listen-client-urls http://172.17.0.2:2379 --advertise-client-urls http://172.17.0.2:2379 --listen-peer-urls http://172.17.0.2:2380 &
docker exec -it etcd2 sh
etcd --name etcd2 --listen-client-urls http://172.17.0.3:2379 --advertise-client-urls http://172.17.0.3:2379 --listen-peer-urls http://172.17.0.3:2380 &
docker exec -it etcd3 sh
etcd --name etcd3 --listen-client-urls http://172.17.0.4:2379 --advertise-client-urls http://172.17.0.4:2379 --listen-peer-urls http://172.17.0.4:2380 &
docker exec -it etcd1 sh
export ETCDCTL_API=3
etcdctl --endpoints http://172.17.0.2:2379,http://172.17.0.3:2379,http://172.17.0.4:2379 endpoint health
etcdctl --endpoints http://172.17.0.2:2379,http://172.17.0.3:2379,http://172.17.0.4:2379 endpoint status -w table
标签:urls,http,Etcd,--,备份,2380,集群,172.17,docker
From: https://www.cnblogs.com/WJQ2017/p/18401967