Configure logrotate
Overview
Aerospike manages log rotations with the Linux logrotate
tool. Most versions of Linux should have logrotate already installed. This page describes how to install logrotate
if necessary.
With journald, you do not need to explicitly setup log rotation as it is implicitly handled by the journaling subsystem when the logs are configured to be output to the console. Refer to the systemd page for more details.
When configured to log to multiple files, it is necessary to use the logrotate sharedscripts directive in order to preserve the content of all the file and prevent a race condition between the different SIGHUP signals. Such race may improperly close log sink file descriptors, which could lead to potential reuse of those file descriptors for client transactions.
Install logrotate binary
For CentOS:
sudo yum install logrotate
For Debian and Ubuntu:
sudo apt-get install logrotate
Configure logrotate policy for Aerospike
If your system is configured with logrotate.d
to manage log rotation, use <logrotate.d>/aerospike
as the filename.
On Aerospike installation, a log rotation policy file is set up at /etc/logrotate.d/aerospike
that specifies:
- The log should be rotated every day
- Compress the old log files
- Retain files for 90 days
- Use date as the suffix
- Use sharedscripts when rotating multiple files.
Logrotate policy
If there are no pid files (on systemd based installations, if logrotate is preferred over journald), the postrotate kill -HUP
command should use either pidof asd
or pgrep -x asd
.
/var/log/aerospike/aerospike.log {
daily
rotate 90
dateext
compress
olddir /var/log/aerospike/
sharedscripts
postrotate
/bin/kill -HUP `pgrep -x asd`
endscript
}
Logrotate policy with multiple files
Multiple log sync files can be configured to be rotated and use the same logrotate configuration and postrotate script.
/var/log/aerospike/aerospike.log /var/log/aerospike/xdr.log {
daily
rotate 90
dateext
compress
olddir /var/log/aerospike/
sharedscripts
postrotate
/bin/kill -HUP `pgrep -x asd`
endscript
}
When typing the configuration lines above, there is a <tab>
before /bin/kill preceded by 4 spaces of indentation.
Force run a logrotate to test
sudo logrotate -f -v /etc/logrotate.d/aerospike
Example output:
logrotate -f -v /etc/logrotate.d/aerospike
reading config file /etc/logrotate.d/aerospike
olddir is now /var/log/aerospike/
Allocating hash table for state file, size 15360 B
Handling 1 logs
rotating pattern: /var/log/aerospike/aerospike.log forced from command line (90 rotations)
olddir is /var/log/aerospike/, empty log files are rotated, old logs are removed
considering log /var/log/aerospike/aerospike.log
log needs rotating
rotating log /var/log/aerospike/aerospike.log, log->rotateCount is 90
dateext suffix '-20171101'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
glob finding old rotated logs failed
renaming /var/log/aerospike/aerospike.log to /var/log/aerospike//aerospike.log-20171101
running postrotate script
compressing log with: /bin/gzip