前言
ETCD使用RAFT协议保证各个节点之间的状态一致。根据RAFT算法原理,节点数目越多,会降低集群的写性能。这是因为每一次写操作,需要集群中大多数节点将日志落盘成功后,Leader节点才能将修改内部状态机,并返回将结果返回给客户端。
也就是说在等同配置下,节点数越少,集群性能越好。显然,只部署1个节点是没什么意义的。通常,按照需求将集群节点部署为3,5,7,9个节点。
etcd有三种集群化启动的配置方案,分别为静态配置启动、etcd自身服务发现、通过DNS进行服务发现。
环境介绍
主机名 | IP | etcd版本 |
---|---|---|
node1 | 192.168.49.135 | 3.3.13 |
node2 | 192.168.49.136 | 3.3.13 |
node3 | 192.168.49.138 | 3.3.13 |
单节点安装
参考 https://www.cnblogs.com/mldblue/articles/10975280.html
配置
首先写配置文件(建议从网上下载example configure)
在集群机器执行如下命令
[root@node1 ~]# mkdir /etc/etcd/ [root@node1 ~]# vim /etc/etcd/etcd.conf [root@node1 ~]# mkdir /opt/etcd_data
node1 配置文件示例,node2、node3修改节点名称和集群内节点通信所用端口和客户端连接的端口。
name: 'node1' data-dir: "/opt/etcd_data" wal-dir: snapshot-count: 10000 heartbeat-interval: 100 election-timeout: 1000 quota-backend-bytes: 0 listen-peer-urls: http://192.168.49.135:2380 listen-client-urls: http://localhost:2379,http://192.168.49.135:2379 max-snapshots: 5 max-wals: 5 cors: initial-advertise-peer-urls: http://192.168.49.135:2380 advertise-client-urls: http://192.168.49.135:2379 discovery: discovery-fallback: 'proxy' discovery-proxy: discovery-srv: initial-cluster: "node1=http://192.168.49.135:2380,node2=http://192.168.49.136:2380,node3=http://192.168.49.138:2380" initial-cluster-token: 'etcd-cluster' initial-cluster-state: 'new' strict-reconfig-check: false enable-v2: true enable-pprof: true proxy: 'off' proxy-failure-wait: 5000 proxy-refresh-interval: 30000 proxy-dial-timeout: 1000 proxy-write-timeout: 5000 proxy-read-timeout: 0 client-transport-security: cert-file: key-file: client-cert-auth: false trusted-ca-file: auto-tls: false peer-transport-security: cert-file: key-file: client-cert-auth: false trusted-ca-file: auto-tls: false debug: false logger: zap log-outputs: [stderr] force-new-cluster: false auto-compaction-mode: periodic auto-compaction-retention: "1"
启动
启动
[root@node1 etcd-v3.3.13-linux-amd64]# etcd --config-file /etc/etcd/etcd.conf
测试
查看集群成员
[root@node2 ~]# etcdctl member list 8816eaa680e63c73: name=node3 peerURLs=http://192.168.49.138:2380 clientURLs=http://192.168.49.138:2379 isLeader=false a3d1fb0d28ed2953: name=node2 peerURLs=http://192.168.49.136:2380 clientURLs=http://192.168.49.136:2379 isLeader=false cf5538a4dab95927: name=node1 peerURLs=http://192.168.49.135:2380 clientURLs=http://192.168.49.135:2379 isLeader=true
参考
https://www.cnblogs.com/softidea/p/6517959.html
https://blog.csdn.net/bbwangj/article/details/82584988
https://blog.csdn.net/fnatic_/article/details/84307332