Skip to content

Instantly share code, notes, and snippets.

@gr8den
Last active May 31, 2022 12:17
Show Gist options
  • Save gr8den/eeac5883fe61f6aef5385e96ccdbf3fd to your computer and use it in GitHub Desktop.
Save gr8den/eeac5883fe61f6aef5385e96ccdbf3fd to your computer and use it in GitHub Desktop.
MongoDB (v4.4) log rotation
# nano /etc/logrotate.d/mongodb
/var/log/mongodb/mongod.log {
rotate 7
daily
size 100M
missingok
create 0600 mongodb mongodb
delaycompress
compress
sharedscripts
postrotate
/bin/kill -SIGUSR1 $(cat /var/run/mongodb/mongod.pid)
endscript
}
# nano /etc/mongod.conf
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
logRotate: reopen
processManagement:
pidFilePath: /var/run/mongodb/mongod.pid
# nano /lib/systemd/system/mongod.service
[Service]
RuntimeDirectory=mongodb
sudo systemctl daemon-reload
sudo systemctl restart mongod
sudo systemctl status mongod
ls -lah /var/log/mongodb/
logrotate -f /etc/logrotate.d/mongodb
ls -lah /var/log/mongodb/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment