The log rotation setting of CentOS7 is required "occasionally", but (that's why) I forget it every time and go to the set server, so I will write it here. For those who want to know only the main points quickly!
<filename>
is optional.
vim /etc/logrotate.d/<filename>
Describe the following in /etc/logrotate.d/<filename>
created above
<target file>
--Full path of files to be rotated/etc/logrotate.d/filename
<target file> {
weekly
rotate 7
missingok
notifempty
copytruncate
compress
dateext
dateformat _%Y%m%d
minsize 1M
}
The setting itself is complete.
I will add a description of the above settings ...
weekly
--Weekly Rotaterotate 7
--Hold for 7 generationsmissingok
--No error even if the file to be rotated does not existnotifempty
--Do not rotate if the file to be rotated is emptycopytruncate
--After creating the rotate file, empty the contents of the file to be rotated.
--If you do not specify this, the original file will grow larger and larger.compress
--Compress the rotate file with gzipdateext
--Add a date suffix to the rotate file (better to use with dateformat
)
--Example: xxx_20200101.gz
dateformat
--Define the format of date
yourself
--In the above example, xxx_20200101.gz
minsize
--Rotate only if the size is larger than the specified size
--In the above example, rotate only when it is 1M or more.