因为在生产中直接拷贝DB比较方便且也比较符合生产中的实际情况,所以我用的是直接拷贝db数据的方式,所以恢复数据的时候加了参数 --skip-hash-check
恢复数据:
ETCDCTL_API=3 ./etcdctl snapshot restore ../db \
--name m1 \--initial-cluster m1=http://192.168.75.145:2380,m2=http://192.168.75.145:3380,m3=http://192.168.75.145:4380 \
--initial-cluster-token etcd-cluster-1 \
--initial-advertise-peer-urls http://192.168.75.145:2380 \
--skip-hash-check
ETCDCTL_API=3 ./etcdctl snapshot restore ../db \
--name m2 \
--initial-cluster m1=http://192.168.75.145:2380,m2=http://192.168.75.145:3380,m3=http://192.168.75.145:4380 \
--initial-cluster-token etcd-cluster-1 \
--initial-advertise-peer-urls http://192.168.75.145:3380 \
--skip-hash-check
ETCDCTL_API=3 ./etcdctl snapshot restore ../db \
--name m3 \
--initial-cluster m1=http://192.168.75.145:2380,m2=http://192.168.75.145:3380,m3=http://192.168.75.145:4380 \
--initial-cluster-token etcd-cluster-1 \
--initial-advertise-peer-urls http://192.168.75.145:4380 \
--skip-hash-check
创建集群:(绿色的是官网的做法,一直没成功,执行etcdctl命令总是出现Error: grpc: timed out when dialing。实在没把发,我用了写出全部参数的方法成功)
./etcd \
--name m1 \
--listen-client-urls http://192.168.75.145:2379 \
--advertise-client-urls http://192.168.75.145:2379 \
--listen-peer-urls http://192.168.75.145:2380
./etcd --name m1 --initial-advertise-peer-urls http://192.168.75.145:2380 \
--listen-peer-urls http://192.168.75.145:2380 \
--listen-client-urls http://192.168.75.145:2379,http://127.0.0.1:2379 \
--advertise-client-urls http://192.168.75.145:2379 \
--initial-cluster-token etcd-cluster-1 \
--initial-cluster m1=http://192.168.75.145:2380,m2=http://192.168.75.145:3380,m3=http://192.168.75.145:4380 \
--initial-cluster-state new
./etcd \
--name m2 \
--listen-client-urls http://192.168.75.145:3379 \
--advertise-client-urls http://192.168.75.145:3379 \
--listen-peer-urls http://192.168.75.145:3380
./etcd --name m2 --initial-advertise-peer-urls http://192.168.75.145:3380 \
--listen-peer-urls http://192.168.75.145:3380 \
--listen-client-urls http://192.168.75.145:3379,http://127.0.0.1:3379 \
--advertise-client-urls http://192.168.75.145:3379 \
--initial-cluster-token etcd-cluster-1 \
--initial-cluster m1=http://192.168.75.145:2380,m2=http://192.168.75.145:3380,m3=http://192.168.75.145:4380 \
--initial-cluster-state new
./etcd \
--name m3 \
--listen-client-urls http://192.168.75.145:4379 \
--advertise-client-urls http://192.168.75.145:4379 \
--listen-peer-urls http://192.168.75.145:4380
./etcd --name m3 --initial-advertise-peer-urls http://192.168.75.145:4380 \
--listen-peer-urls http://192.168.75.145:4380 \
--listen-client-urls http://192.168.75.145:4379,http://127.0.0.1:4379 \
--advertise-client-urls http://192.168.75.145:4379 \
--initial-cluster-token etcd-cluster-1 \
--initial-cluster m1=http://192.168.75.145:2380,m2=http://192.168.75.145:3380,m3=http://192.168.75.145:4380 \
--initial-cluster-state new