具体举个logrotate使用的案例
时间: 2023-11-28 08:29:05 浏览: 120
Linux使用logrotate来切割日志文件
5星 · 资源好评率100%
Sure, logrotate is a tool used for rotating and compressing log files to save disk space. Here's an example:
Let's say you have a web server running and generating log files in /var/log/nginx/. You can create a configuration file for logrotate at /etc/logrotate.d/nginx that specifies how to rotate the logs. Here's what it could look like:
/var/log/nginx/*.log {
daily
rotate 7
compress
missingok
notifempty
create 0640 www-data adm
sharedscripts
postrotate
/etc/init.d/nginx reload > /dev/null
endscript
}
This configuration specifies that logrotate should rotate the log files for nginx every day and keep 7 days' worth of logs. The rotated logs will be compressed to save disk space. The "missingok" and "notifempty" options mean that logrotate won't report errors if the log file is missing or empty. The "create" option ensures that log files are created with the correct permissions and ownership. The "sharedscripts" option means that the postrotate script will only be run once (after all logs have been rotated). Finally, the postrotate script reloads the nginx service to ensure that it starts writing to the new log file.
I hope that helps! Do you have any other questions?
阅读全文