1. 程式人生 > 實用技巧 >多主機搭建etcd叢集

多主機搭建etcd叢集

下載https://github.com/etcd-io/etcd/releases/download/v3.4.10/etcd-v3.4.10-linux-amd64.tar.gz分別放到兩臺主機上,因為wget太慢了。

HOST1:101.200.243.176(公網)172.17.229.160(內網)
HOST2:110.43.50.186(公網)10.0.0.254(內網)

HOST1

[root@peiqi test]# tar xzvf etcd-v3.4.10-linux-amd64.tar.gz
[root@peiqi test]# mv etcd-v3.4.10-linux-amd64 etcd && cd etcd
[root@peiqi etcd]# .
/etcd --name docker01 --listen-peer-urls http://172.17.229.160:2380 --listen-client-urls http://172.17.229.160:2379,http://127.0.0.1:2379 --initial-advertise-peer-urls http://101.200.243.176:2380 --advertise-client-urls http://127.0.0.1:2379,http://101.200.243.176:2379 --initial-cluster docker01=http://101.200.243.176:2380,docker02=http://110.43.50.186
:2380 --initial-cluster-token etcd-cluster --initial-cluster-state new

HOST2

[root@qiaozhi test]# tar xzvf etcd-v3.4.10-linux-amd64.tar.gz
[root@qiaozhi test]# mv etcd-v3.4.10-linux-amd64 etcd && cd etcd
[root@qiaozhi etcd]# ./etcd --name docker02 --listen-peer-urls http://10.0.0.254:2380 --listen-client-urls 
http://10.0.0.254:2379,http://127.0.0.1:2379 --initial-advertise-peer-urls http://110.43.50.186:2380 --advertise-client-urls http://127.0.0.1:2379,http://110.43.50.186:2379 --initial-cluster docker01=http://101.200.243.176:2380,docker02=http://110.43.50.186:2380 --initial-cluster-token etcd-cluster --initial-cluster-state new

檢查cluster狀態

[root@peiqi etcd]# ./etcdctl member list
23311ae1cecb97ad, started, docker01, http://101.200.243.176:2380, http://101.200.243.176:2379,http://127.0.0.1:2379, false
d95dada82a934bb0, started, docker02, http://110.43.50.186:2380, http://110.43.50.186:2379,http://127.0.0.1:2379, false