Set Java / Tomcat heap size (Xmx) without modifying catalina.sh

送分小仙女□ 提交于 2020-01-06 06:56:55

问题


Most people seem to suggest setting the Java/Tomcat heap memory size for Tomcat6 by editing the /usr/share/tomcat6/bin/catalina.sh file, and adding something like:

# Set specific memory requirements for Tomcat6 (for server with ~512MB RAM).
CATALINA_OPTS="$CATALINA_OPTS -server -Xms128m -Xmx256m"

I am trying to build an Ansible playbook to configure a Tomcat-based server on Ubuntu, and it doesn't seem to me like having an entire custom catalina.sh file would be ideal—is there some other configuration file or local settings file/system used by Tomcat and/or Java to get the Xms and Xmx values?

Or... do most people use a custom catalina.sh file, and I'm just making a mountain out of a molehill?


回答1:


If you are launching via the "catalina.sh" script (directly or indirectly), then you have two options:

  • Modify ("hack"!) the script as suggested.

  • Find where the script is being invoked, and ensuring that CATALINA_OPTS is set to include the "-mx" option ... and exported ...

The latter is probably "cleaner", but there is no simple, one-size-fits-all way to get that variable set and exported. If you are launching Tomcat as a service, it depends on how your distro has wrapped Tomcat.

[Am I] just making a mountain out of a molehill?

It depends. If you are just doing this on a non-production platform, then Yes. If you are trying to build a production system that will continue to work over package upgrades and upgrades in your distro version, then No. (In the latter case, it is worth figuring out the best way to do this for your particular distro.)




回答2:


Tomcat reads setenv.sh from bin directory for these extra settings. setenv.sh doesn't come with tomcat but you can create one for you and set CATALINA_OPTS in that.

Using JAVA_OPTS to set memory is not suggested by Tomcat because it applies to both startup and shutdown.



来源:https://stackoverflow.com/questions/20915745/set-java-tomcat-heap-size-xmx-without-modifying-catalina-sh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!