分享

Kafka命令行常用命令说明

 木棉下的守望 2015-03-19

转自:http://blog.csdn.net/itleochen/article/details/18407063

基于0.8.0版本。

##查看topic分布情况 kafka-list-topic.sh

bin/kafka-list-topic.sh --zookeeper 192.168.197.170:2181,192.168.197.171:2181  (列出所有topic的分区情况)

bin/kafka-list-topic.sh --zookeeper 192.168.197.170:2181,192.168.197.171:2181 --topic test (查看test的分区情况)

其实kafka-list-topic.sh里面就一句 

exec $(dirname $0)/kafka-run-class.sh kafka.admin.ListTopicCommand $@
实际是通过

kafka-run-class.sh脚本执行的包kafka.admin下面的类

##创建TOPIC  kafka -create-topic.sh  ,

bin/ kafka -create-topic.sh    --replica 2 --partition 8 --topic test    --zookeeper  192.168.197.170:2181,192.168.197.171:2181

创建名为test的topic, 8个分区分别存放数据,数据备份总共2份

bin/ kafka -create-topic.sh    --replica 1 --partition 1 --topic test2    --zookeeper  192.168.197.170:2181,192.168.197.171:2181

结果 topic: test2 partition: 0 leader: 170 replicas: 170 isr: 170

##重新分配分区 kafka-reassign-partitions.sh

这个命令可以分区指定到想要的--broker-list上

bin/kafka-reassign-partitions.sh --topics-to-move-json-file topics-to-move.json --broker-list "171" --zookeeper 192.168.197.170:2181,192.168.197.171:2181 --execute 

cat topic-to-move.json

{"topics":

     [{"topic": "test2"}],

     "version":1

}

##为Topic增加 partition数目

bin/kafka-add-partitions.sh --topic test --partition 2   --zookeeper   192.168.197.170:2181,192.168.197.171:2181 (为topic test增加2个分区)

##控制台接收消息

bin/ kafka -console-consumer.sh --zookeeper   192.168.197.170:2181,192.168.197.171:2181  --from-beginning --topic test

##控制台发送消息

bin/kafka-console-producer.sh --broker-list  192.168.197.170:9092,192.168.197.171: 9092     --topic test 

##删除topic,慎用,只会删除zookeeper中的元数据,消息文件须手动删除

bin/kafka-run-class.sh kafka.admin.DeleteTopicCommand --topic test666 --zookeeper 192.168.197.170:2181 ,192.168.197.171:2181

##查看topic分布情况 kafka-list-topic.sh

bin/kafka-list-topic.sh --zookeeper 192.168.197.170:2181,192.168.197.171:2181  (列出所有topic的分区情况)

bin/kafka-list-topic.sh --zookeeper 192.168.197.170:2181,192.168.197.171:2181 --topic test (查看test的分区情况)

其实kafka-list-topic.sh里面就一句 

exec $(dirname $0)/kafka-run-class.sh kafka.admin.ListTopicCommand $@
实际是通过

kafka-run-class.sh脚本执行的包kafka.admin下面的类

##创建TOPIC  kafka -create-topic.sh  ,

bin/ kafka -create-topic.sh    --replica 3 --partition 8 --topic test    --zookeeper  192.168.197.170:2181,192.168.197.171:2181

创建名为test的topic, 8个分区分别存放数据,数据备份总共3份

bin/ kafka -create-topic.sh    --replica 1 --partition 1 --topic test2    --zookeeper  192.168.197.170:2181,192.168.197.171:2181

结果 topic: test2 partition: 0 leader: 170 replicas: 170 isr: 170

##重新分配分区 kafka-reassign-partitions.sh

这个命令可以分区指定到想要的--broker-list上

bin/kafka-reassign-partitions.sh --topics-to-move-json-file topics-to-move.json --broker-list "171" --zookeeper 192.168.197.170:2181,192.168.197.171:2181 --execute 

cat topic-to-move.json

{"topics":

     [{"topic": "test2"}],

     "version":1

}


##为Topic增加 partition数 kafka-add-partitions.sh

bin/kafka-add-partitions.sh --topic test --partition 2   --zookeeper   192.168.197.170:2181,192.168.197.171:2181 (为topic test增加2个分区)

##控制台接收消息

bin/ kafka -console-consumer.sh --zookeeper   192.168.197.170:2181,192.168.197.171:2181  --from-beginning --topic test

##控制台发送消息

bin/kafka-console-producer.sh --broker-list  192.168.197.170:9092,192.168.197.171: 9092     --topic test 

##删除topic,慎用,只会删除zookeeper中的元数据,消息文件须手动删除

bin/kafka-run-class.sh kafka.admin.DeleteTopicCommand --topic test666 --zookeeper 192.168.197.170:2181 ,192.168.197.171:2181


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多