kafka关于修改副本数和分区的数的案例实战(也可用作leader节点均衡案例)
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
一.关于topic分区数的修改
1>.创建1分区1个的topic,名称为yinzhengjie-channel
[root@node101 ~]# kafka-topics.sh --zookeeper node102.yinzhengjie.org.cn:2181 --create --replication-factor 1 -partitions 1 --topic yinzhengjie-channel
Created topic"yinzhengjie-channel".
[root@node101~]#
2>.查看topic的信息
[root@node101 ~]# kafka-topics.sh --describe --zookeeper node102.yinzhengjie.org.cn:2181 --topic yinzhengjie-channel
Topic:yinzhengjie-channel PartitionCount:1 ReplicationFactor:1Configs:
Topic: yinzhengjie-channel Partition: 0 Leader: 103 Replicas: 103 Isr: 103 #可以很明显的看出kafka 的分区数和副本数都是1[root@node101~]#
3>.将之前创建的topic修改为3个分区
[root@node101 ~]# kafka-topics.sh --alter --zookeeper node102.yinzhengjie.org.cn:2181 --topic yinzhengjie-channel --partitions 3WARNING: If partitions are increasedfora topic that has a key, the partition logic or ordering of the messages will be affected
Adding partitions succeeded![root@node101~]#
4>.再次查看topic的分区数
[root@node101 ~]# kafka-topics.sh --describe --zookeeper node102.yinzhengjie.org.cn:2181 --topic yinzhengjie-channel
Topic:yin