统一tomcat的程序包路径,日志路径,自定义变量,JAVA启动项的配置文件示例

  1. 云栖社区>
  2. 博客>
  3. 正文

统一tomcat的程序包路径,日志路径,自定义变量,JAVA启动项的配置文件示例

天飞 2018-06-25 17:17:17 浏览1651
展开阅读全文

在企业环境中,将tomcat里的日志和程序包统一到不同的路径,

自定义全局变量,自定义JAVA_OPTS都是很常见的操作。

现将相关文件作一示例,

以后可照猫画虎了。

(有时,tomcat日志的时间不对,系统的时间是对的,这里就要用GMT+8参数)



bin/setenv.sh



CLASSPATH=$CLASSPATH:/xxx/webconfigs
LOG_DIR="/xxx/weblogs/${MY_POD_NAMESPACE}_${MY_POD_NAME}"
JAVA_OPTS="$JAVA_OPTS -Duser.timezone=GMT+08"
JAVA_OPTS="$JAVA_OPTS -Dlog.home=${LOG_DIR}"
JAVA_OPTS="$JAVA_OPTS -Dxxx.log=${LOG_DIR}"
JAVA_OPTS="$JAVA_OPTS -Xms4096m -Xmx6144m -XX:MaxNewSize=512m -XX:MaxPermSize=512m"
JAVA_OPTS="$JAVA_OPTS -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=85 -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps"
JAVA_OPTS="$JAVA_OPTS -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${LOG_DIR}  -verbose:gc -Xloggc:${LOG_DIR}/gc.log"



conf/server.xml



<Server port="59076" shutdown="SHUTDOWN">
    <Listener className="org.apache.catalina.core.AprLifecycleListener" />
    <!--Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" /-->
    <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
    <Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>

    <GlobalNamingResources>
    <!-- Used by Manager webapp -->
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
       description="User database that can be updated and saved"
           factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
          pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>

  <Service name="Catalina">
    <Connector port="8080" protocol="HTTP/1.1" maxThreads="150" minSpareThreads="25"
               enableLookups="false" redirectPort="8443" acceptCount="200"
               connectionTimeout="40000" 
               disableUploadTimeout="false"/>

    <!-- This is here for compatibility only, not required -->
    <!-- <Connector port="59009" protocol="AJP/1.3" /> -->

    <Engine name="Catalina" defaultHost="localhost">
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
             resourceName="UserDatabase" />
      <Host name="localhost" appBase="/xxx/webapps" unpackWARs="true">
           <Valve className="org.apache.catalina.valves.AccessLogValve" rotatable="true"
                            directory="${xxx.log}"  prefix="localhost_access.log"
                            pattern="%h %{X-FORWARDED-FOR}i %l %u %t %r %s %b  %q %{User-Agent}i %T %D" resolveHosts="false"/>
      </Host>
    </Engine>
 </Service>
</Server>


conf/logging.properties



# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

handlers = 1catalina.org.apache.juli.AsyncFileHandler, 2localhost.org.apache.juli.AsyncFileHandler, 3manager.org.apache.juli.AsyncFileHandler, 4host-manager.org.apache.juli.AsyncFileHandler, java.util.logging.ConsoleHandler

.handlers = 1catalina.org.apache.juli.AsyncFileHandler, java.util.logging.ConsoleHandler

############################################################
# Handler specific properties.
# Describes specific configuration info for Handlers.
############################################################

1catalina.org.apache.juli.AsyncFileHandler.level = FINE
1catalina.org.apache.juli.AsyncFileHandler.directory = ${xxx.log}
1catalina.org.apache.juli.AsyncFileHandler.prefix = catalina.

2localhost.org.apache.juli.AsyncFileHandler.level = FINE
2localhost.org.apache.juli.AsyncFileHandler.directory = ${xxx.log}
2localhost.org.apache.juli.AsyncFileHandler.prefix = localhost.

3manager.org.apache.juli.AsyncFileHandler.level = FINE
3manager.org.apache.juli.AsyncFileHandler.directory = ${xxx.log}
3manager.org.apache.juli.AsyncFileHandler.prefix = manager.

4host-manager.org.apache.juli.AsyncFileHandler.level = FINE
4host-manager.org.apache.juli.AsyncFileHandler.directory = ${xxx.log}
4host-manager.org.apache.juli.AsyncFileHandler.prefix = host-manager.

java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = org.apache.juli.OneLineFormatter


############################################################
# Facility specific properties.
# Provides extra control for each logger.
############################################################

org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 2localhost.org.apache.juli.AsyncFileHandler

org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers = 3manager.org.apache.juli.AsyncFileHandler

org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].handlers = 4host-manager.org.apache.juli.AsyncFileHandler

# For example, set the org.apache.catalina.util.LifecycleBase logger to log
# each component that extends LifecycleBase changing state:
#org.apache.catalina.util.LifecycleBase.level = FINE

# To see debug messages in TldLocationsCache, uncomment the following line:
#org.apache.jasper.compiler.TldLocationsCache.level = FINE

# To see debug messages for HTTP/2 handling, uncomment the following line:
#org.apache.coyote.http2.level = FINE

# To see debug messages for WebSocket handling, uncomment the following line:
#org.apache.tomcat.websocket.level = FINE


网友评论

登录后评论
0/500
评论
天飞
+ 关注