Currently my log file sits at 32 meg. Did I miss an option that would split the log file as it grows?
Rotate the logs yourself
http://www.mongodb.org/display/DOCS/Logging
or use 'logrotate' with an appropriate configuration.
You can use logrotate to do this job for you.
Put this in /etc/logrotate.d/mongod
(assuming you use Linux and have logrotate
installed):
/var/log/mongo/*.log {
daily
rotate 30
compress
dateext
missingok
notifempty
sharedscripts
copytruncate
postrotate
/bin/kill -SIGUSR1 `cat /var/lib/mongo/mongod.lock 2> /dev/null` 2> /dev/null || true
endscript
}
copytruncate
to avoid crashing MongoDB versions 2.4.7 and 2.4.6. See jira.mongodb.org/browse/SERVER-11087 for details. –
Spathic logrotate
man page was very useful and educating for me. Also, as pointed out by @ErwinWessels people must pay attention to the paths. –
Calv /bin/kill -SIGUSR1 cat /var/lib/mongo/mongod.lock 2> /dev/null 2> /dev/null || true
–
Decastyle cat /export/home/d17/test/data/v1/mongo/repl0/mongod.lock 2> /dev/null
2> /dev/null || true –
Decastyle mongod.log
to mongod.log-20150511
. After that, the postrotate script is executed, and when mongod receives SIGUSR1 it also does a rotation, copying mongod.log
(now empty) is then copied by mongod (not logrotate) to mongod.log.2015-05-11T20-02-03
. You could add a line to your postrotate script to delete all mongod style rotated logs, after the kill command: rm -f /path/to/log/mongo.log*T*
–
Diao dateformat
parameter - see the logrotate manual for more info. linux.die.net/man/8/logrotate –
Diao mongod.log.2015-05-11T20-02-03
. Set logRotate to reopen and logAppend to true. See docs.mongodb.com/v3.4/tutorial/rotate-log-files –
Theresiatheresina If you think that 32 megs is too large for a log file, you may also want to look inside to what it contains.
If the logs seem mostly harmless ("open connection", "close connection"), then you may want to start mongod
with the --quiet
switch. This will reduce some of the more verbose logging.
quiet = true
to your config file (/etc/mongod.conf
on some systems). –
Evan Using logrotate is a good option. while, it will generate 2 log files that fmchan commented, and you will have to follow Brett's suggestion to "add a line to your postrotate script to delete all mongod style rotated logs".
Also copytruncate is not the best option. There is always a window between copy and truncate. Some mongod logs may get lost. Could check logrotate man page or refer to this copytruncate discussion.
Just provide one more option. You could write a script that sends the rotate signal to mongod and remove the old log files. mongologrotate.sh is a simple reference script that I have written. You could write a simple cron job or script to call it periodically like every 30 minutes.
Rotate the logs yourself
http://www.mongodb.org/display/DOCS/Logging
or use 'logrotate' with an appropriate configuration.
For Linux and Unix-based systems, you can use the SIGUSR1 signal to rotate the logs for a single process.
For example, if a running mongod instance has a process ID (PID) of 2200, the following command rotates the log file for that instance on Linux:
kill -SIGUSR1 2200
© 2022 - 2024 — McMap. All rights reserved.