هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
ماذا يفعل
logrotate renames a log (like messages → messages-20261025), starts a new empty one, compresses old files and deletes the oldest. On RHEL the logrotate.timer runs it once a day.
Main settings are in /etc/logrotate.conf; packages put their own rules in /etc/logrotate.d/. Test a rule with -d (debug, changes nothing) and force a rotation with -f.
طريقة الكتابة
logrotate [OPTION]... CONFIG_FILE...الأجزاء الرئيسية
daily,weekly,monthly,yearly- When to rotate.
sizeSIZE/minsize/maxsize- Rotate by size (like 100M).
rotateN- Keep N old files.
compress/delaycompress- gzip old files / wait one cycle.
dateext- Add the date to the name (RHEL default).
missingok/notifempty- No error if missing / skip empty logs.
createMODEOWNERGROUP- Make the new log with these rights.
copytruncate- Copy and empty the file (for programs that keep it open).
postrotate…endscript- Commands after the rotation, like a reload.
sharedscripts- Run the scripts once for all files of the rule.
maxageDAYS- Delete rotated files older than this.
suUSERGROUP- Rotate as this user (for folders not owned by root).
الخيارات 11
الأكثر استخدامًا
لا يوجد شيء يطابق هذا الفلتر.
أمثلة 10
$ مستخدم عادي# بصلاحية root (أو مع sudo)
1Show the main settings
Defaults for all rules.
2Rules of a package
cat /etc/logrotate.d/httpdIncludes a postrotate reload of httpd.
3Write a rule for your app
cat /etc/logrotate.d/app /var/log/app.log { weekly rotate 8 compress missingok notifempty create 0640 root root }Keeps 8 weeks of compressed logs.
4Test a rule
logrotate -d /etc/logrotate.d/appShows the plan; nothing changes.
5Force a rotation now
logrotate -fv /etc/logrotate.d/appCheck the result with
ls -l /var/log/app.log*.6Rotate by size
cat /etc/logrotate.d/bigapp /var/log/bigapp/*.log { size 200M rotate 5 compress copytruncate }For apps that cannot reopen their logs.
7When did it run last?
The state file stores the last rotation per log.
8Keep logs for compliance
sed -i 's/^rotate 4/rotate 52/' /etc/logrotate.confOne year of weekly logs (check the disk space; also send logs to a central server).
9Find rules with errors
logrotate -d /etc/logrotate.conf 2>&1 | grep -i errorWrong owners or rights stop the rotation.
10Reload a service after rotation
grep -A3 postrotate /etc/logrotate.d/nginxWithout it, the program writes to the renamed old file.
لا يوجد شيء يطابق هذا الفلتر.
الملفات
/etc/logrotate.conf- Main settings.
/etc/logrotate.d/- Rules per program.
/var/lib/logrotate/logrotate.status- Last rotation times.
رموز الخروج
0 :: Done. 1 :: Error.