Bitnami Tomcat Stack の Apache と Tomcat のロギングとログローテーションの設定方法です。
- Debian wheezy 7.11, jessie 8.5
- tomcatstack-7.0.64-0-linux-x64
アパッチのログ出力内容をカスタマイズします。
$ sudo vi /opt/tomcatstack-7.0.64-0/apache2/conf/httpd.conf
<IfModule log_config_module>
#
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
#
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
# You need to enable mod_logio.c to use %I and %O
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
# Custom log format
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{User-Agent}i\"" custom
# Exclude unnecessary request information
SetEnvIf Request_URI "\.(gif|jpg|jpeg|png|ico|js|css|woff|ttf)$" nolog
#
# The location and format of the access logfile (Common Logfile Format).
# If you do not define any access logfiles within a <VirtualHost>
# container, they will be logged here. Contrariwise, if you *do*
# define per-<VirtualHost> access logfiles, transactions will be
# logged therein and *not* in this file.
#
#CustomLog "logs/access_log" common
#
# If you prefer a logfile with access, agent, and referer information
# (Combined Logfile Format) you can use the following directive.
#
#CustomLog "logs/access_log" combined
# Logged custom format and env
CustomLog "logs/access_log" custom env=!nolog
</IfModule>
設定ファイルに記述ミスがないかチェックします。
$ sudo /opt/tomcatstack-7.0.64-0/apache2/bin/apachectl -t
Syntax OK
設定内容を反映します。
sudo /opt/tomcatstack-7.0.64-0/apache2/bin/apachectl graceful
logrotate を使用するため Tomcat 自身のログローテーション設定を無効化します。
$ sudo vi /opt/tomcatstack-7.0.64-0/apache-tomcat/conf/server.xml
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" rotatable="false" prefix="localhost_access" suffix=".log" pattern="%h %l %u %t "%r" %s %b"/>
Tomcat を再起動します。
sudo /opt/tomcatstack-7.0.64-0/ctlscript.sh restart tomcat
Bitnami が提供している 3 つの設定ファイル(apache.conf
, mysql.conf
, tomcat.conf
)の設定内容を変更します。
$ sudo vi /opt/tomcatstack-7.0.64-0/config/logrotate/logrotate.d/*.conf
/opt/tomcatstack-7.0.64-0/apache2/logs/*_log {$
weekly
rotate 15
dateext
compress
copytruncate
missingok
}
tomcat.conf
に関しては、状況に応じて処理対象のファイルを変更します。
/opt/tomcatstack-7.0.64-0/apache-tomcat/logs/catalina.out
/opt/tomcatstack-7.0.64-0/apache-tomcat/logs/localhost_access.log {
…
}
シンボリックリンクを作成し、logrotate を有効化します。
sudo ln -s /opt/tomcatstack-7.0.64-0/config/logrotate/bitnami.conf /etc/logrotate.d/bitnami-tomcatstack
設定内容を確認します。
sudo logrotate -d /etc/logrotate.d/bitnami-tomcatstack
必要に応じて強制的に logrotate を実行し、テストを実施します。
sudo logrotate -f /etc/logrotate.d/bitnami-tomcatstack