Manage log rotation
Aerospike manages log rotation with the Linux logrotate
tool, which is installed by default on most versions of Linux. If your OS does not include logrotate
, this page describes how to install it.
Install the logrotate binary
sudo yum install logrotate
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}
Force run a logrotate to test
sudo logrotate -f -v /etc/logrotate.d/aerospike
Example output:
logrotate -f -v /etc/logrotate.d/aerospikereading config file /etc/logrotate.d/aerospikeolddir 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 removedconsidering log /var/log/aerospike/aerospike.log log needs rotatingrotating log /var/log/aerospike/aerospike.log, log->rotateCount is 90dateext 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 failedrenaming /var/log/aerospike/aerospike.log to /var/log/aerospike//aerospike.log-20171101running postrotate scriptcompressing log with: /bin/gzip