haizhilingyu 的个人知识记录

Open Source, Open Mind,
Open Sight, Open Future!

解决kafka启动找不到meta.properties文件

解决kafka启动找不到meta.properties文件

今天执行启动kafka命令报错了,如下:

[2024-04-22 10:55:12,331] INFO Registered kafka:type=kafka.Log4jController MBean (kafka.utils.Log4jControllerRegistration$)
[2024-04-22 10:55:13,017] INFO Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation (org.apache.zookeeper.common.X509Util)
[2024-04-22 10:55:13,204] ERROR Exiting Kafka due to fatal exception (kafka.Kafka$)
java.lang.RuntimeException: No readable meta.properties files found.
        at org.apache.kafka.metadata.properties.MetaPropertiesEnsemble.verify(MetaPropertiesEnsemble.java:493)
        at kafka.server.KafkaRaftServer$.initializeLogDirs(KafkaRaftServer.scala:152)
        at kafka.server.KafkaRaftServer.<init>(KafkaRaftServer.scala:60)
        at kafka.Kafka$.buildServer(Kafka.scala:82)
        at kafka.Kafka$.main(Kafka.scala:90)
        at kafka.Kafka.main(Kafka.scala)

原因分析:

原因在 kafka默认的server.properites中设置的日志目录是 /tmp/kraft-combined-logs,服务器重启后目录 /tmp 就被清空了,没有修改 log.dirs 日志文件存贮目录,导致启动报错在 /tmp/kraft-combined-logs 目录下找不到 meta.properties 文件

解决办法

在启动的server.properites中将log.dir参数修改,执行命令vim config/kraft/server.properties

# A comma separated list of directories under which to store log files
log.dirs=./kraft-combined-logs

然后重新初始化存储,我这里是单机测试使用用的KRaft存储,根据自己的情况修改即可,更多修改参考官方文档

KAFKA_CLUSTER_ID="$(bin/kafka-storage.sh random-uuid)"
./bin/kafka-storage.sh format -t $KAFKA_CLUSTER_ID -c config/kraft/server.properties

解决连接Kafka后却转发到127.0.0.1进行连接通信的问题

解决方法

执行命令vim config/kraft/server.properties,修改advertised.listeners将ip地址改为服务器IP地址

advertised.listeners=PLAINTEXT://自己服务器IP:9092

标题:解决kafka启动找不到meta.properties文件
作者:haizhilingyu
地址:https://xiweihai.site/articles/2024/04/22/1713783391048.html