What should I do if the MongoDB log is too large?

Source: Internet
Author: User
MongoDB logs are growing rapidly, and the space where var is located is immediately full. Even if you change to another disk partition to save the logs, the logs are still growing rapidly, and the disk is about to crash. There is a good way to use rotating logs. MongoDB's rotating log is a bit strange, the mongd service in Linux receives a kill-SGIUSR1 command immediately after the current log

MongoDB logs are growing rapidly, and the space of/var is immediately full. Even if you switch to another disk partition to save the logs, the logs are still growing rapidly, and the disk is about to be closed. There is a good way to use rotating logs. MongoDB's rotation log is a bit strange. in Linux, The mongd Service receives a kill-SGIUSR1 command and immediately sends the current log

MongoDB logs are growing rapidly, and the space of/var is immediately full. Even if you switch to another disk partition to save the logs, the logs are still growing rapidly, and the disk is about to be closed.

There is a good way to use rotating logs.

MongoDB's rotation log is a bit strange. in Linux, The mongd Service accepts the kill-SGIUSR1 command and immediately renames the current log file to a file with a date, and then creates a new log file.

If you do not want to rotate logs normally, you can configure a rotation policy. But it does not matter. After testing, the MongoDB service will not be affected when the command is sent.

The following is an example. first look for the process id and then send the command.

root@jstc:/etc/init.d# ps -def | grep mongodmongodb    723     1 48 May04 ?        6-22:23:53 /usr/bin/mongod --config /etc/mongodb.confroot     22035 22012  0 20:22 pts/2    00:00:00 grep --color=auto mongodroot@jstc:/etc/init.d# kill -SIGUSR1 723root@jstc:/etc/init.d# cd /home/mongodb/log/root@jstc:/home/mongodb/log# lsmongodb.log  mongodb.log.2014-05-18T12-23-51root@jstc:/home/mongodb/log# ls -alhtotal 20Gdrwxrwxrwx 2 root    root    4.0K May 18 20:23 .drwxrwxrwx 4 root    root    4.0K Apr 20 21:25 ..-rw-r--r-- 1 mongodb nogroup  34K May 18 20:24 mongodb.log-rwxrwxrwx 1 mongodb nogroup  20G May 18 20:23 mongodb.log.2014-05-18T12-23-51

Now you can move or delete the previous 20 GB log files.

You can also run a scheduled script to regularly send commands to the mongod service.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.