etcd集群部署
作者:互联网
一、创建数据存储目录
mkdir /apps/etcd/ -pv
二、创建配置文件目录
mkdir /etc/etcd/
三、编辑配置文件
配置文件中的
ETCD_INITIAL_CLUSTER
参数请按需修改
LOCAL_IP="$(ip addr show eth0|grep -Po '(?<=inet )[0-9.]+')"
cat > etcd.conf << EOF
# Member
ETCD_NAME=etcd-01 # 需要修改为各成员对应名称
ETCD_DATA_DIR="/apps/etcd/"
ETCD_LISTEN_CLIENT_URLS="http://${LOCAL_IP}:2379,http://127.0.0.1:2379"
ETCD_LISTEN_PEER_URLS="http://${LOCAL_IP}:2380"
# Cluster
ETCD_ADVERTISE_CLIENT_URLS="http://${LOCAL_IP}:2379"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://${LOCAL_IP}:2380"
ETCD_INITIAL_CLUSTER="etcd-02=http://172.20.1.27:2380,etcd-01=http://172.20.1.26:2380,etcd-03=http://172.20.1.28:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-1"
ETCD_INITIAL_CLUSTER_STATE="new"
EOF
四、编写Service文件
systemctl cat etcd
# /etc/systemd/system/etcd.service
[Unit]
Description=Etcd Server
After=network.target
After=network-online.target
Wants=network-online.target
[Service]
Type=notify
EnvironmentFile=/etc/etcd/etcd.conf
ExecStart=/usr/local/bin/etcd
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
五、启动服务
启动服务之前请先将所有节点都准备好
systemctl daemon-reload
systemctl start etcd
六、验证集群状态
1. 查看集群成员
etcdctl member list --write-out table
+------------------+---------+---------+-------------------------+-------------------------+------------+
| ID | STATUS | NAME | PEER ADDRS | CLIENT ADDRS | IS LEARNER |
+------------------+---------+---------+-------------------------+-------------------------+------------+
| 11582579cb716706 | started | etcd-02 | http://172.20.1.27:2380 | http://172.20.1.27:2379 | false |
| 3909c7e83049bd5d | started | etcd-01 | http://172.20.1.26:2380 | http://172.20.1.26:2379 | false |
| a10314259291b7b2 | started | etcd-03 | http://172.20.1.28:2380 | http://172.20.1.28:2379 | false |
+------------------+---------+---------+-------------------------+-------------------------+------------+
2. 查看成员健康状态
etcdctl --endpoints="http://172.20.1.26:2379,http://172.20.1.27:2379,http://172.20.1.28:2379" --write-out table endpoint health
+-------------------------+--------+-------------+-------+
| ENDPOINT | HEALTH | TOOK | ERROR |
+-------------------------+--------+-------------+-------+
| http://172.20.1.26:2379 | true | 6.12222ms | |
| http://172.20.1.28:2379 | true | 6.812195ms | |
| http://172.20.1.27:2379 | true | 12.847463ms | |
+-------------------------+--------+-------------+-------+
3. 查看成员状态
etcdctl --endpoints="http://172.20.1.26:2379,http://172.20.1.27:2379,http://172.20.1.28:2379" endpoint status --write-out table
+-------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
+-------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| http://172.20.1.26:2379 | 3909c7e83049bd5d | 3.5.3 | 20 kB | true | false | 2 | 12 | 12 | |
| http://172.20.1.27:2379 | 11582579cb716706 | 3.5.3 | 20 kB | false | false | 2 | 12 | 12 | |
| http://172.20.1.28:2379 | a10314259291b7b2 | 3.5.3 | 20 kB | false | false | 2 | 12 | 12 | |
+-------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
标签:http,部署,1.28,集群,2379,etcd,false,172.20 来源: https://www.cnblogs.com/liy36/p/16534745.html