复制代码

为懒人提供无限可能,生命不息,code不止

人类感性的情绪,让我们知难行难
我思故我在
日拱一卒,功不唐捐
  • 首页
  • 前端
  • 后台
  • 数据库
  • 运维
  • 资源下载
  • 实用工具
  • 接口文档工具
  • 登录
  • 注册

tomcat

【原创】tomcat 宕机 Cannot allocate memory

作者: whooyun发表于: 2017-12-18 16:44

tomcat8.5宕机问题记录:

以下为catalina.out的日志

Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_mem



Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000006c0000000, 4160749568, 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 4160749568 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /usr/local/apache-tomcat-8.5.15/bin/hs_err_pid4923.log

以下为查看到的日志信息

Memory: 4k page, physical 1019984k(49116k free), swap 0k(0k free)

vm_info: Java HotSpot(TM) 64-Bit Server VM (25.131-b11) for linux-amd64 JRE (1.8.0_131-b11), built on Mar 15 2017 01:23:40 by "java_re" with gcc 4.3.0 20080428 (Red Hat 4.3.0-8)

time: Mon Dec 18 14:00:21 2017
elapsed time: 97 seconds (0d 0h 1m 37s)
看到红字的swap等于0k,想必大家都知道了,内存不足。没其它办法,只能在catalina.sh中调整内存了。

解决方案:
修改bin目录下的Catalina.sh
JAVA_OPTS="$JAVA_OPTS -Xms512m -Xmx1G -XX:MaxNewSize=128m -Djava.awt.headless=true -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"

增加变量,大小根据你自己的需要微调就好(记得先看下机器物理内存是否够)
CATALINA_OPTS="$CATALINA_OPTS -server -Xms1G -Xmx1G -XX:+UseG1GC"