因为 es和 logstash 都正常运行。 green 节点green 查看 kibana 日志
<--- Last few GCs --->[6:0x25fdcc0] 370913 ms: Mark-sweep 854.6 (1060.6) -> 854.5 (1028.6) MB, 143.5 / 0.0 ms (average mu = 0.862, current mu = 0.000) last resort GC in old space requested
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
[6:0x25fdcc0] 371055 ms: Mark-sweep 854.5 (1028.6) -> 854.5 (1028.1) MB, 142.6 / 0.0 ms (average mu = 0.757, current mu = 0.000) last resort GC in old space requested<--- JS stacktrace --->==== JS stack trace =========================================Security context: 0x2c5f0f01e6e1 0: builtin exit frame: parse(this=0x2c5f0f011a19
发现是 kibana前端 js 报的内存 oom 异常,通过网上资料发现node.js 的默认内存大小为1.4g ,那么问题就定位到修改node 的内存限制。
docker 实际启动路径 /usr/share/kibana/bin/kibana
查看kibana 执行文件
#!/bin/sh
SCRIPT=$0# SCRIPT may be an arbitrarily deep series of symlinks. Loop until we have the concrete path.
while [ -h "$SCRIPT" ] ; dols=$(ls -ld "$SCRIPT")# Drop everything prior to ->link=$(expr "$ls" : '.*-> \(.*\)$')if expr "$link" : '/.*' > /dev/null; thenSCRIPT="$link"elseSCRIPT=$(dirname "$SCRIPT")/"$link"fi
doneDIR="$(dirname "${SCRIPT}")/.."
NODE="${DIR}/node/bin/node"
test -x "$NODE"
if [ ! -x "$NODE" ]; thenecho "unable to find usable node.js executable."exit 1
fiNODE_ENV=production exec "${NODE}" --no-warnings --max-http-header-size=65536 $NODE_OPTIONS "${DIR}/src/cli" ${@}添加内存空间的环境变量 Solution
NODE_ENV=production exec "${NODE}" --no-warnings --max-http-header-size=65536 $NODE_OPTIONS --max-old-space-size=12288 "${DIR}/src/cli" ${@}
解决办法:
在 kibana 启动文件 添加内存空间的环境变量 Solution
添加 $NODE_OPTIONS --max-old-space-size=12288
参照官方文档的解释:
https://nodejs.org/api/cli.html#cli_node_options_options
V8 has its own set of CLI options. Any V8 CLI option that is provided to node will be passed on to V8 to handle. V8’s options have no stability guarantee. The V8 team themselves don’t consider them to be part of their formal API, and reserve the right to change them at any time. Likewise, they are not covered by the Node.js stability guarantees. Many of the V8 options are of interest only to V8 developers. Despite this, there is a small set of V8 options that are widely applicable to Node.js, and they are documented here:
–max-old-space-size=SIZE (in megabytes)
Sets the max memory size of V8’s old memory section. As memory consumption approaches the limit, V8 will spend more time on garbage collection in an effort to free unused memory.
On a machine with 2 GiB of memory, consider setting this to 1536 (1.5 GiB) to leave some memory for other uses and avoid swapping.
$ node --max-old-space-size=1536 index.js
翻译提炼为:
Old space是 V8 托管(也称为垃圾收集)堆(即 JavaScript 对象所在的位置)中最大和最可配置的部分,而 --max-old-space-size 标志控制其最大大小。 随着内存消耗接近极限,V8 将花费更多时间在垃圾收集上,以释放未使用的内存。
如果堆内存消耗(即 GC 无法释放的活动对象)超过限制,V8 将使您的进程崩溃(因为缺乏替代方案),因此您不想将其设置得太低。 当然,如果您将其设置得太高,那么 V8 将允许的额外堆使用可能会导致您的整个系统内存不足(并且由于缺乏替代方案而交换或终止随机进程)。
总之,在具有 2GB 内存的机器上,我可能会将 --max-old-space-size 设置为大约 1.5GB 以留出一些内存用于其他用途并避免交换。
2G的内存机器,单独运行 node 进程,设置为1.5GB 这里1536 = 1.5GB 。所以 --max-old-space-size 的单位是 MB