首页 > 代码库 > etcd跨机房部署方案
etcd跨机房部署方案
使用ETCD做为元数据方便快捷,但是谈到跨机房灾备可能就迷糊了,我们在做节日灾备的时候同样遇到了问题, 通过查阅官方文档找到了解决方案,官方提供make-mirror方法,提供数据镜像服务
注意: make-mirror 的使用需要依赖于API版本3, 使用API2的无法通过该工具做数据同步
有关ETCD的编译安装这里就不在说明了, 不明白的可以参考官方说明:https://github.com/coreos/etcd
1. 启动集群1
#!/bin/bash nohup etcd --name infra1 --listen-client-urls http://127.0.0.1:2379 --advertise-client-urls http://127.0.0.1:2379 --listen-peer-urls http://127.0.0.1:12380 --initial-advertise-peer-urls http://127.0.0.1:12380 --initial-cluster-token etcd-cluster-1 --initial-cluster ‘infra1=http://127.0.0.1:12380,infra2=http://127.0.0.1:22380,infra3=http://127.0.0.1:32380‘ --initial-cluster-state new --enable-pprof & nohup etcd --name infra2 --listen-client-urls http://127.0.0.1:22379 --advertise-client-urls http://127.0.0.1:22379 --listen-peer-urls http://127.0.0.1:22380 --initial-advertise-peer-urls http://127.0.0.1:22380 --initial-cluster-token etcd-cluster-1 --initial-cluster ‘infra1=http://127.0.0.1:12380,infra2=http://127.0.0.1:22380,infra3=http://127.0.0.1:32380‘ --initial-cluster-state new --enable-pprof & nohup etcd --name infra3 --listen-client-urls http://127.0.0.1:32379 --advertise-client-urls http://127.0.0.1:32379 --listen-peer-urls http://127.0.0.1:32380 --initial-advertise-peer-urls http://127.0.0.1:32380 --initial-cluster-token etcd-cluster-1 --initial-cluster ‘infra1=http://127.0.0.1:12380,infra2=http://127.0.0.1:22380,infra3=http://127.0.0.1:32380‘ --initial-cluster-state new --enable-pprof &
通过命令向集群1中写入数据
export ETCDCTL_API=3 etcdctl put t1 v1 --endpoints=127.0.0.1:2379,127.0.0.1:22379,127.0.0.1:32379 etcdctl put t2 v2 --endpoints=127.0.0.1:2379,127.0.0.1:22379,127.0.0.1:32379 etcdctl put t3 v3 --endpoints=127.0.0.1:2379,127.0.0.1:22379,127.0.0.1:32379 etcdctl put t4 v4 --endpoints=127.0.0.1:2379,127.0.0.1:22379,127.0.0.1:32379
2. 启动集群2
#!/bin/bash nohup etcd --name infra4 --listen-client-urls http://127.0.0.1:12479 --advertise-client-urls http://127.0.0.1:12479 --listen-peer-urls http://127.0.0.1:12480 --initial-advertise-peer-urls http://127.0.0.1:12480 --initial-cluster-token etcd-cluster-2 --initial-cluster ‘infra4=http://127.0.0.1:12480,infra5=http://127.0.0.1:22480,infra6=http://127.0.0.1:32480‘ --initial-cluster-state new --enable-pprof & nohup etcd --name infra5 --listen-client-urls http://127.0.0.1:22479 --advertise-client-urls http://127.0.0.1:22479 --listen-peer-urls http://127.0.0.1:22480 --initial-advertise-peer-urls http://127.0.0.1:22480 --initial-cluster-token etcd-cluster-2 --initial-cluster ‘infra4=http://127.0.0.1:12480,infra5=http://127.0.0.1:22480,infra6=http://127.0.0.1:32480‘ --initial-cluster-state new --enable-pprof & nohup etcd --name infra6 --listen-client-urls http://127.0.0.1:32479 --advertise-client-urls http://127.0.0.1:32479 --listen-peer-urls http://127.0.0.1:32480 --initial-advertise-peer-urls http://127.0.0.1:32480 --initial-cluster-token etcd-cluster-2 --initial-cluster ‘infra4=http://127.0.0.1:12480,infra5=http://127.0.0.1:22480,infra6=http://127.0.0.1:32480‘ --initial-cluster-state new --enable-pprof &
3. 使用 make-mirror同步数据
#export ETCDCTL_API=3;
#etcdctl make-mirror --no-dest-prefix=true 127.0.0.1:12479 --endpoints=127.0.0.1:2379,127.0.0.1:22379,127.0.0.1:32379 --insecure-skip-tls-verify=true
4. 查看集群2的数据
export ETCDCTL_API=3;etcdctl get t1 t99 --endpoints=127.0.0.1:12479,127.0.0.1:22479,127.0.0.1:32479
通过以上命令发现集群1和集群2的数据已经完全同步了, etcdctl make-mirror 代码里面数据同步打印的周期是30s一次, 可以通过日志查看已经同步数据的数量。
etcd跨机房部署方案
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。