Kafka常用命令总结
1、清空某个topic数据
需要在service设置delete.topic.enable=true
./bin/kafka-topics.sh --zookeeper 172.23.75.105:2181 --delete --topic robots2
2、查看topic列表
./bin/kafka-topics.sh --zookeeper localhost:2181 --list
3、启动停止kafka
后台启动:nohup ./bin/kafka-server-start.sh ./config/server.properties &
./kafka-server-start.sh ../config/server.properties 2>&1 &
停止:./bin/kafka-server-stop.sh
4、修改某个topic保存数据时间
./kafka-topics.sh --zookeeper ip地址1:2181,ip地址2:2181,ip地址3:2181 --alter --topic topic名字 --config retention.ms=43200000
5、修改某个topic,单条消息大小。
报错: org.apache.kafka.common.errors.RecordTooLargeException: The request included a message larger than the max message size the server will accept.
./kafka-topics.sh --zookeeper localhost:2181 --alter --topic topic名字 --config max.message.bytes=5914560
6、查看topic列表
./kafka-topics.sh --zookeeper 127.0.0.1:2181 --list
7、消费数据
./kafka-console-consumer.sh --bootstrap-server 127.0.0.1:9092 --topic test.test_123 --group test_wang
带鉴权方式消费数据
./kafka-console-consumer.sh --bootstrap-server ***.tencentcloudmq.com:50000 --topic XXX --consumer.config ../config/consumer.properties
待其它属性输出
./kafka-console-consumer.sh --bootstrap-server 127.0.0.1:9092 --topic test123 --group test_wang --property print.timestamp=true --property print.partition=true --property print.key=true --property print.value=true | grep 417121210759960583|grep 417121056696877056 |grep 8341871042646
8、生产数据
./kafka-console-producer.sh --broker-list ***.tencentcloudmq.com:50000 --topic XXX --producer.config ../config/producer.properties
9、查看消费延迟情况
bin/kafka-consumer-groups.sh --bootstrap-server 127.0.0.1:9092 --describe --group test-compass
10、kafka配置消息大小
message.max.bytes=5242880
每个分区试图获取的消息字节数。要大于等于message.max.bytes
replica.fetch.max.bytes=6291456
原有的socket.send.buffer.bytes,socket.receive.buffer.bytes,socket.request.max.bytes也要改成和message.max.bytes一样的大小
11、创建topic
./kafka-topics.sh --zookeeper localhost:2181 --create --topic test5 --partitions 1 --replication-factor 1
12、查询topic的offset
./kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 -topic test5 --time -2

浙公网安备 33010602011771号