etcdV3集群扩容

一、需求

将目前已有的三节点etcd集群扩容到五节点
注:版本为V3.5

二、详细步骤

1、目前已有的集群信息

目前已有的三节点etcd配置(supervisord托管)

test-etcd-001 客户端端口:2371 集群端口:2381

test-etcd-002 客户端端口:2372 集群端口:2382

test-etcd-003 客户端端口:2373 集群端口:2383

etcd001节点配置如下:

[program:etcd01]
directory=/opt/etcd/etcd-data01
command=/usr/local/bin/etcd
  -name test-etcd-001
  --data-dir /opt/etcd/etcd-data01
  -initial-advertise-peer-urls http://10.140.0.23:2381
  -listen-peer-urls http://10.140.0.23:2381
  -listen-client-urls http://10.140.0.23:2371,http://127.0.0.1:2371
  -advertise-client-urls http://10.140.0.23:2371
  -initial-cluster-token etcd-test
  -initial-cluster test-etcd-001=http://10.140.0.23:2381,test-etcd-002=http://10.140.0.23:2382,test-etcd-003=http://10.140.0.23:2383
  -initial-cluster-state new
  --auto-compaction-retention=2
  --quota-backend-bytes=4294967296
  --logger zap
  --log-outputs  stderr
autorestart=true
stdout_logfile=/opt/supervisor/log/etcd01.log
user=root
redirect_stderr=true

etcd002节点点配置如下:

[program:etcd02]
directory=/opt/etcd/etcd-data02
command=/usr/local/bin/etcd
  -name test-etcd-002
  --data-dir /opt/etcd/etcd-data02
  -initial-advertise-peer-urls http://10.140.0.23:2382
  -listen-peer-urls http://10.140.0.23:2382
  -listen-client-urls http://10.140.0.23:2372,http://127.0.0.1:2372
  -advertise-client-urls http://10.140.0.23:2372
  -initial-cluster-token etcd-test
  -initial-cluster test-etcd-001=http://10.140.0.23:2381,test-etcd-002=http://10.140.0.23:2382,test-etcd-003=http://10.140.0.23:2383
  -initial-cluster-state new
  --auto-compaction-retention=2
  --quota-backend-bytes=4294967296
  --logger zap
  --log-outputs  stderr
autorestart=true
stdout_logfile=/opt/supervisor/log/etcd02.log
user=root
redirect_stderr=true

etcd003节点点配置如下:

[program:etcd03]
directory=/opt/etcd/etcd-data03
command=/usr/local/bin/etcd
  -name test-etcd-003
  --data-dir /opt/etcd/etcd-data03
  -initial-advertise-peer-urls http://10.140.0.23:2383
  -listen-peer-urls http://10.140.0.23:2383
  -listen-client-urls http://10.140.0.23:2373,http://127.0.0.1:2373
  -advertise-client-urls http://10.140.0.23:2373
  -initial-cluster-token etcd-test
  -initial-cluster test-etcd-001=http://10.140.0.23:2381,test-etcd-002=http://10.140.0.23:2382,test-etcd-003=http://10.140.0.23:2383
  -initial-cluster-state new
  --auto-compaction-retention=2
  --quota-backend-bytes=4294967296
  --logger zap
  --log-outputs  stderr
autorestart=true
stdout_logfile=/opt/supervisor/log/etcd03.log
user=root
redirect_stderr=true

查看集群状态和成员

#查看集群成员列表
[root@tw-61-instance-149 conf.d]# etcdctl --endpoints=http://10.140.0.23:2381 member list
76d35032baa0cea1, started, test-etcd-002, http://10.140.0.23:2382, http://10.140.0.23:2372, false
da58cce32d8d50aa, started, test-etcd-003, http://10.140.0.23:2383, http://10.140.0.23:2373, false
dc59600a0d8a88e3, started, test-etcd-001, http://10.140.0.23:2381, http://10.140.0.23:2371, false
#查看集群的状态
[root@tw-61-instance-149 conf.d]# etcdctl --endpoints=http://10.140.0.23:2383,http://10.140.0.23:2382,http://10.140.0.23:2381 endpoint status -w table
+-------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
|        ENDPOINT         |        ID        | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
+-------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| http://10.140.0.23:2383 | da58cce32d8d50aa |   3.5.0 |  1.4 MB |     false |      false |         3 |      19612 |              19612 |        |
| http://10.140.0.23:2382 | 76d35032baa0cea1 |   3.5.0 |  1.4 MB |      true |      false |         3 |      19612 |              19612 |        |
| http://10.140.0.23:2381 | dc59600a0d8a88e3 |   3.5.0 |  1.4 MB |     false |      false |         3 |      19612 |              19612 |        |
+-------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+

通过脚本往etcd写入数据,方便后续进行检查

