一、前言:
今天收到kibana服务告警。
环境信息:
- es7,4
- kibana 7.4
二、报错内容:
<--- Last few GCs --->[2800:0x326ea90] 95392 ms: Mark-sweep 799.2 (1133.8) -> 799.2 (1085.3) MB, 150.5 / 0.0 ms (average mu = 0.710, current mu = 0.000) last resort GC in old space requested[2800:0x326ea90] 95529 ms: Mark-sweep 799.2 (1085.3) -> 799.2 (1070.3) MB, 137.3 / 0.0 ms (average mu = 0.543, current mu = 0.000) last resort GC in old space requested
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x3a58ad01e6e1 <JSObject>
0: builtin exit frame: parse(this=0x3a58ad011a19 <Object map = 0x374341f842a9>,0x3841a8ca2039 <Very long string[288880043]>,0x3a58ad011a19 <Object map = 0x374341f842a9>)
1: deserialize [0x819d66b2741] [/home/rong/kibana-7.4.2-linux-x86_64/node_modules/elasticsearch/src/lib/serializers/json.js:~42] [pc=0x3678c4fca9ea](this=0x07db7f934c09 <Json map = 0x3a4fd1f3c591>,str=0x3841a8ca2039 <Ve...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
1: 0x8dc1c0 node::Abort() [./../node/bin/node]
2: 0x8dc20c [./../node/bin/node]
3: 0xad60ae v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [./../node/bin/node]
4: 0xad62e4 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [./../node/bin/node]
5: 0xec3972 [./../node/bin/node]
6: 0xed318f v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [./../node/bin/node]
三、报错原因:
发现是前端 js 报的内存 oom 异常,通过网上资料发现node.js 的默认内存大小为1.4g
Node 中通过 JavaScript 使用内存时只能使用部分内存(64位系统下约为1.4 GB,32位系统下约为0.7 GB),这就是我们编译项目时为什么会出现内存泄露了,因为前端项目如果非常的庞大,webpack 编译时就会占用很多的系统资源,如果超出了V8对 Node 默认的内存限制大小就会出现node内存溢出的报错:CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
四、解决方案:
修改 --max-old-space-size
参数来调整内存大小的使用限制
- 进入 kibana/bin 目录(也可以设置在 node 的环境变量里,我是加在 kibana 文件中)
vi kibana
- 添加内存空间的环境变量(以下 size 为4g,根据实际情况修改)
NODE_OPTIONS="--max-old-space-size=4096"
- 修改位置如下:
NODE_OPTIONS="--no-warnings --max-old-space-size=4096 --max-http-header-size=65536 ${NODE_OPTIONS}" NODE_ENV=production exec "${NODE}" "${DIR}/src/cli" ${@}
注意: NODE_OPTIONS 后面不能有空格。
参考文章:
- https://www.cnblogs.com/oldboyooxx/p/14276483.html
- https://blog.csdn.net/yiyueqinghui/article/details/105834233
- https://blog.csdn.net/qq_40907977/article/details/104646947