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

MongoDB logs do not rotate automatically on secondary nodes in HA environment

Original Question or Issue:

In an HA environment, logs on the secondary MongoDB node do not appear to be rotating. Is this expected behavior, and can logs be configured to rotate on all MongoDB nodes?


Environment:

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

Steps to Reproduce:

Configure a FileCloud HA environment with multiple MongoDB nodes.
Observe MongoDB log behavior across the primary and secondary DB nodes.
Note that logs may appear to rotate on one node but not on another.


Error or Log Message:

No specific FileCloud error.


Defect or Enhancement Number:

No JIRA assigned


Cause:

This behavior is expected. MongoDB log rotation is handled per node and is not replicated between primary and secondary nodes in an HA replica set.


Resolution or Workaround:

To ensure logs rotate consistently across the HA environment, configure Linux logrotate on each MongoDB node individually.

On each DB node, create a logrotate configuration file:

sudo nano /etc/logrotate.d/mongod

Add the following:

/var/log/mongodb/mongod.log {
    daily
    rotate 7
    compress
    missingok
    notifempty
    copytruncate
}

This will:

  1. Rotate logs daily

  2. Retain 7 days of history

  3. Compress older logs and help prevent disk space issues

     

A manual one-time log rotation can also be performed if needed from mongosh:

use admin
db.adminCommand({ logRotate: 1 })

 


Notes:

MongoDB log rotation should be configured on all MongoDB nodes, including both primary and secondary nodes.

The one-time logRotate command rotates the log only for the node where it is executed.

Long-term rotation and retention should be handled through Linux logrotate