Configure and use logrotate
Logrotate 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.
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.
Locate logrotate files
Logrotate files for different servers are stored in the /opt/bitnami/config/logrotate/logrotate.d and /etc/logrotate.d directories. For instance, to configure the Apache Logrotate file, edit the file at /opt/bitnami/config/logrotate/logrotate.d/apache. Use the man logrotate command for information on all available options.
By default, Logrotate uses the “copytruncate” approach so it is not necessary to restart the servers.
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. To record every request, use a different approach for rotating the logs.
NOTE: We are in the process of modifying the file structure and configuration for many Bitnami stacks. On account of these changes, the file paths stated in this guide may change depending on whether your Bitnami stack uses native Linux system packages (Approach A), or if it is a self-contained installation (Approach B). To identify your Bitnami installation type and what approach to follow, run the command below:
$ test ! -f "/opt/bitnami/common/bin/openssl" && echo "Approach A: Using system packages." || echo "Approach B: Self-contained installation."
The output of the command indicates which approach (A or B) is used by the installation, and will allow you to identify the paths, configuration and commands to use in this guide. Refer to the FAQ for more information on these changes.
Approach A: Bitnami installations using system packages
The command below displays the current Logrotate configuration for the Apache server:
$ sudo logrotate -d /etc/logrotate.d/apache rotating pattern: /opt/bitnami/apache/logs/*log weekly (150 rotations) empty log files are rotated, old logs are removed considering log /opt/bitnami/logs/access_log log does not need rotating considering log /opt/bitnami/apache2/logs/error_log log does not need rotating
To test Logrotate, run the command below and then check the Apache server’s log/ directory which should contain the compressed files with the logs:
$ sudo logrotate -f /etc/logrotate.d/apache $ ls /opt/bitnami/apache/logs access_log access_log-YYYYMMDD.gz error_log error_log-YYYYMMDD.gz
Approach B: Self-contained Bitnami installations
The command below displays the current Logrotate 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
To test Logrotate, run the command below and then check the server’s log/ directories which should contain the compressed files with the logs:
$ sudo logrotate -f /etc/logrotate.d/bitnami.conf