[root@tw-61-instance-149 conf.d]# cat /tmp/test.sh 
for ((i=1; i<=50000; i++))
do
    etcdctl --endpoints=http://127.0.0.1:2372 put $i hhhhhsdsdsds
done

2、加入新节点etcd004

需要逐个节点进行添加

先将节点加入到集群中

[root@tw-61-instance-149 conf.d]# etcdctl --endpoints=http://10.140.0.23:2371,http://10.140.0.23:2372,http://10.140.0.23:2373 member add test-etcd-004 --peer-urls=http://10.140.0.23:2384

Member 94ec697883c8588b added to cluster ef04ddcca5995ad7

ETCD_NAME="test-etcd-004"
ETCD_INITIAL_CLUSTER="test-etcd-002=http://10.140.0.23:2382,test-etcd-004=http://10.140.0.23:2384,test-etcd-003=http://10.140.0.23:2383,test-etcd-001=http://10.140.0.23:2381"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://10.140.0.23:2384"
ETCD_INITIAL_CLUSTER_STATE="existing"

查看集群成员信息,会发现节点etcd004没有启动

 [root@tw-61-instance-149 conf.d]# etcdctl --endpoints=http://10.140.0.23:2381 member list
 
76d35032baa0cea1, started, test-etcd-002, http://10.140.0.23:2382, http://10.140.0.23:2372, false
94ec697883c8588b, unstarted, , http://10.140.0.23:2384, , false
da58cce32d8d50aa, started, test-etcd-003, http://10.140.0.23:2383, http://10.140.0.23:2373, false
dc59600a0d8a88e3, started, test-etcd-001, http://10.140.0.23:2381, http://10.140.0.23:2371, false

通过supervisor启动etcd004节点,supervisor配置文件如下:

需要注意的是。使用标志启动新成员--initial-cluster-state existing

[program:etcd04]
directory=/opt/etcd/etcd-data04
command=/usr/local/bin/etcd
  -name test-etcd-004
  --data-dir /opt/etcd/etcd-data04
  -initial-advertise-peer-urls http://10.140.0.23:2384
  -listen-peer-urls http://10.140.0.23:2384
  -listen-client-urls http://10.140.0.23:2374,http://127.0.0.1:2374
  -advertise-client-urls http://10.140.0.23:2374
  -initial-cluster-token etcd-test
  -initial-cluster test-etcd-001=http://10.140.0.23:2381,test-etcd-002=http://10.140.0.23:2382,test-etcd-003=http://10.140.0.23:2383,test-etcd-004=http://10.140.0.23:2384
  -initial-cluster-state existing
  --auto-compaction-retention=2
  --quota-backend-bytes=4294967296
  --logger zap
  --log-outputs  stderr
autorestart=true
stdout_logfile=/opt/supervisor/log/etcd04.log
user=root
redirect_stderr=true

继续查看集群信息等元数据,核对新成员的key的数量和数据目录大小

[root@tw-61-instance-149 conf.d]# etcdctl --endpoints=http://10.140.0.23:2381 member list
76d35032baa0cea1, started, test-etcd-002, http://10.140.0.23:2382, http://10.140.0.23:2372, false
94ec697883c8588b, started, test-etcd-004, http://10.140.0.23:2384, http://10.140.0.23:2374, false
da58cce32d8d50aa, started, test-etcd-003, http://10.140.0.23:2383, http://10.140.0.23:2373, false
dc59600a0d8a88e3, started, test-etcd-001, http://10.140.0.23:2381, http://10.140.0.23:2371, false

[jms_ops_all@tw-61-instance-149 ~]# du -sh /opt/etcd/etcd-data04/
126M    /opt/etcd/etcd-data04/

3、加入新节点etcd005

将etcd005也加入到新集群中

[root@tw-61-instance-149 conf.d]# etcdctl --endpoints=http://10.140.0.23:2371,http://10.140.0.23:2372,http://10.140.0.23:2373 member add test-etcd-005 --peer-urls=http://10.140.0.23:2385

Member 6f59aefe31880220 added to cluster ef04ddcca5995ad7

ETCD_NAME="test-etcd-005"
ETCD_INITIAL_CLUSTER="test-etcd-005=http://10.140.0.23:2385,test-etcd-002=http://10.140.0.23:2382,test-etcd-004=http://10.140.0.23:2384,test-etcd-003=http://10.140.0.23:2383,test-etcd-001=http://10.140.0.23:2381"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://10.140.0.23:2385"
ETCD_INITIAL_CLUSTER_STATE="existing"

通过supervisor启动etcd005节点,supervisor配置文件如下:

需要注意的是。使用标志启动新成员--initial-cluster-state existing

