First, log cleanup steps
1. Rotate logs with database commands and log on to Mongod and MONGOs instances respectively
# mongo --host localhost:27xxxmongodb shell version: 2.6.xconnecting to: localhost:27xxx/testreplicaset003:SECONDARY> dbtestreplicaset003:SECONDARY> use Adminswitched to db adminreplicaset003:secondary> db.runcommand ({logRotate:1}) { " OK " : 1 }replicaset003:secondary> replicaset001:arbiter> exitbye# lltotal 22195424-rw-r--r-- 1 mongod mongod 1124 Dec 20 11:04 mongoc.log-rw-r--r-- 1 mongod mongod 33341517 dec 20 10:59 mongoc.log.2016-12-20t03-01-17-rw-r--r-- 1 mongod mongod 4944 dec 20 11:07 mongod1.log-rw-r--r-- 1 mongod mongod 680817815 dec 20 11:03 mongod1.log.2016-12-20t03-04-01-rw-r--r-- 1 mongod mongod 1030 dec 20 11:07 mongod2.log-rw-r--r-- 1 mongod mongod 1813798574 dec 20 11:07 mongod2.log.2016-12-20t03-07-43-rw-r--r-- 1 mongod mongod 2413 Dec 20 11:07 mongod.log-rw-r--r-- 1 mongod Mongod 1880520643 dec 20 11:06 mongod.log.2016-12-20t03-06-17-rw-r--r-- 1 mongod mongod 2071 Dec 20 11:05 mongos.log-rw-r--r-- 1 mongod mongod 18319577575 dec 20 10:52 mongos.log.2016-12-20t02-53-04
2. Use the system command to empty the log file and keep the log
# cat /dev/null > mongos.log.2016-12-20t02-53-04# cat /dev/null > mongod.log.2016-12-20t03-06-17# cat /dev/null > mongod2.log.2016-12-20t03-07-43# cat /dev/null > mongod1.log.2016-12-20T03-04-01# cat /dev/null > mongoc.log.2016-12-20t03-01-17# [[email protected] mongo]# lltotal 28-rw-r--r-- 1 mongod mongod 1338 Dec 20 11:09 mongoc.log-rw-r--r-- 1 mongod mongod 0 dec 20 11:10 Mongoc.log.2016-12-20t03-01-17-rw-r--r-- 1 mongod mongod 7670 dec 20 11:10 mongod1.log-rw-r--r-- 1 mongod mongod 0 Dec 20 11:10 mongod1.log.2016-12-20t03-04-01-rw-r--r-- 1 mongod mongod 3594 dec 20 11:10 mongod2.log-rw-r--r-- 1 mongod mongod 0 dec 20 11:10 mongod2.log.2016-12-20t03-07-43-rw-r--r-- 1 mongod mongod 5247 Dec 20 11:10 mongod.log-rw-r--r-- 1 mongod mongod 0 dec 20 11:09 Mongod.log.2016-12-20t03-06-17-rw-r--r-- 1 mongod mongod 2297 dec 20 11:10 mongos.log-rw-r--r-- 1 mongod mongod 0 dec 20 11:09 mongos.log.2016-12-20t02-53-04
Second, the idea
1. In general, there are two ways in which a database log can be cleared, one through a database command and one system command.
2. Log clean up the original file must be retained, can not use RM to delete files, avoid, we aim to free up space.
3. Some companies require that the logs be archived to the big data platform for analysis, so you need to be clear when you clean up the log files, and don't be reckless.
III. Official documents
https://docs.mongodb.com/v2.6/tutorial/rotate-log-files/
It is very easy for the students to learn English well, so we should try to learn English better.
This article is from the "ROIDBA" blog, make sure to keep this source http://roidba.blog.51cto.com/12318731/1884198
MongoDB 2.6.x ways to clean up large log files