While using mongo, I got huge log files (several Gs) under my /var/log/mongodb directory. Example:
root@redis-frankfurt-production:/var/log/mongodb# ls -ltrh /var/log/mongodb/mongod.log*
-rw-r--r-- 1 root root 9.2G Aug 29 06:10 /var/log/mongodb/mongod.log.2016-08-29T10-29-04
-rw-r--r-- 1 root root 2.5G Aug 29 10:01 /var/log/mongodb/mongod.log.2016-08-29T14-03-30
In addition, there are the journal logs:
root@redis-frankfurt-production:/var/log/mongodb# ls -ltrh /var/log/mongodb/journal/
total 301M
-rw-r--r-- 1 mongodb mongodb 101M Jun 17 13:10 WiredTigerPreplog.0000000002
-rw-r--r-- 1 mongodb mongodb 101M Jun 17 13:10 WiredTigerPreplog.0000000001
-rw-r--r-- 1 mongodb mongodb 101M Jun 17 13:10 WiredTigerLog.0000000001
From what I understood the journal logs are used to sync between memory levels. And the logs which are under /var/log/mongodb/mongod.log.* are pure logging data. From what I see, the dates of the logs are not changing over time (last modified date).
Here is my question: Is it possible to delete old /var/log/mongodb/mongod.log.* (not touching the journal logs)?
Thanks!
Few info about the journal files. https://docs.mongodb.com/manual/core/journaling/
LOGROTATE :- And regarding the removal of the mongo log files, yes you can remove them any time, but ensure to have a new file, with the same user privillages and same user group as the old mongo log file.
For maintaing the log files, please use logrotate dameon process, which automatically handles this for you. It can compress the previous log files, compress them, and mail them also, and can remove the files older then a certain age. http://www.linuxcommand.org/man_pages/logrotate8.html
"/var/log/httpd/access.log" /var/log/httpd/error.log {
rotate 5
mail [email protected]
size=100k
sharedscripts
postrotate
/sbin/killall -HUP httpd
endscript
}
You can check all the parameters for the input in the logrotate, in the link mentioned above.