首页 > 代码库 > kafka常用命令
kafka常用命令
1)下载kafka_2.10-0.8.2.1.tgz并解压(整合scala)
2)修改配置文件(可选)
config/zookeeper.properties
dataDir=/zookeeper
这么写建到d盘根目录
dataDir=zookeeper
这么写建到bin/windows目录
3)启动zookeeper(窗口1)
zookeeper-server-start.sh ../config/zookeeper.properties
4)zookeeper测试(窗口2)
echo stat | nc 192.168.159.133 2181
5)启动kafka(窗口3)
kafka-server-start.sh ../config/server.properties
6)创建topic(窗口4)
kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 3 --topic mytopic
7)查看topic(窗口4)
kafka-topics.sh --describe --zookeeper localhost:2181 --topic mytopic
Topic:mytopic PartitionCount:3 ReplicationFactor:1 Configs:
Topic: mytopic Partition: 0 Leader: 0 Replicas: 0 Isr: 0
Topic: mytopic Partition: 1 Leader: 0 Replicas: 0 Isr: 0
Topic: mytopic Partition: 2 Leader: 0 Replicas: 0 Isr: 0
8)发布/生产消息窗口(窗口5)
kafka-console-producer.sh --broker-list localhost:9092 --topic mytopic
有一个错误提示,但是不影响(kafa的bugKAFKA-1711,KAFKA-1824,预计0.9修复)
9)消费消息窗口(窗口6)
kafka-console-consumer.sh --zookeeper localhost:2181 --from-beginning --topic mytopic
10)znode查看
ls /
[consumers, config, controller, admin, brokers, zookeeper, controller_epoch
ls /consumers
[console-consumer-21728]
ls /config
[topics, changes]
ls /controller
[]
ls /admin
[delete_topics]
ls /brokers
[topics, ids]
ls /zookeeper
[quota]
ls /controller_epoch
[]
11)检查offset(窗口4)
注意:group为consumerid,需要在zk里面查ls /consumer
kafka-consumer-offset-checker.sh --topic mytopic --zookeeper localhost:2181 --broker-info 1
27.0.0.1:9092 --group console-consumer-64061
Group Topic Pid Offset logSize
Lag Owner
console-consumer-64061 mytopic 0 4 4
0 console-consumer-64061_zynb0411-1443580144073-95285fc3
-0
console-consumer-64061 mytopic 1 1 1
0 console-consumer-64061_zynb0411-1443580144073-95285fc3
-0
console-consumer-64061 mytopic 2 1 1
0 console-consumer-64061_zynb0411-1443580144073-95285fc3
-0
BROKER INFO
0 -> zynb0411:9092
kafka常用命令