| 原始服务器名称 | 原始服务器ip | 节点 |
|---|---|---|
| centos7虚拟机1 | 192.168.136.27 | broker0 |
| centos7虚拟机2 | 192.168.136.28 | broker1 |
| centos7虚拟机3 | 192.168.136.29 | broker2 |
| centos7虚拟机4 | 192.168.136.30 | broker3 |
启动zookeeper集群
[root@localhost /]# cd /opt/module/zookeeper-3.5.7/bin/
[root@localhost bin]# pwd
/opt/module/zookeeper-3.5.7/bin
[root@localhost bin]# sh zkServer.sh start

启动kafka集群
[root@localhost bin]# cd /opt/module/kafka-3.0.0/
[root@localhost kafka-3.0.0]# pwd
/opt/module/kafka-3.0.0
[root@localhost kafka-3.0.0]# bin/kafka-server-start.sh -daemon config/server.properties
[root@localhost kafka-3.0.0]# jps

创建名称为twotopic的topic(主题)
bin/kafka-topics.sh --bootstrap-server 192.168.136.27:9092 --create --partitions 4 --replication-factor 1 --topic twotopic

查看分区副本存储情况,由下图可知:目前分布在broker0、broker1、broker2和broker3的4台服务器的某一个服务器上。
bin/kafka-topics.sh --bootstrap-server 192.168.136.27:9092 --describe --topic twotopic

创建副本存储计划(所有副本都指定存储在 broker0、broker1、broker2 和broker3中)。
vim increase-replication-factor.json
//增加以下内容
{
"version":1,
"partitions":[{"topic":"twotopic","partition":0,"replicas":[0,1,2,3]},
{"topic":"twotopic","partition":1,"replicas":[0,1,2,3]},
{"topic":"twotopic","partition":2,"replicas":[0,1,2,3]},
{"topic":"twotopic","partition":3,"replicas":[0,1,2,3]}]
}


执行副本存储计划。
bin/kafka-reassign-partitions.sh --bootstrap-server 192.168.136.27:9092 --reassignment-json-file increase-replication-factor.json --execute

验证副本存储计划。
bin/kafka-reassign-partitions.sh --bootstrap-server 192.168.136.27:9092 --reassignment-json-file increase-replication-factor.json --verify

查看分区副本存储情况。
由下图可知: 所有副本都指定存储在 broker0、broker1、broker2 和broker3中。
