[Kafka] - Kafka基本操作命令

网友投稿 241 2022-11-16

[Kafka] - Kafka基本操作命令

Kafka支持的基本命令位于${KAFKA_HOME}/bin文件夹中,主要是kafka-topics.sh命令;

-1. 查看帮助信息

bin/kafka-topics.sh --help

-2. 创建Topic

bin/kafka-topics.sh --create --topic test0 --zookeeper 192.168.187.146:2181 --config max.message.bytes=12800000 --config flush.messages=1 --partitions 5 --replication-factor 1

--create: 指定创建topic动作

--topic:指定新建topic的名称

--zookeeper: 指定kafka连接zk的连接url,该值和server.properties文件中的配置项{zookeeper.connect}一样

--config:指定当前topic上有效的参数值,参数列表参考文档为: ​​Topic-level configuration​​

--partitions:指定当前创建的kafka分区数量,默认为1个

--replication-factor:指定每个分区的复制因子个数,默认1个

-3. 查看当前Kafka集群中Topic的情况

bin/kafka-topics.sh --list --zookeeper 192.168.187.146:2181

-4. 查看对应topic的描述信息

bin/kafka-topics.sh --describe --zookeeper 192.168.187.146:2181  --topic test0

--describe: 指定是展示详细信息命令

--zookeeper: 指定kafka连接zk的连接url,该值和server.properties文件中的配置项{zookeeper.connect}一样

--topic:指定需要展示数据的topic名称

-5. Topic信息修改

bin/kafka-topics.sh --zookeeper 192.168.187.146:2181 --alter --topic test0 --config max.message.bytes=128000bin/kafka-topics.sh --zookeeper 192.168.187.146:2181 --alter --topic test0 --delete-config max.message.bytesbin/kafka-topics.sh --zookeeper 192.168.187.146:2181 --alter --topic test0 --partitions 10 bin/kafka-topics.sh --zookeeper 192.168.187.146:2181 --alter --topic test0 --partitions 3 ## Kafka分区数量只允许增加,不允许减少

-6. Topic删除

默认情况下Kafka的Topic是没法直接删除的,需要进行相关参数配置

bin/kafka-topics.sh --delete --topic test0 --zookeeper 192.168.187.146:2181

Note: This will have no impact if delete.topic.enable is not set to true.## 默认情况下,删除是标记删除,没有实际删除这个Topic;如果运行删除Topic,两种方式:方式一:通过delete命令删除后,手动将本地磁盘以及zk上的相关topic的信息删除即可方式二:配置server.properties文件,给定参数delete.topic.enable=true,重启kafka服务,此时执行delete命令表示允许进行Topic的删除

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:【PyTorch基础教程29】DIN模型
下一篇:创基Type-c扩展坞五口合一随便连接
相关文章

 发表评论

暂时没有评论,来抢沙发吧~