启动kafka后,连接kafka消息队列报org.apache.kafka.clients.NetworkClient异常

could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)

检查kafka运行日志,报The broker is trying to join the wrong cluster异常

[2024-11-06 16:31:11,219] ERROR Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.KafkaServer)
kafka.common.InconsistentClusterIdException: The Cluster ID QAy4XKSVSYWyIWRKCl3BBQ doesn't match stored clusterId Some(AMdXxjsGTe-ebuBwX0E57g) 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:252)
	at kafka.server.KafkaServerStartable.startup(KafkaServerStartable.scala:44)
	at kafka.Kafka$.main(Kafka.scala:82)
	at kafka.Kafka.main(Kafka.scala)
[2024-11-06 16:31:11,221] INFO shutting down (kafka.server.KafkaServer)
[2024-11-06 16:31:11,223] INFO [feature-zk-node-event-process-thread]: Shutting down (kafka.server.FinalizedFeatureChangeListener$ChangeNotificationProcessorThread)
[2024-11-06 16:31:11,224] INFO [feature-zk-node-event-process-thread]: Shutdown completed (kafka.server.FinalizedFeatureChangeListener$ChangeNotificationProcessorThread)
[2024-11-06 16:31:11,224] INFO [feature-zk-node-event-process-thread]: Stopped (kafka.server.FinalizedFeatureChangeListener$ChangeNotificationProcessorThread)
[2024-11-06 16:31:11,225] INFO [ZooKeeperClient Kafka server] Closing. (kafka.zookeeper.ZooKeeperClient)
[2024-11-06 16:31:11,329] INFO Session: 0x110085d708f0001 closed (org.apache.zookeeper.ZooKeeper)
[2024-11-06 16:31:11,329] INFO EventThread shut down for session: 0x110085d708f0001 (org.apache.zookeeper.ClientCnxn)
[2024-11-06 16:31:11,331] INFO [ZooKeeperClient Kafka server] Closed. (kafka.zookeeper.ZooKeeperClient)
[2024-11-06 16:31:11,335] INFO App info kafka.server for 0 unregistered (org.apache.kafka.common.utils.AppInfoParser)
[2024-11-06 16:31:11,336] INFO shut down completed (kafka.server.KafkaServer)
[2024-11-06 16:31:11,337] ERROR Exiting Kafka. (kafka.server.KafkaServerStartable)
[2024-11-06 16:31:11,337] INFO shutting down (kafka.server.KafkaServer)

修改kafka日志目录的meta.properties文件的cluster.id值

cluster.id=AMdXxjsGTe-ebuBwX0E57g
version=0
broker.id=0

最后再重启kafka,连接恢复正常

[root@master kafka _2.11-1.1.1]# /opt/ kafka / kafka _2.11-1.1.1/bin/ kafka -console-consumer.sh --bootstrap-server master:9092 --topic alarmHis SLF4J: Class ... 2020-08-19 22:55:56.089 WARN [-,,,] 35672 --- [ad | producer-1] org . apache . kafka . client s .Net work Client : [Producer client Id=producer-1] Error while fetching metadata with correlation id 483 : {abc_001=LEADER_NOT_ AVAILABLE } 2020-08-19 22:55:56.205 WARN. 可查看config目录下的server.properti es 中的listeners=PLAINTEXT://xx.xx.xx.xx:9092, kafka 命令中的ip和端口要跟这个配置文件中保持一致。命令中的 kafka 地址和端口是否填写正确。执行 kafka 命令 错。 Connection to node 0 could not be es tabl ished . Broker may not be available . ( org . apache . kafka . client s .Net work Client ) Connection to node 1 (localhost/127.0.0.1:9092) could not be es tabl ished . Broker may not be available . 服务器已经开通了对应的端口,防火.. 具体 错:[Producer client Id=console-producer] Connection to node -1 (localhost/127.0.0.1:9092) could not be es tabl ished . Broker may not be available . ( org . apache . kafka . client s .Net work Client )从上述结果来看,是 错和配置里面的地址有关系,只需要改用配置里的hostname启动就好了。之后输入数据回车 错。 当 kafka Connection to node -1 (localhost/127.0.0.1:9092) could not be es tabl ished . Broker may not be available . ( org . apache . kafka . client s .Net work Client )错的时候,首先检查server.properti es 中的host.name是否一致,若是在spin... kafka could not be es tabl ished . Broker may not be available kafka 启动 错 我查到的解决方法: 修改server.properti es 配置文件 listeners=PLAINTEXT://ip地址:9092 advertised.listeners=PLAINTEXT://ip地址:9092 其实这不用配,也默认localhost:9092的 我也试了这个方法,无效 解决不了问题啊,最后我试了各种方法,甚至导致我的 kafka 启动不了了,最后 意思是连不上 Kafka ,我启动了虚拟机之后,启动项目,运行程序之后 这个错误,一开始没想起来,网上找了一些类似的问题和解决问题,差不多都和IP地址相关,我后来想起来,项目中的application.yml文件中,关于 Kafka 的bootstrap-servers: 虚拟机地址:9092 配置改为了自己的虚拟机地址,原来是:bootstrap-servers: 127.0.0.1:9092,改过之后,重新启动项目,调试接口,能够正常运行。我的 Kafka 配置文件: liulux服务器,安装启动 kafka 服务 kafka _2.12-2.2.0.tgz 解压安装包,修改config目录中zookeeper.properti es 和server.properti es 配置文件,一般只需要修改日志和数据保存的路径,端口使用默认即可 zookeeper.properti es 可以修改dataDir和端口 dataDir=/home/kkk/ kafka /zookeeper server.properti es 可以改,默认参数在本机生产消费可以 log.dirs=/home/kkk/k