1、修改partitions(只能新增)shell
[root@hftest0001 kafka_2.11-0.8.2.2]# pwd /opt/kafka_2.11-0.8.2.2 [root@hftest0001 kafka_2.11-0.8.2.2]# ./bin/kafka-topics.sh --zookeeper ${ip}:${port} --replication-factor 2 --partitions 1 --topic topic_r2_p1 --create Created topic "topic_r2_p1". [root@hftest0001 kafka_2.11-0.8.2.2]# ./bin/kafka-topics.sh --zookeeper ${ip}:${port} --topic topic_r2_p1 --describe Topic:topic_r2_p1 PartitionCount:1 ReplicationFactor:2 Configs: Topic: topic_r2_p1 Partition: 0 Leader: 201 Replicas: 201,155 Isr: 201,155 [root@hftest0003 kafka_2.11-0.8.2.2]# ./bin/kafka-topics.sh --zookeeper ${ip}:${port} --alter --partitions 2 --topic topic_r2_p1 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! [root@hftest0003 kafka_2.11-0.8.2.2]# ./bin/kafka-topics.sh --zookeeper 10.224.246.201:2181,10.224.246.155:2181,10.224.246.154:2181 --describe topic_r2_p1 Topic:topic_r2_p1 PartitionCount:2 ReplicationFactor:2 Configs: Topic: topic_r2_p1 Partition: 0 Leader: 201 Replicas: 201,155 Isr: 201,155 Topic: topic_r2_p1 Partition: 1 Leader: 155 Replicas: 155,154 Isr: 155,154 [root@hftest0003 kafka_2.11-0.8.2.2]# ./bin/kafka-topics.sh --zookeeper 10.224.246.201:2181,10.224.246.155:2181,10.224.246.154:2181 --alter --partitions 1 --topic topic_r2_p1 WARNING: If partitions are increased for a topic that has a key, the partition logic or ordering of the messages will be affected Error while executing topic command The number of partitions for a topic can only be increased kafka.admin.AdminOperationException: The number of partitions for a topic can only be increased at kafka.admin.AdminUtils$.addPartitions(AdminUtils.scala:114) at kafka.admin.TopicCommand$$anonfun$alterTopic$1.apply(TopicCommand.scala:119) at kafka.admin.TopicCommand$$anonfun$alterTopic$1.apply(TopicCommand.scala:100) at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59) at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48) at kafka.admin.TopicCommand$.alterTopic(TopicCommand.scala:100) at kafka.admin.TopicCommand$.main(TopicCommand.scala:57) at kafka.admin.TopicCommand.main(TopicCommand.scala)
2、app