kafka 无法从 URL [file:/c/kafka_2.12-2.8.0/bin/../config/tools-log4j.properties 读取 log4j 配置文件

kafka could not read log4j config file from URL [file:/c/kafka_2.12-2.8.0/bin/../config/tools-log4j.properties]

我启动了 zkper 和 kafka。然后我尝试 运行 消费者并得到这个错误。 我使用的命令:

kafka-console-consumer.sh  --zookeeper localhost:2181 --topic erjan --from-beginning

错误:

erjan@erjancomputer MINGW64 /c/kafka_2.12-2.8.0/bin/windows
$ kafka-console-consumer.sh  --zookeeper localhost:2181 --topic erjan --from-beginning
log4j:ERROR Could not read configuration file from URL [file:/c/kafka_2.12-2.8.0/bin/../config/tools-log4j.properties].
java.io.FileNotFoundException: \c\kafka_2.12-2.8.0\bin\..\config\tools-log4j.properties (The system cannot find the path specified)
        at java.io.FileInputStream.open0(Native Method)
        at java.io.FileInputStream.open(FileInputStream.java:195)
        at java.io.FileInputStream.<init>(FileInputStream.java:138)
        at java.io.FileInputStream.<init>(FileInputStream.java:93)
        at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:90)
        at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:188)
        at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:557)
        at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:526)
        at org.apache.log4j.LogManager.<clinit>(LogManager.java:127)
        at org.slf4j.impl.Log4jLoggerFactory.<init>(Log4jLoggerFactory.java:66)
        at org.slf4j.impl.StaticLoggerBinder.<init>(StaticLoggerBinder.java:72)
        at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:45)
        at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
        at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
        at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:417)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:362)
        at com.typesafe.scalalogging.Logger$.apply(Logger.scala:48)
        at kafka.utils.Log4jControllerRegistration$.<init>(Logging.scala:25)
        at kafka.utils.Log4jControllerRegistration$.<clinit>(Logging.scala)
        at kafka.utils.Logging.$init$(Logging.scala:47)
        at kafka.tools.ConsoleConsumer$.<init>(ConsoleConsumer.scala:44)
        at kafka.tools.ConsoleConsumer$.<clinit>(ConsoleConsumer.scala)
        at kafka.tools.ConsoleConsumer.main(ConsoleConsumer.scala)
log4j:ERROR Ignoring configuration file [file:/c/kafka_2.12-2.8.0/bin/../config/tools-log4j.properties].
log4j:WARN No appenders could be found for logger (kafka.utils.Log4jControllerRegistration$).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
zookeeper is not a recognized option

为什么没有看到 config/log4j.properties?

找不到 log4j 文件,因为我猜,Windows 中的 mingw 或类似 shell 环境并未在 Kafka 源代码中真正测试。这就是为什么有 .bat 脚本的原因。如果要使用 Linux shell,请卸载 Git Bash 并使用 WSL2

除此之外,它与实际错误无关。您需要使用 --bootstrap-server localhost:9092 而不是 Zookeeper 标志才能从 Kafka 消费。

参考官方文档(针对Linux),但是命令参数都是一样的,即使你使用windows脚本

http://kafka.apache.org/quickstart