Linux Tomcat 7:如何正确设置初始堆大小?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6897476/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Tomcat 7: How to set initial heap size correctly?
提问by GLA
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?
这些选项有什么问题?
采纳答案by Joachim Sauer
You must not use =
. Simply use this:
您不得使用=
. 只需使用这个:
export CATALINA_OPTS="-Xms512M -Xmx1024M"
回答by Phat H. VU
You might no need to having export, just add this line in catalina.sh:
您可能不需要export,只需在catalina.sh 中添加这一行:
CATALINA_OPTS="-Xms512M -Xmx1024M"
回答by MeJ
Use following command to increase java heap size for tomcat7 (linux distributions) correctly:
使用以下命令正确增加 tomcat7(linux 发行版)的 java 堆大小:
echo 'export CATALINA_OPTS="-Xms512M -Xmx1024M"' > /usr/share/tomcat7/bin/setenv.sh
回答by mentallurg
setenv.sh is better, because you can easily port such configuration from one machine to another, or from one Tomcat version to another. catalina.sh changes from one version of Tomcat to another. But you can keep your setenv.sh unchanged with any version of Tomcat.
setenv.sh 更好,因为您可以轻松地将此类配置从一台机器移植到另一台机器,或者从一个 Tomcat 版本移植到另一个。catalina.sh 从一个版本的 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. 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.
另一个优点是,如果将其添加到备份或版本控制系统中,则可以更轻松地跟踪更改的历史记录。如果您查看 setenv.sh 沿历史记录的更改方式,您将只会看到您自己的更改。而如果您使用 catalina.sh,您将始终不仅会看到您的更改,还会看到随 Tomcat 的每个更新版本而带来的更改。
回答by Roberto C. Rodriguez-Hidalgo
Take care with change in Debian distributions! I tried to change CATALINA_OPTS
in my Debian 7 and the results where that tomcat didn't start anymore. Thus I solved this issue by changing the property JAVA_OPTS
in place of CATALINA_OPTS
, like this
注意 Debian 发行版的变化!我尝试CATALINA_OPTS
在我的 Debian 7 中进行更改,结果该 tomcat 不再启动。因此,我通过更改属性来解决这个问题JAVA_OPTS
的地方CATALINA_OPTS
,像这样
export JAVA_OPTS="-Xms512M -Xmx1024M"
回答by APA
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
回答by Musa
Go to "Tomcat Directory"/bin directory
转到“Tomcat目录”/bin目录
if Linux then create setenv.sh else if Windows then create setenv.bat
如果 Linux 则创建 setenv.sh 否则如果 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.
在此之后使用新参数重新启动 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/
回答by mdev
It works even without using 'export' keyword. This is what i have in my setenv.sh (/usr/share/tomcat7/bin/setenv.sh) and it works.
即使不使用“export”关键字,它也能工作。这是我在我的 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"
回答by Dinesh Rajendran
After spending good time time on this . I found this is the what the setenv.bat must look like . No " characters are accepted in batch file.
在此度过美好时光之后。我发现这就是 setenv.bat 的样子。批处理文件中不接受 " 字符。
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%"
回声你好“%CATALINA_OPTS%”
回答by Birendra Rawat
If it's not work in your centos 7 machine "export CATALINA_OPTS="-Xms512M -Xmx1024M"" then you can change heap memory from vi /etc/systemd/system/tomcat.service file then this value shown in your tomcat by help of ps -ef|grep tomcat.
如果它在您的 centos 7 机器上不起作用“export CATALINA_OPTS="-Xms512M -Xmx1024M"” 那么您可以从 vi /etc/systemd/system/tomcat.service 文件更改堆内存,然后通过 ps 的帮助在您的 tomcat 中显示此值-ef|grep Tomcat。