kafka启动之后,一段时间后自动关闭
kafka启动之后,一段时间后自动停止,出现这种情况一般是没有使用守护进程 -daemon 启动kafka。
①第一种情况:
[cluster@hadoop102 kafka_2.11-0.11.0.2]$ bin/kafka-server-start.sh -daemon config/server.properties
原因请参考/opt/module/kafka_2.11-0.11.0.2/bin下的kafka-run-class.sh 文件。
# Launch mode
#使用-daemon启动
if [ "x$DAEMON_MODE" = "xtrue" ]; then
nohup $JAVA $KAFKA_HEAP_OPTS $KAFKA_JVM_PERFORMANCE_OPTS $KAFKA_GC_LOG_OPTS $KAFKA_JMX_OPTS $KAFKA_LOG4J_OPTS -cp $CLASSPATH $KAFKA_OPTS "$@" > "$CONSOLE_OUTPUT_FILE" 2>&1 < /dev/null &
else
#不使用-daemon启动
exec $JAVA $KAFKA_HEAP_OPTS $KAFKA_JVM_PERFORMANCE_OPTS $KAFKA_GC_LOG_OPTS $KAFKA_JMX_OPTS $KAFKA_LOG4J_OPTS -cp $CLASSPATH $KAFKA_OPTS "$@"
fi
②、还有一种情况是上次kafka没有正常退出,即kafka还没有关闭就关闭了zookeeper。
查看kafka启动日志,一般在kafka/logs目录下的server.log文件。
报错信息如下:
[2020-02-02 00:02:04,660] INFO Result of znode creation is: NODEEXISTS (kafka.utils.ZKCheckedEphemeral)
[2020-02-02 00:02:04,663] FATAL [Kafka Server 3], Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.KafkaServer)
java.lang.RuntimeException: A broker is already registered on the path /brokers/ids/3. This probably indicates that you either have configured a brokerid that is already in use, or else you have shutdown this broker and restarted it faster than the zookeeper timeout so it appears to be re-registering.
at kafka.utils.ZkUtils.registerBrokerInZk(ZkUtils.scala:417)
at kafka.utils.ZkUtils.registerBrokerInZk(ZkUtils.scala:403)
at kafka.server.KafkaHealthcheck.register(KafkaHealthcheck.scala:70)
at kafka.server.KafkaHealthcheck.startup(KafkaHealthcheck.scala:50)
at kafka.server.KafkaServer.startup(KafkaServer.scala:280)
at kafka.server.KafkaServerStartable.startup(KafkaServerStartable.scala:38)
at kafka.Kafka$.main(Kafka.scala:65)
at kafka.Kafka.main(Kafka.scala)
解决方法;
停掉kafka,启动zkCli.sh,删除对应的节点。
[atguigu@hadoop102 jobs]$ zkCli.sh
[zk: localhost:2181(CONNECTED) 2] ls /brokers/ids
[1]
[zk: localhost:2181(CONNECTED) 2] rmr /brokers/ids
[zk: localhost:2181(CONNECTED) 2] ls /brokers/ids
[]
然后。。。
当然是重新启动kafka了,一般到了这里问题就解决了。
如果有不足之处,还请大家多多指正。