Kafka常用命令 2015-07-29 19:00

常用命令

列出所有Topic:

/opt/kafka/bin/kafka-topics.sh --list --zookeeper data01:2181,data02:2181,data03:2181/kafka

列出所有Topic信息:

/opt/kafka/bin/kafka-topics.sh --describe --zookeeper data01:2181,data02:2181,data03:2181/kafka
root@data01 kafka]# bin/kafka-topics.sh --describe --zookeeper data01:2181
Topic:mytopic1  PartitionCount:2        ReplicationFactor:2     Configs:
        Topic: mytopic1 Partition: 0    Leader: 3       Replicas: 2,3   Isr: 3,2
        Topic: mytopic1 Partition: 1    Leader: 3       Replicas: 3,1   Isr: 3,1
Topic:mytopic2  PartitionCount:2        ReplicationFactor:2     Configs:
        Topic: mytopic2 Partition: 0    Leader: 3       Replicas: 2,3   Isr: 3,2
        Topic: mytopic2 Partition: 1    Leader: 3       Replicas: 3,1   Isr: 3,1
Topic:mytopic3  PartitionCount:2        ReplicationFactor:2     Configs:
        Topic: mytopic3 Partition: 0    Leader: 2       Replicas: 2,1   Isr: 2,1
        Topic: mytopic3 Partition: 1    Leader: 3       Replicas: 3,2   Isr: 3,2
Topic:mytopic4  PartitionCount:2        ReplicationFactor:2     Configs:
        Topic: mytopic4 Partition: 0    Leader: 3       Replicas: 2,3   Isr: 3,2
        Topic: mytopic4 Partition: 1    Leader: 3       Replicas: 3,1   Isr: 3,1
[root@data01 kafka]#

删除Topic:

/opt/kafka/bin/kafka-topics.sh --delete --topic cheyo-topic --zookeeper data01:2181,data02:2181,data03:2181/kafka

创建Topic:

/opt/kafka/bin/kafka-topics.sh --create --replication-factor 2 --partitions 2 --topic mytopic1 --zookeeper data01:2181,data02:2181,data03:2181/kafka

生产消息:

/opt/kafka/bin/kafka-console-producer.sh --broker-list data01:9092,data02:9092,data03:9092 --topic mytopic4

消费消息:

/opt/kafka/bin/kafka-console-consumer.sh --zookeeper data01:2181,data02:2181,data03:2181/kafka --from-beginning --topic mytopic4
Tags: #Kafka    Post on Hadoop