Today, customers are asked to provide a MONGO log cleanup solution, and the customer provides a KILL-SIGUSR1 way to record the learning and testing process as well as several other log cleanup methods.
Method 1: Use Db.runcommand ({logrotate:1}) in MONGO's Shell to organize the logs:
The operation is as follows:
shard1:primary> Use admin
Switched to DB admin
Shard1:primary> Db.runcommand ({logrotate:1})
{"OK": 1}
Log directory status before and after operation:
Ago:
[email protected] log]# LL
Total 600
-rw-rw-r--1 MONGO MONGO 156703 May 8 22:43 Arbiter.log
-rw-rw-r--1 MONGO MONGO 446123 May 8 22:29 Mongod.log
After:
[email protected] log]# LL
Total 604
-rw-rw-r--1 MONGO MONGO 156703 May 8 22:43 Arbiter.log
-rw-r--r--1 root root 1114 May 8 22:44 Mongod.log
-rw-rw-r--1 MONGO MONGO 446123 May 8 22:29 mongod.log.2018-05-08t14-44-56
After executing the command, a new time-named log file is copied.
Method 2: Use the command provided by the customer to KILL-SIGUSR1 the command.
First, query the Mongod process number:
[Email protected] log]# Ps-ef|grep Mongod
Root 1335 1 1 22:15? 00:00:53/usr/local/mongodb/bin/mongod-f/data/mongodb/conf/mongod.conf
Root 1620 1416 0 23:09 pts/1 00:00:00 grep mongod
Locate the Mongod process number 1335, and then do the following:
[Email protected] log]# KILL-SIGUSR1 1335
Ago:
[email protected] log]# LL
Total 12
-rw-r--r--1 root root 1306 May 8 23:13 Arbiter.log
-rwxr-xr-x 1 root root 356 May 8 23:08 clear-log.sh
-rw-r--r--1 root root 1540 May 8 23:23 Mongod.log
After:
[email protected] log]# LL
Total 16
-rw-r--r--1 root root 1306 May 8 23:13 Arbiter.log
-rwxr-xr-x 1 root root 356 May 8 23:08 clear-log.sh
-rw-r--r--1 root root 1301 May 8 23:30 Mongod.log
-rw-r--r--1 root root 1540 May 8 23:23 mongod.log.2018-05-08t15-30-42
After executing the command KILL-SIGUSR1 1335 (process number), a new log file is generated with the same size as the original log Mongod.log file, with a time name.
Method 3: Use the command KILLALL-SIGUSR1 Mongod
Execute command: [[email protected] log]# KILLALL-SIGUSR1 Mongod
Ago:
[email protected] log]# LL
Total 12
-rw-r--r--1 root root 1306 May 8 23:13 Arbiter.log
-rwxr-xr-x 1 root root 356 May 8 23:08 clear-log.sh
-rw-r--r--1 root root 1301 May 8 23:30 Mongod.log
After:
[email protected] log]# LL
Total 20
-rw-r--r--1 root root 1306 May 8 23:33 Arbiter.log
-rw-r--r--1 root root 1306 May 8 23:13 arbiter.log.2018-05-08t15-33-49
-rwxr-xr-x 1 root root 356 May 8 23:08 clear-log.sh
-rw-r--r--1 root root 1301 May 8 23:33 Mongod.log
-rw-r--r--1 root root 1301 May 8 23:30 mongod.log.2018-05-08t15-33-49
This command cleans up the deployment of multiple mongod on a single server.
Method 4:
cp,>, the most primitive way.
CP Mongodb17.log MONGODB17.LOG.BAK.2013-05-21.10-40
> Mongodb17.log
According to the actual needs to choose, for the MONGO database, the personal recommendation of the use of KILL-SIGUSR1 this command, this command on the Redis attempt to use, directly to the Redis process to kill. Use on MySQL, although the process is not dead, but also with the log does not matter. So this command is only suitable for MONGO.
MongoDB log Cleanup Learn to organize