Skip to content
English
  • There are no suggestions because the search field is empty.

MongoDB log rotation in Linux

Original Question or Issue:

We noticed that our MongoDB logs keep growing and are not being rotated.


Environment:

  • Product - FileCloud Server
  • Version - Any
  • Platform - Linux

Steps to Reproduce:

MongoDB is installed on Ubuntu or Redhat.


Error or Log Message:

Growing MongoDB logs consume storage space.


Defect or Enhancement Number:

 


Cause:

Logrotate utiliy.


Resolution or Workaround:

Access the MongoDB node via SSH and proceed as follows:

Modify the /etc/mongod.conf and set the parameters below:
"logAppend: true" and "logRotate: reopen".

Ensure the logrotate utility is installed:
apt install logrotate OR dnf install logrotate

Create the logrotate file /etc/logrotate.d/mongodb and append the content below:
/var/log/mongodb/mongod.log {
   daily
   rotate 7
   compress
   missingok
   notifempty
   sharedscripts
   postrotate
       /bin/kill -SIGUSR1 $(pgrep mongod)
   endscript
}

Restart the MongoDB service: systemctl restart mongod

 


Notes:

The above implementation will rotate the MongoDB log file daily, zip it and delete the oldest log file after 7 days.