kafka如何修改topic的分区数

THEYUNG 发表于: 2020-12-21   最后更新时间: 2020-12-21 18:43:31   3,330 游览

通过命令修改后重启,分区数又变回1

kafka-topics.sh --zookeeper localhost:2181 --alter --topic topic --partitions 3
发表于 2020-12-21
添加评论

试试这个:

bin/kafka-topics.sh --bootstrap-server broker_host:port --alter --topic my_topic_name --partitions 40
THEYUNG -> 半兽人 3年前

报了这个错

Exception in thread "main" joptsimple.UnrecognizedOptionException: bootstrap-server is not a recognized option
    at joptsimple.OptionException.unrecognizedOption(OptionException.java:108)
    at joptsimple.OptionParser.handleLongOptionToken(OptionParser.java:510)
    at joptsimple.OptionParserState$2.handleArgument(OptionParserState.java:56)
    at joptsimple.OptionParser.parse(OptionParser.java:396)
    at kafka.admin.TopicCommand$TopicCommandOptions.(TopicCommand.scala:358)
    at kafka.admin.TopicCommand$.main(TopicCommand.scala:44)
    at kafka.admin.TopicCommand.main(TopicCommand.scala)
半兽人 -> THEYUNG 3年前

kafka什么版本

半兽人 -> THEYUNG 3年前

你的kafka版本<2.2,不识别bootstrap-server,正确方式和日志

bin/kafka-topics.sh --zookeeper localhost:2181 --alter --topic topic1 --partitions 3
WARNING: If partitions are increased for a topic that has a key, the partition logic or ordering of the messages will be affected
Adding partitions succeeded!

查看是否增加成功:

bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic topic1
THEYUNG -> 半兽人 3年前

那请问 单机kafka可以 设置多分区吗

半兽人 -> THEYUNG 3年前

可以多分区,不能多副本。

THEYUNG -> 半兽人 3年前

哦哦 多分区的话 在生产的时候 需要改什么吗 比如想要发送到多出来的分支里

半兽人 -> THEYUNG 3年前

默认会轮询发送到各个分区中。
ps:如果问题不同,新提个问题详细描述下吧(这个问题可以结贴了哦)。

THEYUNG -> 半兽人 3年前

好的 知道了 谢谢大佬

你的答案

查看kafka相关的其他问题或提一个您自己的问题