一、环境准备
节点 | IP |
---|---|
node1 | 10.1.43.1 |
node2 | 10.1.43.2 |
node3 | 10.1.43.3 |
所需安装包:etcd-v3.4.15-linux-amd64.tar.gz
二、部署步骤
1、下载安装包
etcd-v3.4.15-linux-amd64.tar.gz
2、解压
# tar -zxvf etcd-v3.4.15-linux-amd64.tar.gz
# cp -r etcd-v3.4.15-linux-amd64 /data/etcd
3、三个节点创建目录
# mkdir -p /data/etcd/node1(按节点更改)
# mkdir -p /data/etcddata/
4、在每个节点上创建etcd的systemd unit文件/usr/lib/systemd/system/etcd.service
# vim /usr/lib/systemd/system/etcd.service #如果没有system目录则新创建一个
[Unit]
Description=etcd server
After=network.target
After=network-online.target
Wants=network-online.target
[Service]
Type=notify
WorkingDirectory=/data/etcddata/
EnvironmentFile=-/data/etcd/nodefile.yml
ExecStart=/data/etcd/etcd --config-file=/data/etcd/nodefile.yml
Restart=on-failure
RestartSec=5
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
4、编写nodefile.yml(按节点更改)
name: node1
data-dir: /data/etcd/node1
listen-client-urls: 'http://192.168.120.100:12379'
advertise-client-urls: 'http://192.168.120.100:12379'
listen-peer-urls: 'http://192.168.120.100:12380'
initial-advertise-peer-urls: 'http://192.168.120.100:12380'
initial-cluster: node1=http://192.168.120.100:12380,node2=http://192.168.120.101:12380,node3=http://192.168.120.102:12380
initial-cluster-token: etcd-cluster-1
initial-cluster-state: new
5、开启etcd服务
# systemctl daemon-reload && systemctl enable etcd && systemctl start etcd
6、检查集群情况
# etcdctl --endpoints='10.1.43.1:12379,10.1.43.2:12379,10.1.43.3:12379' endpoint health
10.1.43.2:12379 is healthy: successfully committed proposal: took = 2.645184ms
10.1.43.1:12379 is healthy: successfully committed proposal: took = 1.897015ms
10.1.43.3:12379 is healthy: successfully committed proposal: took = 1.869879ms
# etcdctl --endpoints='10.1.43.1:12379,10.1.43.2:12379,10.1.43.3:12379' -w table endpoint status
+-----------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
+-----------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| 10.1.43.1:12379 | 23b295581f086091 | 3.4.15 | 192 kB | true | false | 2 | 785 | 785 | |
| 10.1.43.2:12379 | 72aef3b68b361b6c | 3.4.15 | 192 kB | false | false | 2 | 785 | 785 | |
| 10.1.43.3:12379 | 6781172eef7f4de0 | 3.4.15 | 205 kB | false | false | 2 | 785 | 785 | |
+-----------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
1个leader正常