#切除本身日志内容并且自动生成新的以日期生成的历史文件方法一: Mongod -v --logpath /var/log/mongodb/mongos.log method Two: kill - Sigusr1 {pid} Method Three: Use admindb.runcommand ("LogRotate") #两种删除旧的日志文件, keep the log file for 7 days find /var/log/mongodb/ mongos.log.* -mtime +7 -exec rm -rf {} \;find /var/log/mongodb/ Mongos.log.* -mtime +7 -delete method Four: vim /etc/logrotate.d/mongodb/mongod/config.log { daily# Daily rotate 7# rotation for 7 days compress# by gzip compression missingok# if the log does not exist then ignore the warning notifempty# if it is empty file does not dump sharedscripts #只为整个日志组运行一次的脚本copytruncate #用于还在打开中的日志文件, the current log is backed up and truncated dateext# use date as a named format size 200m# when a log file reaches a specified size, you can specify k,mpostrotate/bin/ kill -sigusr1 ' Cat /mongod/mongod.lock 2>/dev/null ' 2> /dev/null | | trueendscript# End Script} #立即使上面的语句生效logrotate mongodb# script for automatic cutting of logs vim /root/cut_mongodb_log.sh#!/bin/ Bashdatafile=/mongodb/mongodb_datalogfile=/mongodb/mongodb_logdays=7/bin/kill -sigusr1 ' cat $datafile/mongod.lock ' find $logfile / -mtime + $days -deletechmod +x /root/cut_mongodb_log.shvim /etc/crontab0 0 * * * /root/cut_mongodb_log.shservice crond restartchkconfig crond on
This article is from the "Wu Shanqiang" blog, make sure to keep this source http://shanqiangwu.blog.51cto.com/8067564/1654972
MongoDB Log Management