catalina.sh 中设置的 JAVA_OPTS 不适用于 TOMCAT 私有实例

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24723854/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 14:28:17  来源:igfitidea点击:

JAVA_OPTS set in catalina.sh not working for TOMCAT private instance

javatomcatubuntucatalinajava-opts

提问by user20507

I have placed JVM options via JAVA_OPTS in catalina.sh in the catalina base. However, the system doesn't pick those options--I am trying to pass profiling information to set paths for project properties and logging files. I have to set the options in setenv.sh in the private instance's bin. Even the echo command that I put in catalina.sh to view the JAVA_OPTS doesn't get printed-defaults like CATALINA_BASE,etc. do get printed. Is catalina.sh even being processed?

我已经通过 JAVA_OPTS 在 catalina 库中的 catalina.sh 中放置了 JVM 选项。但是,系统不会选择这些选项——我试图传递分析信息来设置项目属性和日志文件的路径。我必须在私有实例的 bin 中的 setenv.sh 中设置选项。即使我放在 catalina.sh 中查看 JAVA_OPTS 的 echo 命令也没有像 CATALINA_BASE 等那样打印默认值。打印出来。甚至正在处理 catalina.sh 吗?

At the end of the day, my system works fine with setenv.sh. I am curious as to why JAVA_OPTS are not being picked up from catalina.sh.

归根结底,我的系统在 setenv.sh 上运行良好。我很好奇为什么没有从 catalina.sh 获取 JAVA_OPTS。

I am using Ubuntu 12.04 with TOMCAT 7 installed and JDK 1.7.

我正在使用安装了 TOMCAT 7 和 JDK 1.7 的 Ubuntu 12.04。

Thanks

谢谢

回答by konrad

please edit: /etc/default/tomcat7or /etc/default/{user_who_runs_tomcat}

请编辑:/etc/default/tomcat7/etc/default/{user_who_runs_tomcat}

e.g.:

例如:

*JAVA_OPTS="-Djava.awt.headless=true -Xmx2G -XX:+UseConcMarkSweepGC -server -XX:MaxPermSize=384m"*

回答by Olaf Kock

catalina.shhas a lot of conditionals - it happened to me more than once that I edited the wrong position, or one that was overwritten later in that file. setenv.shworks fine, and that's exactly what it's there for: Imagine you're installing a tomcat update - this will overwrite your catalina.sh. However, tomcat never comes with setenv.sh, thus it won't overwrite your changes.

catalina.sh有很多条件 - 我不止一次地编辑了错误的位置,或者后来在该文件中覆盖的位置。setenv.sh工作正常,这正是它的用途:想象一下您正在安装 tomcat 更新 - 这将覆盖您的catalina.sh. 但是,tomcat 永远不会附带setenv.sh,因此它不会覆盖您的更改。

Further, you might want to define CATALINA_OPTSinstead of JAVA_OPTS: Those are the options that are used to start tomcat. If part of your configuration is JAVA_OPTS="-Xmx16G -Xms16G", you'd allocate 16G heap space when you try to shut down tomcat: The shutdown process spawns a JVM with the JAVA_OPTSparameters as well. Only the startup process spawns with the CATALINA_OPTSenvironment (in addition to JAVA_OPTS), thus that's most likely what you want to configure/tune, otherwise you risk not being able to stop tomcat due to ridiculous memory requirements of shutdown.sh.

此外,您可能想要定义CATALINA_OPTS而不是JAVA_OPTS:这些是用于启动 tomcat 的选项。如果您的配置的一部分是JAVA_OPTS="-Xmx16G -Xms16G",那么当您尝试关闭 tomcat 时,您将分配 16G 堆空间:关闭过程JAVA_OPTS也会生成一个带有参数的 JVM 。只有启动过程随CATALINA_OPTS环境生成(除了JAVA_OPTS),因此这很可能是您想要配置/调整的内容,否则您可能会因 shutdown.sh 的荒谬内存要求而无法停止 tomcat。

回答by cst1992

You are not supposed to edit the catalina.sh file - it states so in that file. Instead, to setyour environmental variables, create a setenv.shfile in the same directory where catalina.sh is (called CATALINA_BASE/bin) and write your code in it.

您不应该编辑 catalina.sh 文件 - 它在该文件中如此说明。相反,要设置您的ENVironmental变量,创建一个setenv.sh在catalina.sh是同一个目录(称为CATALINA_BASE /箱)文件,并在编写代码。

I had to set the JAVA_OPTSvariable myself, and I created the bin/setenv.shfile, set it to executable chmod +x bin/setenv.shand wrote in it:

我必须自己设置JAVA_OPTS变量,然后创建bin/setenv.sh文件,将其设置为可执行文件chmod +x bin/setenv.sh并在其中写入:

JAVA_OPTS="$JAVA_OPTS -Xms128m -Xmx512m -server"

JAVA_OPTS="$JAVA_OPTS -Xms128m -Xmx512m -server"

which set my initial allocated memory to 128 and max memory to 512 MB. And it was working.

这将我的初始分配内存设置为 128,最大内存设置为 512 MB。它正在发挥作用。