kafka版本声明
- 使用的是
kafka 0.10.0.1
版本
常用命令
查看kafka版本
-
查看kafka版本
# find / -name \*kafka_\* | head -1 | grep -o '\kafka[^\n]*'
主题
-
创建
Topic
、Partition
(5个),replication
(1个)# bin/kafka-topics.sh --create --zookeeper zookeeper:2181 --replication-factor 1 --partitions 5 --topic testTopic
-
查看
Topic
最大(最小)的offset
,--time,-1表示最大,-2表示最小
# bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 -topic topic-A --time -1 topic-A:2:60 topic-A:4:60 topic-A:1:60 topic-A:3:60 topic-A:0:60
-
列出集群中所有的
topic
# bin/kafka-topics.sh --zookeeper zookeeper:2181 --list
-
查看
Topic
明细# bin/kafka-topics.sh --describe --zookeeper zookeeper:2181 --topic testTopic Topic:testTopic PartitionCount:5 ReplicationFactor:1 Configs: Topic: testTopic Partition: 0 Leader: 1 Replicas: 1 Isr: 1 Topic: testTopic Partition: 1 Leader: 1 Replicas: 1 Isr: 1 Topic: testTopic Partition: 2 Leader: 1 Replicas: 1 Isr: 1 Topic: testTopic Partition: 3 Leader: 1 Replicas: 1 Isr: 1 Topic: testTopic Partition: 4 Leader: 1 Replicas: 1 Isr: 1
-
修改
topic
参数,partitions
个数只能被增加不能减少。如果一定要减少partitions
个数,只能删除整个主题,重新建立# bin/kafka-topics.sh --zookeeper zookeeper:2181 --partition 6 --topic testTopic --alter
-
删除
Topic
,broker
的delete.topic.enable=true
才可以删除,否则删除topic
的请求会被忽略.删除topic
会丢弃topic
里所有数据。# bin/kafka-topics.sh --zookeeper zookeeper:2181 --delete --topic topicAgroup
生产
-
生产数据
# bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test --producer.config config/producer.properties
消费
-
消费
# bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --new-consumer --from-beginning --consumer.config config/consumer.properties # bin/kafka-simple-consumer-shell.sh --brist localhost:9092 --topic test --partition 0 --offset 1234 --max