Etcd数据同步

Etcd数据同步

1.获取需要同步的快照

etcdctl --endpoints $ENDPOINT snapshot save /path/filename.db
例: etcdctl --endpoints=10.1.1.1:2379 snapshot save /tmp/my.db

注:若是生成本地的快照,则不需要加endpoints项

2. 进入save路径,在你当前目录下生成.etcd资源

$ etcdctl snapshot restore snapshot.db \
  --name [filename] \
  --initial-cluster m1=http:/[host1]:2380,m2=http://[host2]:2380,m3=http://[host3]:2380 \
  --initial-cluster-token etcd-cluster-1 \
  --initial-advertise-peer-urls http://[host1]:2380
  
例:生成m1.etcd
etcdctl snapshot restore my.db \
  --name m1 \
  --initial-cluster m1=http://0.0.0.0:2380 \
  --initial-cluster-token tkn \
  --initial-advertise-peer-urls http://0.0.0.0:2380

3. 启动时换成新目录

#本地etcd启动
etcd \
  --name [fliename] \
  --listen-client-urls http://[host1]:2379 \
  --advertise-client-urls http://[host1]:2379 \
  --listen-peer-urls http://[host1]:2380 &
或
etcd --data-dir=/path/filename.etcd
例:
etcd --data-dir=/Users/bytedance/m1.etcd

#docker启动
docker run -d  -p 2379:2379   -p 2380:2380   --mount type=bind,source=/path/m1.etcd,destination=/etcd-data   --name etcd-gcr-v3.5.4   hub.byted.org/etcd-development/etcd:v3.5.4   /usr/local/bin/etcd   --name m1   --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

你可能感兴趣的:(go,etcd)