Child pages
  • Setting Mongod Logrotate
Skip to end of metadata
Go to start of metadata

If you downloaded the Opmantek VM then the mongod.conf for logrotate is already in place for you and maybe you just need to modify the settings. Otherwise the steps and sample are below.

Note: You can find all of your logrotate configuration files in /etc/logroate.d/, Logrotate is a job ran daily by cron

There are a few options you should look at before making your configuration file: Logrotate Man page. Considerations include:

  • Do you need to rotate your log daily or weekly?
  • How many past logs do you need to keep?
  • Compression and how you handle it.

  1. Open a terminal session to your Opmantek server
  2. Find the location of your mongod.log file. This can be done by cat /etc/mongod.conf  you will find the log location under the systemLog section. Copy the full path and paste it in a notepad for later.
  3. Making your logrotate mongod file: (**Note this is the default we ship with in our VM. Depending on your company standards it may need edits)
    1. vi /etc/logrotate.d/mongod.conf

      # Replace /var/log/mongodb/mongod.log with your log location (step 1) if different
      /var/log/mongodb/mongod.log {
        maxsize 500M
        rotate 50
        create 640 mongod mongod
          kill -SIGUSR1 $(pidof mongod) >/dev/null 2>&1||:
    2. Save and quit
  4. Check permissions and ownership of the new conf file: ls -al /etc/logrotate.d/
  5. Testing your new logrotate: logrotate --debug /etc/logrotate.d/mongod.log
    1. Any errors you have will appear in your output.

Thats it! It is advised to revisit your logs after a few cycles (Days or Weeks) to ensure your operating as expected and make any tweaks that you see fit.

  • No labels