Kafka 宕机,调整内存设置

现象

突然发现 Flink 连接不上 Kafka 了,经检查 s1 服务器上的 Kafka 宕了,尝试用命令启动 Kafka:

$ kafka-server-start.sh -daemon /opt/module/kafka/config/server.properties

还是启动不了。

问题

检查日志:

$ vim /opt/module/kafka/logs/kafkaServer.out

Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c0000000, 1073741824, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 1073741824 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /home/hadoop/hs_err_pid61275.log

是 JVM 的问题,没有内存了,我这台服务器可能是运行的东西太多了,所以导致 Kafka 因为缺少内存而宕掉了;

解决

修改 Kafka 启动命令脚本中的 JVM 设置

$ vim vim /opt/module/kafka/bin/kafka-server-start.sh

将其中的:

if [ "x$KAFKA_HEAP_OPTS" = "x" ]; then
    export KAFKA_HEAP_OPTS="-Xmx1G -Xms1G"
fi

改为

if [ "x$KAFKA_HEAP_OPTS" = "x" ]; then
    export KAFKA_HEAP_OPTS="-Xmx256M -Xms128M"
fi

再尝试启动:

$ kafka-server-start.sh -daemon /opt/module/kafka/config/server.properties

启动成功!

你可能感兴趣的:(Kafka,Java,kafka,java,分布式,JVM,Flink)