Linux下Tomcat VM參数改动

Posted mfmdaoyou

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux下Tomcat VM參数改动相关的知识,希望对你有一定的参考价值。

不可行的方法

最初我直接改动catalina.sh, 将JAVA_OPTS变量加上了

-server -Xms1G -Xmx1G -XX:+UserG1GC

最初看起来没啥问题,可是当服务器运行几天后,发现运行shutdown.sh无法关闭tomcat, 错误信息例如以下:

# [email protected]:~/projects/taolijie# cat hs_err_pid5519.log 
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 1073741824 bytes for committing reserved memory.
# Possible reasons:
#   The system is out of physical RAM or swap space
#   In 32 bit mode, the process size limit was hit
# Possible solutions:
#   Reduce memory load on the system
#   Increase physical memory or swap space
#   Check if swap backing store is full
#   Use 64 bit Java on a 64 bit OS
#   Decrease Java heap size (-Xmx/-Xms)
#   Decrease number of Java threads
#   Decrease Java thread stack sizes (-Xss)
#   Set larger code cache with -XX:ReservedCodeCacheSize=
# This output file may be truncated or incomplete.
#
#  Out of Memory Error (os_linux.cpp:2673), pid=5519, tid=3061726064
#
# JRE version:  (8.0_45-b14) (build )
# Java VM: Java HotSpot(TM) Server VM (25.45-b02 mixed mode linux-x86 )
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#

关闭个tomcat要请求1G的内存, 当时服务器就剩下200M内存,所以Out Of Memory了。查看shutdown.sh,发现它事实上还是调用了catalina.sh,仅仅是传入了一个stop參数。而catalina.sh是运行了

org.apache.catalina.startup.Bootstrap stop

来向tomcat发送关闭信息的。因为上面我们设置了JAVA_OPTS使用1G的堆。因此运行该类时JVM会向系统申请1G多的内存,直接导致Out Of Memory。

可行的方法

catalina.sh的第二行加入:

CATALINA_OPTS="$CATALINA_OPTS -server -Xms1G -Xmx1G -XX:+UseG1GC"

这些VM參数就会仅仅应用到catalina而不是全部Tomcat进程。

以上是关于Linux下Tomcat VM參数改动的主要内容,如果未能解决你的问题,请参考以下文章

hi3531 SDK 编译 uboot, 改动PHY地址, 改动 uboot 參数 .

Linux下配置JDK和Tomcat

linux改动登陆主机提示信息

linux下oracle11G DG搭建:环绕备库搭建操作

在Tomcat的安装目录下conf目录下的server.xml文件中增加一个xml代码片段,该代码片段中每个属性的含义与用途

vm12下Centos6的javaweb环境搭建