增删改查
1- 创建topic, 制定分区数,副本数,和一些配置config
常用的,只制定 分区数和副本数 (我已经配置了kafka命令的环境变量)
sh kafka-topics.sh -zookeeper localhost:2181 --create --topic tp_test_01 --partitions 2 --replication-factor 2
可以加一些 config指定 配置项的值,例子是:指定每条消息的大小和消息快的大小
sh kafka-topics.sh -zookeeper localhost:2181 --create --topic tp_test_02 --partitions 2 --replication-factor 2 --config max.message.bytes=1048576 --config segment.bytes=1048576
2- 查, 可以查看全部可用的topic,也可以查看指定的topic信息
A- 列出所有可用的topic --list
sh kafka-topics.sh --zookeeper localhost:2181 --list
B- 查看某个 topic 的详细信息 --decribe --topic (若是没指定topic,则是列出所有topic的详细信息)
sh kafka-topics.sh --zookeeper localhost:2181 --describe --topic tp_test_02
C- 查看某个 topic的信息,只显示覆盖了默认值的配置项。 --topics-with-overrides --describe
比如tp_test_02,我们设置了 segment和message的大小
sh kafka-topics.sh --zookeeper localhost:2181 --describe --topic tp_test_02 --topics-with-overrides --describe
对比起来,不带--topics-with-overrides 的命令还有额外的信息。包括 分区所在机子,leader、和ISR的信息
3- 改动
A- 改动配置项的值, --alter --config xxx=xxxValue
更改segment的值为 104800
sh kafka-topics.sh --zookeeper localhost:2181 --alter --topic tp_test_02 --config segment.bytes=104800
B - 删除配置项的值 , --alter --delete-config configName
sh kafka-topics.sh --zookeeper localhost:2181 --alter --topic tp_test_02 --delete-config segment.bytes
C- 更改 分区数 --alter --partitions
讲分区从2 改成 3
sh kafka-topics.sh --zookeeper localhost:2181 --alter --topic tp_test_02 --partitions 3
4- 删除 (1.0以后的版本支持),前提是设置可删除配置项(delete.topic.enable)为true
删除 tp_test_02 , --delerte --topic
sh kafka-topics.sh --zookeeper localhost:2181 --delete --topic tp_test_02
检查是否删除成功,可以查看 kafka存放数据的目录 kafka-logs, zookeeper的元数据信息,topic的列表
A- kafka-logs检查
已经标识为delete,过段时间后会删除(可设置时间)
B- topic列表检查
已经没有显示 tp_test_02
sh kafka-topics.sh --zookeeper localhost:2181 --list
C- zookeeper元数据检查
进入 zkCli 客户端。查看topics,没有发现 tp_test_02