[program:etcd05]
directory=/opt/etcd/etcd-data05
command=/usr/local/bin/etcd
  -name test-etcd-005
  --data-dir /opt/etcd/etcd-data05
  -initial-advertise-peer-urls http://10.140.0.23:2385
  -listen-peer-urls http://10.140.0.23:2385
  -listen-client-urls http://10.140.0.23:2375,http://127.0.0.1:2375
  -advertise-client-urls http://10.140.0.23:2375
  -initial-cluster-token etcd-test
  -initial-cluster test-etcd-001=http://10.140.0.23:2381,test-etcd-002=http://10.140.0.23:2382,test-etcd-003=http://10.140.0.23:2383,test-etcd-004=http://10.140.0.23:2384,test-etcd-005=http://10.140.0.23:2385
  -initial-cluster-state existing
  --auto-compaction-retention=2
  --quota-backend-bytes=4294967296
  --logger zap
  --log-outputs  stderr

继续查看集群信息等元数据,核对新成员的key的数量和数据目录大小

[root@tw-61-instance-149 conf.d]# etcdctl --endpoints=http://10.140.0.23:2381 member list
6f59aefe31880220, started, test-etcd-005, http://10.140.0.23:2385, http://10.140.0.23:2375, false
76d35032baa0cea1, started, test-etcd-002, http://10.140.0.23:2382, http://10.140.0.23:2372, false
94ec697883c8588b, started, test-etcd-004, http://10.140.0.23:2384, http://10.140.0.23:2374, false
da58cce32d8d50aa, started, test-etcd-003, http://10.140.0.23:2383, http://10.140.0.23:2373, false
dc59600a0d8a88e3, started, test-etcd-001, http://10.140.0.23:2381, http://10.140.0.23:2371, false

[jms_ops_all@tw-61-instance-149 ~]# du -sh /opt/etcd/etcd-data05/
125M    /opt/etcd/etcd-data05/

4、将所有的节点停止修改配置文件后重新启动

需要将-initial-cluster选项都修改成包含所有的节点

[program:etcd01]
directory=/opt/etcd/etcd-data01
command=/usr/local/bin/etcd
  -name test-etcd-001
  --data-dir /opt/etcd/etcd-data01
  -initial-advertise-peer-urls http://10.140.0.23:2381
  -listen-peer-urls http://10.140.0.23:2381
  -listen-client-urls http://10.140.0.23:2371,http://127.0.0.1:2371
  -advertise-client-urls http://10.140.0.23:2371
  -initial-cluster-token etcd-test
  -initial-cluster test-etcd-001=http://10.140.0.23:2381,test-etcd-002=http://10.140.0.23:2382,test-etcd-003=http://10.140.0.23:2383,test-etcd-004=http://10.140.0.23:2384,test-etcd-005=http://10.140.0.23:2385
  -initial-cluster-state new
  --auto-compaction-retention=2
  --quota-backend-bytes=4294967296
  --logger zap
  --log-outputs  stderr
autorestart=true
stdout_logfile=/opt/supervisor/log/etcd01.log
user=root
redirect_stderr=true

检查集群状态

[root@tw-61-instance-149 conf.d]# etcdctl --endpoints=http://10.140.0.23:2381 member list
6f59aefe31880220, started, test-etcd-005, http://10.140.0.23:2385, http://10.140.0.23:2375, false
76d35032baa0cea1, started, test-etcd-002, http://10.140.0.23:2382, http://10.140.0.23:2372, false
94ec697883c8588b, started, test-etcd-004, http://10.140.0.23:2384, http://10.140.0.23:2374, false
da58cce32d8d50aa, started, test-etcd-003, http://10.140.0.23:2383, http://10.140.0.23:2373, false
dc59600a0d8a88e3, started, test-etcd-001, http://10.140.0.23:2381, http://10.140.0.23:2371, false


[root@tw-61-instance-149 conf.d]# etcdctl --endpoints=http://10.140.0.23:2383,http://10.140.0.23:2382,http://10.140.0.23:2381,http://10.140.0.23:2384,http://10.140.0.23:2385 endpoint status -w table
+-------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
|        ENDPOINT         |        ID        | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
+-------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| http://10.140.0.23:2383 | da58cce32d8d50aa |   3.5.0 |  1.4 MB |     false |      false |         3 |      19612 |              19612 |        |
| http://10.140.0.23:2382 | 76d35032baa0cea1 |   3.5.0 |  1.4 MB |      true |      false |         3 |      19612 |              19612 |        |
| http://10.140.0.23:2381 | dc59600a0d8a88e3 |   3.5.0 |  1.4 MB |     false |      false |         3 |      19612 |              19612 |        |
| http://10.140.0.23:2384 | 94ec697883c8588b |   3.5.0 |  1.4 MB |     false |      false |         3 |      19612 |              19612 |        |
| http://10.140.0.23:2385 | 6f59aefe31880220 |   3.5.0 |  1.4 MB |     false |      false |         3 |      19612 |              19612 |        |
+-------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+

注:官方建议,etcd集群的节点数不应该超过7个

  • 11
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值