Tomcat负载均衡、调优核心应用进阶学习笔记(四):Tomcat调优和Tomcat监控(差评)
作者:互联网
文章目录
tomcat调优
vi catalina.sh
# -----------------------------------------------------------------------------
# Control Script for the CATALINA Server
#
# Environment Variable Prerequisites
#
# Do not set the variables in this script. Instead put them into a script
# setenv.sh in CATALINA_BASE/bin to keep your customizations separate.
#
# CATALINA_HOME May point at your Catalina "build" directory.
#
# CATALINA_BASE (Optional) Base directory for resolving dynamic portions
# of a Catalina installation. If not present, resolves to
# the same directory that CATALINA_HOME points to.
#
# CATALINA_OUT (Optional) Full path to a file where stdout and stderr
# will be redirected.
# Default is $CATALINA_BASE/logs/catalina.out
#
# CATALINA_OPTS (Optional) Java runtime options used when the "start",
# "run" or "debug" command is executed.
# Include here and not in JAVA_OPTS all options, that should
# only be used by Tomcat itself, not by the stop process,
# the version command etc.
# Examples are heap size, GC logging, JMX ports etc.
#
# CATALINA_TMPDIR (Optional) Directory path location of temporary directory
# the JVM should use (java.io.tmpdir). Defaults to
# $CATALINA_BASE/temp.
#
# JAVA_HOME Must point at your Java Development Kit installation.
# Required to run the with the "debug" argument.
#
# JRE_HOME Must point at your Java Runtime installation.
# Defaults to JAVA_HOME if empty. If JRE_HOME and JAVA_HOME
# are both set, JRE_HOME is used.
#
# JAVA_OPTS (Optional) Java runtime options used when any command
# is executed.
# Include here and not in CATALINA_OPTS all options, that
# should be used by Tomcat and also by the stop process,
# the version command etc.
# Most options should go into CATALINA_OPTS.
#
# JAVA_ENDORSED_DIRS (Optional) Lists of of colon separated directories
# containing some jars in order to allow replacement of APIs
# created outside of the JCP (i.e. DOM and SAX from W3C).
# It can also be used to update the XML parser implementation.
# Note that Java 9 no longer supports this feature.
# Defaults to $CATALINA_HOME/endorsed.
#
# JPDA_TRANSPORT (Optional) JPDA transport used when the "jpda start"
# command is executed. The default is "dt_socket".
#
catalina这个脚本会读取很多参数:
-
CATALINA_HOME tomcat的安装目录
-
CATALINA_BASE tomcat的工作目录
如果我们想要运行Tomcat的 多个实例,但是不想安装多个Tomcat软件副本。那么我们可以配置多个工作目录,每个运行实例独占一个工作目录,但是共享同一个安装目录。 -
CATALINA_OPTS catalina运行时的参数 heap size 、GC logging、JMX ports etc
-
JAVA_OPTS java运行时的参数 heap size 、GC logging、JMX ports etc
两者的区别:
在Tomcat的catalina.sh文件中的启停server脚本中都应用到了两个变量: CATALINA_OPTS和JAVA_OPTS。用于保存Tomcat运行所需的各种参数。
他们在文件中的注释如下:
(可选)Java 执行"start","stop"或"run"命令时用到的运行时参数; [JAVA_OPTS]
(可选)Java 执行"start"或"run"命令时用到的运行时参数; [CATALINA_OPTS]
那么,为什么有两个不同的变量?他们有什么区别?
首先,定义在这两个变量中的参数都会被传递到启动Tomcat的命令:“start"和"run”,只有定义在JAVA_OPTS中的参数会被传递到"stop"命令。
所以将参数定义到哪个变量中并不影响Tomcat的启动和运行,而只影响到了Tomcat的运行结束。
第二种区别更加微妙。其他应用程序也可以使用JAVA_OPTS,但Tomcat只会用到CATALINA_OPTS。所以如果你只使用了Tomcat,在设置环境变量时,你最好使用CATALINA_OPTS,而如果你同时也用到了其他java应用程序,如JBoss,在设置环境变量时你应该使用JAVA_OPTS。
原文:https://www.cnblogs.com/yaowen/p/9722241.html
if $cygwin; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$JRE_HOME" ] && JRE_HOME=`cygpath --unix "$JRE_HOME"`
[ -n "$CATALINA_HOME" ] && CATALINA_HOME=`cygpath --unix "$CATALINA_HOME"`
[ -n "$CATALINA_BASE" ] && CATALINA_BASE=`cygpath --unix "$CATALINA_BASE"`
[ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi
发现脚本是可以自动获取这些值的
exec "$_RUNJDB" "$LOGGING_CONFIG" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \
-D$ENDORSED_PROP="$JAVA_ENDORSED_DIRS" \
-classpath "$CLASSPATH" \
-sourcepath "$CATALINA_HOME"/../../java \
-Djava.security.manager \
-Djava.security.policy=="$CATALINA_BASE"/conf/catalina.policy \
-Dcatalina.base="$CATALINA_BASE" \
-Dcatalina.home="$CATALINA_HOME" \
-Djava.io.tmpdir="$CATALINA_TMPDIR" \
org.apache.catalina.startup.Bootstrap "$@" start
根据这些参数$JAVA_OPTS $CATALINA_OPTS 来启动tomcat
所以只需要在前面添加:
例如:
//其他的参数也同理
export JAVA_OPTS="-Xms:100m -Xmx:2048m"
后面会自动读取
tomcat监控
jps
xxxx Bootstrap
//1s打印一次
jstat -gc xxxx 1s
标签:CATALINA,JAVA,Tomcat,差评,BASE,调优,HOME,OPTS 来源: https://blog.csdn.net/dataiyangu/article/details/89076245