Kafka启动报错:ERROR Error while loading log dir tmp kafka-logs

Kafka启动报错:

ERROR Error while loading log dir /tmp/kafka-logs (kafka.log.LogManager)
java.io.IOException: Invalid argument
        at java.io.RandomAccessFile.setLength(Native Method)
        at kafka.log.AbstractIndex.$anonfun$resize$1(AbstractIndex.scala:189)
        at kafka.log.AbstractIndex.resize(AbstractIndex.scala:175)
        at kafka.log.AbstractIndex.$anonfun$trimToValidSize$1(AbstractIndex.scala:241)
        at kafka.log.AbstractIndex.trimToValidSize(AbstractIndex.scala:241)
        at kafka.log.LogSegment.recover(LogSegment.scala:378)
        at kafka.log.LogLoader$.recoverSegment(LogLoader.scala:375)
        at kafka.log.LogLoader$.recoverLog(LogLoader.scala:426)
        at kafka.log.LogLoader$.$anonfun$load$11(LogLoader.scala:168)
        at kafka.log.LogLoader$.load(LogLoader.scala:280)
        at kafka.log.UnifiedLog$.apply(UnifiedLog.scala:1785)
        at kafka.log.LogManager.loadLog(LogManager.scala:282)
        at kafka.log.LogManager.$anonfun$loadLogs$13(LogManager.scala:368)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:750)

ERROR Error while loading log dir /tmp/kafka-logs (kafka.server.LogDirFailureChannel)
java.io.IOException: Invalid argument
        at java.io.RandomAccessFile.setLength(Native Method)
        at kafka.log.AbstractIndex.$anonfun$resize$1(AbstractIndex.scala:189)
        at kafka.log.AbstractIndex.resize(AbstractIndex.scala:175)
        at kafka.log.AbstractIndex.$anonfun$trimToValidSize$1(AbstractIndex.scala:241)
        at kafka.log.AbstractIndex.trimToValidSize(AbstractIndex.scala:241)
        at kafka.log.LogSegment.recover(LogSegment.scala:378)
        at kafka.log.LogLoader$.recoverSegment(LogLoader.scala:375)
        at kafka.log.LogLoader$.recoverLog(LogLoader.scala:426)
        at kafka.log.LogLoader$.$anonfun$load$11(LogLoader.scala:168)
        at kafka.log.LogLoader$.load(LogLoader.scala:280)
        at kafka.log.UnifiedLog$.apply(UnifiedLog.scala:1785)
        at kafka.log.LogManager.loadLog(LogManager.scala:282)
        at kafka.log.LogManager.$anonfun$loadLogs$13(LogManager.scala:368)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:750)

Kafka注册到Zookeeper,Zookeeper也报错:

EndOfStreamException: Unable to read additional data from client, it probably closed the socket: address = /127.0.0.1:12345, session = 0x1000027de680000
        at org.apache.zookeeper.server.NIOServerCnxn.handleFailedRead(NIOServerCnxn.java:163)
        at org.apache.zookeeper.server.NIOServerCnxn.doIO(NIOServerCnxn.java:326)
        at org.apache.zookeeper.server.NIOServerCnxnFactory$IOWorkRequest.doWork(NIOServerCnxnFactory.java:522)
        at org.apache.zookeeper.server.WorkerService$ScheduledWorkRequest.run(WorkerService.java:154)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:750)
[2022-04-01 15:52:57,519] INFO Expiring session 0x1000027de680000, timeout of 18000ms exceeded (org.apache.zookeeper.server.ZooKeeperServer)

Kafka的错误已经比较明确的指出了问题点:/tmp/kafka-logs
解决办法:直接清空/tmp/kafka-logs目录下的文件,重新启动Zookeeper和Kafka即可。