在使用brew services start kafka 成功启动kafka后,
执行发送消息会有提示以下,无法发送消息。
kafka-console-producer --broker-list localhost:9092 --topic test1
[2020-10-09 20:46:34,131] WARN [Consumer clientId=consumer-console-consumer-76912-1, groupId=console-consumer-76912] Bootstrap broker localhost:9092 (id: -1 rack: null) disconnected (org.apache.kafka.clients.NetworkClient)
[2020-10-09 20:46:34,885] WARN [Consumer clientId=consumer-console-consumer-76912-1, groupId=console-consumer-76912] Connection to node -1 (localhost/127.0.0.1:9092) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
查看kafka启动日志(mac brew安装),和bin目录在同一级
cd /usr/local/Cellar/kafka/2.6.0/libexec
ls
bin config libs logs
如果不知道日志文件在哪里可以搜索server.log
日志报错
kafka.common.InconsistentClusterIdException: The Cluster ID PLRSHbe7QESsqnyqO2JJsw doesn't match stored clusterId Some(RoyCX4R1TYOGg3GoNsoxNg) in meta.properties. The broker is trying to join the wrong cluster. Configured zookeeper.connect may be wrong.
at kafka.server.KafkaServer.startup(KafkaServer.scala:235)
at kafka.server.KafkaServerStartable.startup(KafkaServerStartable.scala:44)
at kafka.Kafka$.main(Kafka.scala:82)
at kafka.Kafka.main(Kafka.scala)
[2020-10-09 21:03:36,766] INFO shutting down (kafka.server.KafkaServer)
解决办法:
删除 /usr/local/var/lib/kafka-logs文件。
如果在bin目录下直接执行./kafka-server-start.sh …/config/server.properties
会直接控制台会打印上面的报错。