简体   繁体   English

Tomcat 7:如何正确设置初始堆大小?

[英]Tomcat 7: How to set initial heap size correctly?

I was trying to adjust initial heap size of a tomcat 7 (CentOS, java -version: 1.6.0_25-b06) instance by adding the following line to catalina.sh: 我试图通过将以下行添加到catalina.sh来调整tomcat 7(CentOS,java -version:1.6.0_25-b06)实例的初始堆大小:

export CATALINA_OPTS="-Xms=512M -Xmx=1024M"

Starting up tomcat fails and logs the following message to catalina.out: 启动tomcat失败并将以下消息记录到catalina.out:

Invalid initial heap size: -Xms=512m
Could not create the Java virtual machine.

What is wrong with these options? 这些选项有什么问题?

You must not use = . 你不能使用= Simply use this: 只需使用:

export CATALINA_OPTS="-Xms512M -Xmx1024M"

使用以下命令正确增加tomcat7(linux发行版)的java堆大小:

echo 'export CATALINA_OPTS="-Xms512M -Xmx1024M"' > /usr/share/tomcat7/bin/setenv.sh

您可能不需要导出 ,只需在catalina.sh中添加以下行:

CATALINA_OPTS="-Xms512M -Xmx1024M"

setenv.sh is better, because you can easily port such configuration from one machine to another, or from one Tomcat version to another. setenv.sh更好,因为您可以轻松地将此类配置从一台机器移植到另一台机器,或从一个Tomcat版本移植到另一台机器。 catalina.sh changes from one version of Tomcat to another. catalina.sh从一个版本的Tomcat变为另一个版本。 But you can keep your setenv.sh unchanged with any version of Tomcat. 但您可以使用任何版本的Tomcat保持setenv.sh不变。

Another advantage is, that it is easier to track the history of your changes if you add it to your backup or versioning system. 另一个优点是,如果将更改添加到备份或版本控制系统,则更容易跟踪更改的历史记录。 If you look how you setenv.sh changes along the history, you will see only your own changes. 如果您看看setenv.sh在历史记录中的变化,您将只看到自己的更改。 Whereas if you use catalina.sh, you will always see not only your changes, but also changes that came with each newer version of the Tomcat. 然而,如果您使用catalina.sh,您将不仅会看到您的更改,还会看到每个较新版本的Tomcat附带的更改。

Take care with change in Debian distributions! 注意Debian发行版的变化! I tried to change CATALINA_OPTS in my Debian 7 and the results where that tomcat didn't start anymore. 我试图在我的Debian 7中更改CATALINA_OPTS以及tomcat不再启动的结果。 Thus I solved this issue by changing the property JAVA_OPTS in place of CATALINA_OPTS , like this 因此,我通过更改属性JAVA_OPTS代替CATALINA_OPTS解决了这个问题,就像这样

export JAVA_OPTS="-Xms512M -Xmx1024M"

Just came across this and I've implemented Nathan's solution: 刚刚遇到这个,我已经实现了Nathan的解决方案:

add the line (changing the values as required): 添加行(根据需要更改值):

export JAVA_OPTS="-Xms512M -Xmx1024M"

to /usr/share/tomcat7/bin/setenv.sh 到/usr/share/tomcat7/bin/setenv.sh

If that file doesn't exists then create it and 如果该文件不存在,则创建它

chown root:root it
chmod 755 it

And then restart tomcat and check it with 然后重启tomcat并检查它

ps aux | grep logging

Which should just pick up the instance and show the java parms 哪个应该只是拿起实例并显示java parms

It works even without using 'export' keyword. 它甚至不使用'export'关键字也可以工作。 This is what i have in my setenv.sh (/usr/share/tomcat7/bin/setenv.sh) and it works. 这就是我在setenv.sh(/usr/share/tomcat7/bin/setenv.sh)中的功能。

OS : 14.04.1-Ubuntu Server version: Apache Tomcat/7.0.52 (Ubuntu) Server built: Jun 30 2016 01:59:37 Server number: 7.0.52.0 操作系统:14.04.1-Ubuntu服务器版本:Apache Tomcat / 7.0.52(Ubuntu)服务器内置:2016年6月30日01:59:37服务器编号:7.0.52.0

JAVA_OPTS="-Dorg.apache.catalina.security.SecurityListener.UMASK=`umask` -server -Xms6G -Xmx6G -Xmn1400m -XX:HeapDumpPath=/Some/logs/ -XX:+HeapDumpOnOutOfMemoryError -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:SurvivorRatio=8 -XX:+UseCompressedOops -Dcom.sun.management.jmxremote.port=8181 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"
JAVA_OPTS="$JAVA_OPTS -Dserver.name=$HOSTNAME"

After spending good time time on this . 花了很多时间在这之后。 I found this is the what the setenv.bat must look like . 我发现这就是setenv.bat必须看起来的样子。 No " characters are accepted in batch file. 没有“批处理文件中接受的字符。

set CATALINA_OPTS=-Xms512m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=768m 设置CATALINA_OPTS = -Xms512m -Xmx1024m -XX:PermSize = 128m -XX:MaxPermSize = 768m

echo hello "%CATALINA_OPTS%" echo hello“%CATALINA_OPTS%”

Go to "Tomcat Directory"/bin directory 转到“Tomcat目录”/ bin目录

if Linux then create setenv.sh else if Windows then create setenv.bat 如果Linux然后创建setenv.sh else如果Windows然后创建setenv.bat

content of setenv.* file : setenv。*文件的内容:

export CATALINA_OPTS="$CATALINA_OPTS -Xms512m"
export CATALINA_OPTS="$CATALINA_OPTS -Xmx8192m"
export CATALINA_OPTS="$CATALINA_OPTS -XX:MaxPermSize=256m"

after this restart tomcat with new params. 在此之后用新的params重新启动tomcat。

explanation and full information is here 解释和完整信息在这里

http://crunchify.com/how-to-change-jvm-heap-setting-xms-xmx-of-tomcat/ http://crunchify.com/how-to-change-jvm-heap-setting-xms-xmx-of-tomcat/

如果它在你的centos 7机器上没有工作“export CATALINA_OPTS =” - Xms512M -Xmx1024M“”那么你可以从vi /etc/systemd/system/tomcat.service文件更改堆内存然后通过ps的帮助在tomcat中显示这个值-ef | grep tomcat。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM