Kafka 常用命令
Kafka 常用命令
适用于kafka-2.4.0
注意,如下命令是在kafka/bin目录下执行,如果配置了环境变量,可直接使用命令:如 kafka-topics xxxx
## 1. 查看topic消费到的offset
kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --topic test2 --time -1
## 2.指定分区消费消息
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test2 --from-beginning [--partition 0]
## 3.生产消息
kafka-console-producer.sh --broker-list localhost:9092 --topic test2 < file-input.txt
## 4.查看详细信息
kafka-topics.sh --zookeeper zookeeper:2181 --topic test --describe
kafka-topics.sh --alter --zookeeper zookeeper:2181 --topic test --partitions 2
## 5.创建topic
## 方式1
kafka-topics.sh --create \
--topic com_push \
--zookeeper localhost:2181 \
--partitions 2 \
--replication-factor 1
## 方式2
kafka-topics.sh --create --bootstrap-server kafka-n1:9092,kafka-n2:9092,kafka-n3:9092 --replication-factor 1 --partitions 3 --topic com_push
kafka-topics.sh --create --bootstrap-server kafka-n1:9092,kafka-n2:9092,kafka-n3:9092 --replication-factor 1 --partitions 3 --topic test_topic
## 6.删除topic
kafka-topics.sh --delete --zookeeper zookeeper-n1:2181,zookeeper-n2:2181,zookeeper-n3:2181 --topic test_topic
## 7.列出topic
kafka-topics.sh --list --zookeeper zookeeper-n1:2181,zookeeper-n2:2181,zookeeper-n3:2181
## 8.列出consumer
kafka-consumer-groups.sh --list -bootstrap-server kafka-n1:9092,kafka-n2:9092,kafka-n3:9092
## 9.删除consumer
kafka-consumer-groups.sh --delete --group be-python-event-pair -bootstrap-server kafka-n1:9092,kafka-n2:9092,kafka-n3:9092
## 10.console生产者
kafka-console-producer.sh --broker-list kafka-n1:9092,kafka-n2:9092,kafka-n3:9092 --topic test_topic
## 11.console消费者
bin/kafka-console-consumer.sh --topic test_topic --from-beginning --bootstrap-server kafka-n1:9092,kafka-n2:9092,kafka-n3:9092
## 12.增加分区
kafka-topics.sh --alter --topic mall-merged-tracks --zookeeper zookeeper-n1:2181,zookeeper-n2:2181,zookeeper-n3:2181 --partitions 6
## 13.获取偏移量
kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 -topic test --time -1
## 14.重置偏移量
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group consumer_id --topic mall-tracks --execute --reset-offsets --to-offset 80
## 14-2.重置时间偏移量
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group flink-dev1 --topic bigdata_table--reset-offsets --to-datetime 2022-04-01T16:00:00.000 --execute