By default, MongoDB does not automatically switch the rotation log, which will increase the number of logs. In the busy business, the log growth volume is very large. It is not convenient to view logs of a certain day for such a large log file. If yes, you need to switch the mongodb log file for 7 days. SIGUSR1 method # kill-SIGUSR1 # finddata
By default, MongoDB does not automatically switch the rotation log, which will increase the number of logs. In the busy business, the log growth volume is very large. It is not convenient to view logs of a certain day for such a large log file. If yes, you need to switch the mongodb log file for 7 days. SIGUSR1 method # kill-SIGUSR1 # find/data/
By default, MongoDB does not automatically switch the rotation log, which will increase the number of logs. In the busy business, the log growth volume is very large. It is not convenient to view logs of a certain day for such a large log file. If yes, you need to switch the mongodb log file for 7 days. SIGUSR1 Method
# kill -SIGUSR1 # find /data/mongodb_data/log/mongodb.log.* -mtime +7 -delete
This method can only be performed in Linux. Mongo logRotate command Method
use admindb.runCommand( { logRotate : 1 } )It must be run on mongos, mongod, and config server. This method is the only method in Windows. Syslog Rotation
# vi /etc/logrotate.d/mongodb /opt/mongodb/log/mongodb.log { daily rotate 7 compress dateext missingok notifempty sharedscripts copytruncate postrotate /bin/kill -SIGUSR1 `cat /data/mongodb_data/mongod.lock 2> /dev/null` 2> /dev/null || true endscript}
# logrotate -f /etc/logrotate.d/mongodb
For details about logrotate, see logrotate log management tools. Mongodb bug is not stable enough. In log rotation, the mongodb process is terminated. For details, refer to the mongodb bug system.
Original article address: MongoDB log switch. Thank you for sharing it.