1、创建主题
./bin/kafka-topics.sh --zookeeper localhost:2181 --create --topic zmtest --partitions 4 --replication-factor 2
2、查看主题分区情况
./bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic topic-create-same
3、指定分区副本创建主题命令
./bin/kafka-topics.sh --zookeeper localhost:2181 --create --topic topic-create-same --replica-assignment 2:0,0:1,1:2,2:1
4、config覆盖默认配置
./bin/kafka-topics.sh --zookeeper localhost:2181 --create --topic zmtest --partitions 4 --replication-factor 2 --config cleanup.policy=compact --config max.message.bytes=1000
5、创建主题时名称冲突–if-not-exists指令
./bin/kafka-topics.sh --zookeeper localhost:2181 --create --topic zmtest --partitions 4 --replication-factor 2 --if-not-exists
6、查看主题列表命令
./bin/kafka-topics.sh --zookeeper localhost:2181 -list
7、查看主题,无–topic显示所有主题
./bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topics-with-overrides
//列出覆盖配置的主题
./bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic zmtest --under-replicated-partitions
//找出失效副本分区
./bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic zmtest --unavailable-partitions
//找出没有leader副本的分区
8、修改主题信息
./bin/kafka-topics.sh --zookeeper localhost:2181 --alter --topic zmtest --partitions 1
//修改分区数量,只增不减
注:–if-exists参数如果存在时才执行命令;–delete-config xxxxxx//删除之前的覆盖属性
9、主题配置管理
//增加配置
./bin/kafka-configs.sh --zookeeper localhost:2181 --alter --entity-type topics --entity-name zmtest --add-config cleanup.policy=compact,max.message.bytes=1000
//查看配置,无–entity-name则查看所有的信息
./bin/kafka-configs.sh --zookeeper localhost:2181 --describe --entity-type topics --entity-name zmtest
//删除配置
./bin/kafka-configs.sh --zookeeper localhost:2181 --alter --entity-type topics --entity-name zmtest --delete-config cleanup.policy,max.message.bytes
10、删除主题
./bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic topic-delete
//主题不存在会忽略
./bin/kafka-topics.sh --zookeeper 10.1.26.25:2181 --delete --topic topic-delete --if-exists