kafka启动
nohup bin/zookeeper-server-start.sh config/zookeeper.properties >log/zookeeper/zookeeper.log 2>1 &
nohup bin/kafka-server-start.sh config/server.properties >log/kafka/kafka.log 2>1 &
创建topic
创建一个名为“test”的Topic,只有一个分区和备份(2181是zookeeper的默认端口)
./kafka-topics.sh --create --zookeeper localhost:2181 --config max.message.bytes=12800000 --config flush.messages=1 --replication-factor 1 --partitions 1 --topic test
删除topic
如果需要彻底删除kafka中的topic,需要更改config文件夹下的server.properties,否则所谓的删除只是做一个标记。
delete.topic.enable=true
执行以下命令删除topic
bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic ${TOPIC_NAME}
查看当前的topic
bin/kafka-topics.sh --list --zookeeper localhost:2181
查看对应的topic信息
./kafka-topics.sh --describe --zookeeper localhost:2181 --topic test
kafka自带的消费工具
1.使用kafka自带的消费工具从头开始消费数据
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
2.指定分区、偏移量以及消费的条数
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test11 --offset 0 --partition 2 --max-messages 1
说明:
--offset:指定偏移量
--partition:指定分区
--max-messages:指定退出程序之前最多消费多少条数据。如果不加该参数,默认消费该偏移量后的所有数据
日志输出dead for group解决办法
修改C:\Windows\System32\drivers\etc\hosts文件,添加主机名和ip