Logrotate Generator
What is Logrotate?
Logrotate is a Linux utility designed to manage log files on Unix/Linux systems. It automatically compresses, rotates, deletes, and emails log files according to a scheduled configuration.
Why use logrotate?
- Space saving: Prevents log files from growing indefinitely and filling the disk.
- Organization: Maintains a history of rotated logs with dates.
- Compression: Reduces the size of older logs.
- Automation: Everything works automatically without manual intervention.
Installation
# Debian/Ubuntu
sudo apt-get install logrotate
# RHEL/CentOS/Fedora
sudo yum install logrotate
# Arch Linux
sudo pacman -S logrotate
Basic Configuration
Typical configuration is located in:
/etc/logrotate.conf- Global configuration/etc/logrotate.d/- Per-application configurations
Important Directives
- daily/weekly/monthly - Rotation frequency
- rotate N - Keep N old files
- size Size - Rotate if size exceeds (e.g., 100M)
- compress - Compress old logs with gzip
- create mode user group - Create new file after rotation
- missingok - No error if file doesn't exist
- notifempty - Don't rotate if file is empty
- postrotate/endscript - Run commands after rotation
Practical Example
/var/log/nginx/access.log {
daily
rotate 14
compress
delaycompress
missingok
notifempty
create 640 www-data adm
sharedscripts
postrotate
[ -f /var/run/nginx.pid ] && kill -USR1 $(cat /var/run/nginx.pid)
endscript
}
Frequently Asked Questions
What is logrotate and what is it used for?
How to install logrotate on Linux?
What is the difference between daily, weekly, and monthly directives in logrotate?
How to compress old logs with logrotate?
What does the "rotate" directive mean in logrotate?
How to force log rotation without waiting for the logrotate schedule?
How to configure logrotate for Nginx or Apache?
Related Tools
K8s to Helm Chart Converter
Convert Kubernetes manifests into Helm charts with parameterizable values.
Server Name Generator
Generate consistent server names (prod-web-01, staging-db-01)
Downtime Calculator
Calculate availability percentage based on downtime
Deployment Simulator
Visualize strategies: Rolling Update, Blue-Green and Canary