[Kafka] - Kafka基本操作命令

Kafka支持的基本命令位于${KAFKA_HOME}/bin文件夹中,主要是kafka-topics.sh命令;Kafka命令参考页面: kafka-0.8.x-帮助文档

 

 -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=128000
bin/kafka-topics.sh --zookeeper 192.168.187.146:2181 --alter --topic test0 --delete-config max.message.bytes
bin/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的删除

 

posted @ 2017-02-21 11:58  liuming_1992  阅读(48464)  评论(0编辑  收藏  举报