FreeBSD 10.4 RELEASE - apache24 - ログ設定

 クラウディア
1. 出力先や書式の設定
2. 出力先ディレクトリの作成
3. 再起動
4. ログローテーションの設定

1. 出力先や書式の設定

 ログに関する記述は、前頁でふれましたが /usr/local/etc/apache24/httpd.conf にあります。  デフォルトのままを以下に記載します。

#
# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here.  If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog "/var/log/httpd-error.log"

#
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
LogLevel warn

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

    #
    # 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 "/var/log/httpd-access.log" common

    #
    # If you prefer a logfile with access, agent, and referer information
    # (Combined Logfile Format) you can use the following directive.
    #
    #CustomLog "/var/log/httpd-access.log" combined
</IfModule>
 ログはローテーションさせたい。  また、後述するログ解析で解析できるようにしたいものです。  この理由により、ログの出力先と書式を変更します。  ここでは、以下のように設定するものとします。
ログの出力先			/var/log/www
アクセスログファイル	access.log
エラーログファイル		error.log
 エラーログの記述

ErrorLog "/var/log/httpd-error.log"
  ↓

ErrorLog "/var/log/www/error.log"
 アクセスログの記述

    CustomLog "/var/log/httpd-access.log" common

    #
    # If you prefer a logfile with access, agent, and referer information
    # (Combined Logfile Format) you can use the following directive.
    #
    #CustomLog "/var/log/httpd-access.log" combined
  ↓

    #CustomLog "/var/log/httpd-access.log" common

    #
    # If you prefer a logfile with access, agent, and referer information
    # (Combined Logfile Format) you can use the following directive.
    #
    CustomLog "/var/log/www/access.log" combined

2. 出力先ディレクトリの作成

 出力先ディレクトリを作成して、所有者を変えておきます。

> mkdir /var/log/www
> chown www:www /var/log/www

3. 再起動

 設定ファイルに誤りがないことを確認して、apache を再起動します。

> /usr/local/etc/rc.d/apache24 configtest
Performing sanity check on apache24 configuration:
Syntax OK
> /usr/local/etc/rc.d/apache24 restart
Performing sanity check on apache24 configuration:
Syntax OK
Stopping apache24.
Waiting for PIDS: 1995.
Performing sanity check on apache24 configuration:
Syntax OK
Starting apache24.

4. ログローテーションの設定

 ログローテーションを記述します。

/usr/local/etc/newsyslog.conf.d/apache.conf
 を作成してローテーションを記述します。

# logfilename                    [owner:group]      mode count size when  flags [/pid_file] [sig_num]
/var/log/www/*.log                      644 36     *    $M1D0 BG    /var/run/httpd.pid
 この設定は、毎月1日にローテーションして、3年間(36ヶ月)分を保持する設定です。  間隔やサイズは、方針を決めて調整します。
ハイスピードプラン