Logrotate

    Logrote  is designed to ease administration of systems that generate large numbers of log files. It allows automatic rotation, compression, removal, and mailing of log files.

    How to enable logrotate?

    Recent versions of BitNami stacks ship logrotate configuration files for all servers. If you are using a Virtual Machine or Cloud Image, logrotate is already configured and enabled by default. Note the following is only valid for Linux platforms.

    Check the logrotate files in the installdir/config folder. If you are using a Virtual Machine or a Cloud Image, installdir is the /opt/bitnami folder.

    You can enable logrotate in your machine creating a symbolic link. For example, in Ubuntu:

    $ sudo ln -s installdir/config/logrotate/bitnami.conf /etc/logrotate.d/bitnami.conf

     

    How to check if logrotate is working properly?

    It is possible to check your current configuration. The command below shows the current configuration for your servers:

    $ sudo logrotate -d /etc/logrotate.d/bitnami.conf
    
    rotating pattern: /opt/bitnami/apache2/logs/*_log  weekly (150 rotations)
    empty log files are rotated, old logs are removed
    considering log /opt/bitnami/apache2/logs/access_log
      log does not need rotating
    considering log /opt/bitnami/apache2/logs/error_log
      log does not need rotating

    Also it is possible to run a logrotate test:

    $ sudo logrotate -f /etc/logrotate.d/bitnami.conf

    Then check the server's log folders, you will find the compressed files with the logs:

    access_log  access_log-20130711.gz  error_log  error_log-20130711.gz

     

    How to configure logrotate for each server?

    Log rotate files for the different servers are in the installdir/config/logrotate/logrotate.d folder.  By default, logrotate configuration uses the "copytruncate" approach so it is not necessary to restart the servers. For instance, Apache logrotate file:

    installdir/config/logrotate/logrotate.d/apache

    installdir/opt/bitnami/apache2/logs/*_log {
      weekly
      rotate 150
      dateext
      compress
      copytruncate
      missingok
    }

    In this file you can change the log rotate configuration. You can check "man logrotate" to know all the options that you can configure.

    IMPORTANT: The "copytruncate" approach truncates the original log file to zero size in place after creating a copy, instead of moving the old log file and optionally creating a new one. There is a very small time slice between copying the file and truncating it, so some logging data might be lost. If you want to record every request, you can use a different approach for rotating the logs.

    Tag page (Edit tags)
    • No tags
    Page statistics
    7602 view(s), 6 edit(s) and 2851 character(s)

    Comments

    You must login to post a comment.

    Attach file

    Attachments