Tomcat


Theory


Context - In a nutshell, a Context is a web application.
<Context docBase="Driver:/locationOfWebApp/webManager" path="WebAppUrl"/>

CATALINA_HOME and CATALINA_BASE


CATALINA_HOME: Represents the root of your Tomcat installation, for example/home/tomcat/apache-tomcat-9.0.10 or C:\Program Files\apache-tomcat-9.0.10.
CATALINA_BASE: Represents the root of a runtime configuration of a specific Tomcat instance. If you want to have multiple Tomcat instances on one machine, use the CATALINA_BASE property.

Contents of CATALINA_BASE



Before you start using CATALINA_BASE, first consider and create the directory tree used by CATALINA_BASE. Note that if you do not create all the recommended directories, Tomcat creates the directories automatically. If it fails to create the necessary directory, for example due to permission issues, Tomcat will either fail to start, or may not function correctly.
Consider the following list of directories:
The bin directory with the setenv.sh, setenv.bat, and tomcat-juli.jar files.
Recommended: No.
Order of lookup: CATALINA_BASE is checked first; fallback is provided to CATALINA_HOME.
The lib directory with further resources to be added on classpath.
Recommended: Yes, if your application depends on external libraries.
Order of lookup: CATALINA_BASE is checked first; CATALINA_HOME is loaded second.
The logs directory for instance-specific log files.
Recommended: Yes.
The webapps directory for automatically loaded web applications.
Recommended: Yes, if you want to deploy applications.
Order of lookup: CATALINA_BASE only.
The work directory that contains temporary working directories for the deployed web applications.
Recommended: Yes.
The temp directory used by the JVM for temporary files.
Recommended: Yes.
Standard DIR layout
.html, .jsp, etc. - The HTML and JSP pages, along with other files that must be visible to the client browser (such as JavaScript, stylesheet files, and images) for your application. In larger applications you may choose to divide these files into a subdirectory hierarchy, but for smaller apps, it is generally much simpler to maintain only a single directory for these files.
/WEB-INF/web.xml - The Web Application Deployment Descriptor for your application. This is an XML file describing the servlets and other components that make up your application, along with any initialization parameters and container-managed security constraints that you want the server to enforce for you. This file is discussed in more detail in the following subsection.
/WEB-INF/classes/- This directory contains any Java class files (and associated resources) required for your application, including both servlet and non-servlet classes, that are not combined into JAR files. If your classes are organized into Java packages, you must reflect this in the directory hierarchy under/WEB-INF/classes/. For example, a Java class named com.mycompany.mypackage.MyServlet would need to be stored in a file named/WEB-INF/classes/com/mycompany/mypackage/MyServlet.class.
/WEB-INF/lib/- This directory contains JAR files that contain Java class files (and associated resources) required for your application, such as third party class libraries or JDBC drivers.

JDBC Pool

<Resource name="jdbc/TestDB"
          auth="Container"
          type="javax.sql.DataSource"
          factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
          testWhileIdle="true"
          testOnBorrow="true"
          testOnReturn="false"
          validationQuery="SELECT 1"
          validationInterval="30000"
          timeBetweenEvictionRunsMillis="30000"
          maxActive="100"
          minIdle="10"
          maxWait="10000"
          initialSize="10"
          removeAbandonedTimeout="60"
          removeAbandoned="true"
          logAbandoned="true"
          minEvictableIdleTimeMillis="30000"
          jmxEnabled="true"
          jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;
            org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"
          username="root"
          password="password"
          driverClassName="com.mysql.jdbc.Driver"
          url="jdbc:mysql://localhost:3306/mysql"/>

LOGGING


Empty catalina.out

cat /dev/null > catalina.out

レコードポリシー

/etc/logrotate.d/tomcat

/var/log/tomcat/catalina.out {   copytruncate   daily   rotate 7   compress   missingok   size 5M  }

/usr/sbin/logrotate /etc/logrotate.conf

説明:


copytruncate:既存のファイルをバックアップして別のファイルに移動し、既存のファイルを削除するオプションです.
day:日付によるログファイルの変換
圧縮:経過したログファイルをgzipに圧縮
Dateext:ループログファイルの日付拡張子
missingok:ログファイルがなくてもエラーはありません
rotate 30:ログファイルを30個保存し、削除またはメールで送信
notifempty:ファイルにコンテンツがない場合、新しいログファイルは作成されません.
postrotate-endscript:ログファイルを処理してコマンドを実行する
size 100 m:サイズが100 mの場合はrotedとなります
extensionext:logrotate実行後、ループ生成されたファイル名の後に拡張子を付ける拡張子を指定します.
create 0664ルートutmp:新しいログファイルを作成するときに、0644権限、ルートユーザー、utmpグループとして作成します.

REF


http://tomcat.apache.org/tomcat-8.5-doc/jdbc-pool.html
https://stackoverflow.com/questions/37094871/how-to-clear-catalina-out-without-disabling-further-logging/37124354
https://www.linux.co.kr/linux/logrotate/page04.htm
https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=sory1008&logNo=221124291927