记录一些kafka的常用命令,便于平时使用:
1.kafka启动: bin/kafka-server-start.sh config/server.properties &
2.kafka停止: bin/kafka-server-stop.sh
3.创建topic: bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 3 --partitions 3 --topic test
4.查看kafka的topic: bin/kafka-topics.sh --zookeeper master:2181 --list
5.查看kafka的指定topic信息: bin/kafka-topics.sh --zookeeper master:2181 --describe --topic test
6.客户端向kafka集群生产数据: bin/kafka-console-producer.sh --broker-list master:9092 --topic test
7.客户端消费kafka集群的数据: bin/kafka-console-consumer.sh --zookeeper storm1:2181 --topic test --from-beginning
8.查看topic下某分区offset偏移量: bin/kafka-run-class.sh kafka.tools.GetOffsetShell --topic test --time -1 --broker-list master:9092 --partitions 0
9.增加topic的partition: bin/kafka-topics.sh --alter --topic test --zookeeper master:2181 --partitions 5
10.删除topic: /bin/kafka-topics --delete --topic test --zookeeper localhost:2181(需设置delete.topic.enable=true)
11.删除主题数据: log.retention.hours=168 //保留时间,单位小时 log.retention.check.interval.ms=300000 //保留时间检查间隔,单位毫秒
12.删除日志: log.cleanup.policy=delete