ETCD集群部署

下载

https://github.com/etcd-io/etcd/releases

选取适合自己的版本,这里我选择的是 etcd-v3.3.18-linux-amd64.tar.gz

安装

tar -zxvf  etcd-v3.3.18-linux-amd64.tar.gz -C /opt/
mv /opt/etcd-v3.3.18-linux-amd64 /opt/etcd-v3.3.18

节点配置文件

文件位置 /etc/etcd/conf.yml

节点一

name: etcd-1
data-dir: /opt/etcd-v3.3.18/data
listen-client-urls: http://10.0.0.12:2379,http://127.0.0.1:2379
advertise-client-urls: http://10.0.0.12:2379,http://127.0.0.1:2379
listen-peer-urls: http://10.0.0.12:2380
initial-advertise-peer-urls: http://10.0.0.12:2380
initial-cluster: etcd-1=http://10.0.0.12:2380,etcd-2=http://10.0.0.4:2380,etcd-3=http://10.0.0.2:2380
initial-cluster-token: etcd-cluster-token
initial-cluster-state: new

节点二

name: etcd-2
data-dir: /opt/etcd-v3.3.18/data
listen-client-urls: http://10.0.0.4:2379,http://127.0.0.1:2379
advertise-client-urls: http://10.0.0.4:2379,http://127.0.0.1:2379
listen-peer-urls: http://10.0.0.4:2380
initial-advertise-peer-urls: http://10.0.0.4:2380
initial-cluster: etcd-1=http://10.0.0.12:2380,etcd-2=http://10.0.0.4:2380,etcd-3=http://10.0.0.2:2380
initial-cluster-token: etcd-cluster-token
initial-cluster-state: new

节点三

name: etcd-1
data-dir: /opt/etcd-v3.3.18/data
listen-client-urls: http://10.0.0.2:2379,http://127.0.0.1:2379
advertise-client-urls: http://10.0.0.2:2379,http://127.0.0.1:2379
listen-peer-urls: http://10.0.0.2:2380
initial-advertise-peer-urls: http://10.0.0.2:2380
initial-cluster: etcd-1=http://10.0.0.12:2380,etcd-2=http://10.0.0.4:2380,etcd-3=http://10.0.0.2:2380
initial-cluster-token: etcd-cluster-token
initial-cluster-state: new

启动

cd  /opt/etcd-v3.3.18
./etcdctl version
./etcd --config-file=/etc/etcd/conf.yml

检查

./etcdctl member list
2b5fecead9954d75, started, etcd-2, http://10.0.0.4:2380, http://10.0.0.4:2379,http://127.0.0.1:2379
7c872d2ed797f77b, started, etcd-3, http://10.0.0.2:2380, http://10.0.0.2:2379,http://127.0.0.1:2379
f082a4d4e902ff0a, started, etcd-1, http://10.0.0.12:2380, http://10.0.0.12:2379,http://127.0.0.1:2379

不知道是不是最新版本的问题./etcdctl cluster-health 不支持了,仔细看了下help,使用了另一个指令

./etcdctl endpoint health --cluster
http://127.0.0.1:2379 is healthy: successfully committed proposal: took = 3.390671ms
http://10.0.0.4:2379 is healthy: successfully committed proposal: took = 3.367381ms
http://127.0.0.1:2379 is healthy: successfully committed proposal: took = 3.298052ms
http://10.0.0.2:2379 is healthy: successfully committed proposal: took = 1.776691ms
http://127.0.0.1:2379 is healthy: successfully committed proposal: took = 1.447691ms
http://10.0.0.12:2379 is healthy: successfully committed proposal: took = 4.985519ms

测试使用

./etcdctl put /message Hello-World
OK

另一个节点读取
./etcdctl get /message
/message
Hello-World

一切正常

本人使用etcd主要是为了实现服务发现和服务注册。

搭建感悟,和zookeeper相比,配置部署相比较也不算太复杂。看到别人说的特点

  • 1.简单。使用Go语言编写部署简单;使用HTTP作为接口使用简单;使用Raft算法保证强一致性让用户易于理解。
  • 2.数据持久化。etcd默认数据一更新就进行持久化。
  • 3.安全。etcd支持SSL客户端安全认证。

实际使用根据自己业务来考虑,目前我只是想实现服务发现和注册,方便grpc的管理和调度,感觉etcd应该绰绰有余,如果有更复杂的业务需求可能需要更加深入了解etcd的特性。

你可能感兴趣的:(ETCD集群部署)