Case: Logrotate's log rotation
For admin.log files, set logrotate
Rotate once a day
Keep 3 Backups
File larger than 100k Auto rotate
On the finished file compression Create permission 0600, owner Root belongs to group root
Steps:
1. First check if the Logrotate package is installed
[Email protected] log]# rpm-q logrotate
Logrotate-3.7.8-17.el6.x86_64
Create log Admin.log because I don't have admin.log this file in my virtual machine
[Email protected] log]# Mkair Admin.log
2. Setting up the configuration file
[Email protected] log]# vim/etc/logrotate.d/admin
/var/log/admin.log {
Missingok
Daily
Size 100k
Rotate 3
Create 0600 root root
Compress
3. Testing
Here because the log is more than 100K automatic rotation, we can manually rotate
Find a file larger than 100k in the system file and copy it to Admin.log
[Email protected] log]# Cp/etc/ssh/moduli/var/log/admin.log
[Email protected] log]# logrotate/etc/logrotate.conf
[Email protected] log]# ls-l/var/log/admin.log*
-RW-------. 1 root root 125811 February 16:10/var/log/admin.log
-RW-------. 1 root root 127214 February 15:59 /var/log/admin.log-20170228.gz
can look at a. GZ end of the compressed file, indicating that the rotation log file settings are successful
You can also force rotation through the logrotate-f command. But it doesn't make much sense, because it doesn't make sense to detect whether our settings are successful, regardless of whether the set conditions will be rotated.
This article is from the "12619984" blog, please be sure to keep this source http://12629984.blog.51cto.com/12619984/1902073
Logrotate's log rotation Linux