使用 docker-compose 启动kafka时失败,日志显示报错信息:

[2022-02-15 09:19:09,135] INFO Cluster ID = fGh3I6w3QkCRV6YfFWPnuA (kafka.server.KafkaServer)

[2022-02-15 09:19:09,150] ERROR Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.KafkaServer)

kafka.common.InconsistentClusterIdException: The Cluster ID fGh3I6w3QkCRV6YfFWPnuA doesn't match stored clusterId Some(gK7UrN_6TYqTLH8OhiZM9A) 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:228)

at kafka.Kafka$.main(Kafka.scala:109)

at kafka.Kafka.main(Kafka.scala)

[2022-02-15 09:19:09,152] INFO shutting down (kafka.server.KafkaServer)

大致原因为:
如果kafka部署时挂载了本地目录, kafka 初次启动会注册 cluster id 到 /data/meta.properties 中。
当删除容器又重新生成,但 /data 中数据没有清除,则会产生引发该错误

解决办法:
清空数据即可