1, create a polling log file, add the following, Log-file is my self-specified file log name
[Email protected] mnt]# Cat/etc/logrotate.d/log-file
/mnt/log-file {
size=100m
Rotate 5
Compress
Dateext
DateFormat%y-%m-%d-%s
Delaycompress
Notifempty
Missingok
Create 644 root root
Postrotate
/usr/bin/killall-hup RSYSLOGD
Endscript
}
Over here:
monthly: The log file will be round by month. Other available values are ' daily ', ' weekly ' or ' yearly '.
Size: Log file sizes, and capacity waits for the size of the set range, it will cut itself
Rotate 5: 5 Archive logs will be stored at a time. For a sixth archive, the oldest archive will be deleted.
Compress: After a round-robin task is completed, the archived archive will be compressed using gzip.
delaycompress: Always with the Compress option, the Delaycompress option indicates that logrotate does not compress the most recent archive, and compression will take place during the next round-robin cycle. This is useful when you or any software still needs to read the latest archive.
Missingok: During log rotation, any errors will be ignored, such as "files cannot be found".
notifempty: If the log file is empty, the round robin does not proceed.
Create 644 root root: Creates a completely new log file with the specified permissions, and logrotate renames the original log file.
postrotate/endscript: After all other instructions have been completed, the commands specified inside postrotate and Endscript will be executed. In this case, the RSYSLOGD process will immediately read its configuration again and continue to run.
2. Generate log files and test
[Email protected]mysql ~]# cd/mnt
[[email protected] mnt]# dd If=/dev/zero of=/mnt/log-file bs=100m count=1
Recorded 1+0 read-in
Recorded the writing of 1+0.
104857600 bytes (MB) Replicated, 0.103621 sec, 1.0 GB/s
[Email protected] mnt]# Logrotate/etc/logrotate.d/log-file
[[email protected] mnt]# ls
Log-file log-file2015-11-30-1448828422
[[email protected] mnt]# dd If=/dev/zero of=/mnt/log-file bs=100m count=1
Recorded 1+0 read-in
Recorded the writing of 1+0.
104857600 bytes (MB) Replicated, 0.0940398 sec, 1.1 GB/s
[Email protected] mnt]# Logrotate/etc/logrotate.d/log-file
[[email protected] mnt]# ls
Log-file log-file2015-11-30-1448828442
Log-file2015-11-30-1448828422.gz
[[email protected] mnt]# dd If=/dev/zero of=/mnt/log-file bs=100m count=1
Recorded 1+0 read-in
Recorded the writing of 1+0.
104857600 bytes (MB) Replicated, 0.0861139 sec, 1.2 GB/s
[Email protected] mnt]# Logrotate/etc/logrotate.d/log-file
[[email protected] mnt]# ls
Log-file log-file2015-11-30-1448828442.gz
Log-file2015-11-30-1448828422.gz log-file2015-11-30-1448828473
[Email protected] mnt]# crontab-l
*/1 * * * */usr/sbin/logrotate/etc/logrotate.d/log-file
Hope to communicate with the technology can contact me by the following ways
My OPS group 517751492
My QQ1934844044.
This article is from the "Wsyht blog" blog, make sure to keep this source http://wsyht2015.blog.51cto.com/9014030/1718812
Logrotate Log cutting, polling, deleting