Kafka 节点服役和退役
新节点服役
新加入的 Kafka 节点,要求对之前的主题进行负载均衡
先按照之前 Kafka 在 Windows 下集群搭建 的方式,创建了一个新的 broker,id=3
接着查询主题详情,从图中我们可以看到,之前创建的主题副本并没有出现在新的 broker 上,因此我们希望可以实现对特定主题的负载均衡
1、创建要均衡的主题
创建 balance.json
文件,内容如下
1 | { |
创建好以后放到了 %KAFKA_HOME%\bin\windows
目录下
2、生成负载均衡计划
在 %KAFKA_HOME%\bin\windows
目录下执行命令
1 | kafka-reassign-partitions.bat --bootstrap-server localhost:9092 --topics-to-move-json-file balance.json --broker-list "0,1,2,3" --generate |
上面的是当前的计划,下面的是生成的计划,如果符合要求的话,就可以直接拿来执行。
3、执行副本存储计划
将上面生成的 json 结果拷贝到新的文件:execute.json
,同样放到 %KAFKA_HOME%\bin\windows
目录下
生成的 json 结果即:Proposed partition reassignment configuration
1 | { |
执行命令
1 | kafka-reassign-partitions.bat --bootstrap-server localhost:9092 --reassignment-json-file execute.json --execute |
结果
4、验证副本存储计划
执行命令
1 | kafka-reassign-partitions.bat --bootstrap-server localhost:9092 --reassignment-json-file execute.json --verify |
同时通过查看主题详情加以验证
退役旧节点
与新节点服役的操作相同,首先创建需要均衡的主题,可以参考上面的文件
然后执行负载均衡计划,少了 broker3 这个节点
1 | kafka-reassign-partitions.bat --bootstrap-server localhost:9092 --topics-to-move-json-file balance.json --broker-list "0,1,2" --generate |
复制生成的计划,我是直接替代了原来的execute.json
文件,执行计划
1 | kafka-reassign-partitions.bat --bootstrap-server localhost:9092 --reassignment-json-file execute.json --execute |
验证计划
1 | kafka-reassign-partitions.bat --bootstrap-server localhost:9092 --reassignment-json-file execute.json --verify |
同时查看主题详情加以验证
1 | kafka-topics.bat --bootstrap-server localhost:9092 --describe --topic firstTest,secondTest |
最后在相应服务器上执行 Kafka 停止命令即可(这里用的 Windows 集群,就不演示了)
本文采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 ShiGuang
评论