Tomcat常用配置

1、部署war包的默认位置

conf/server.xml中修改docBase目录


    
    

2、存放日志的默认位置

2.1 accessLog日志

同样也是在conf/server.xml中修改Host节点


        
    

2.2 catalina.out日志

bin/catalina.sh中的官方注释

#   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_OUT    (Optional) Full path to a file where stdout and stderr
#                   will be redirected.
#                   Default is $CATALINA_BASE/logs/catalina.out

故只需在bin/目录下创建setenv.sh文件并定义CATALINA_OUT变量即可

setenv.sh:
...
CATALINA_OUT=/apps/logs/myapp/catalina.out
2.2 其他日志

编辑conf/logging.propertyxxx.directory的值为目标目录即可

# logging.base = ${catalina.base}/logs

1catalina.org.apache.juli.AsyncFileHandler.level = FINE
1catalina.org.apache.juli.AsyncFileHandler.directory = /apps/logs/myapp
1catalina.org.apache.juli.AsyncFileHandler.prefix = catalina.

2localhost.org.apache.juli.AsyncFileHandler.level = FINE
2localhost.org.apache.juli.AsyncFileHandler.directory = /apps/logs/myapp
2localhost.org.apache.juli.AsyncFileHandler.prefix = localhost.

3manager.org.apache.juli.AsyncFileHandler.level = FINE
3manager.org.apache.juli.AsyncFileHandler.directory = /apps/logs/myapp
3manager.org.apache.juli.AsyncFileHandler.prefix = manager.

4host-manager.org.apache.juli.AsyncFileHandler.level = FINE
4host-manager.org.apache.juli.AsyncFileHandler.directory = /apps/logs/myapp
4host-manager.org.apache.juli.AsyncFileHandler.prefix = host-manager.

3、tomcat日志乱码

linux中需要为tomcat指定文件编码为utf-8
bin/catalina.sh中的官方注释

#   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.

同样自定义的变量放在bin/setenv.sh中即可

bin/setenv.sh:
...
JAVA_OPTS="$JAVA_OPTS -Dfile.encoding=utf-8"

你可能感兴趣的:(Tomcat常用配置)