MongoDB log rotation
Add parameters to the configuration file
Logpath=/data/app_data/mongodb/log/mongodb.log logappend=true
This is the only way to rotate logs under Windows.
> use admin;switched to db admin > db.runCommand ({logRotate: 1}) {"ok": 1}
Under Linux, you can also rotate logs by setting scheduled tasks in the early hours of each day.
0 * / bin/kill-SIGUSR1 `cat / data/app_data/mongodb/data/ mongod.pid`
View the log
-rw-r--r-- 1 mongod mongod 13M Apr 1 20:47 mongodb.log-rw-r--r-- 1 mongod mongod 332K Dec 20 2013 mongodb.log.2013-12-19T16-00-01 Mustang RWFUR-1 mongod mongod 1.7m Dec 21 2013 mongodb.log.2013-12-20T16-00-01When RWFUR-1 mongod mongod 1.9m Dec 22 2013 mongodb.log.2013-12-21T16-00-01 Mustang -1 mongod mongod 2.3M Dec 23 2013 mongodb.log.2013-12-22T16-00-02When RWQQ-1 mongod mongod 2.3M Dec 24 2013 mongodb.log.2013-12-23T16-00-01What RWQA-1 mongod mongod 2.7m Dec 25 2013 mongodb.log.2013-12-24T16-00-01When RWFRT-1 mongod mongod 2.5m Dec 26 2013 mongodb.log.2013-12-25T16-00-01
The rotated log is suffixed with the file name with the UTC timestamp. There is a certain time difference between local time and local time. For example, 16 here should be 16: 00, 8: 24, Beijing time, that is, 0 o'clock.
You can use the log rotation tool logrotate that comes with the system to rotate MongoDB logs.
/ etc/logrotate.d/mongodb
/ data/app_data/mongodb/log/*.log {daily rotate 10 copytruncate delaycompress compress notifempty missingok postrotate / bin/kill-USR1 `cat / data/app_data/mongodb/data/mongod.pid 2 > / dev/ null`2 > / dev/null | | true endscript}
Reference documentation:
Http://docs.mongodb.org/v2.4/tutorial/rotate-log-files/