Last active
May 31, 2022 12:17
-
-
Save gr8den/eeac5883fe61f6aef5385e96ccdbf3fd to your computer and use it in GitHub Desktop.
MongoDB (v4.4) log rotation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# nano /etc/mongod.conf | |
systemLog: | |
destination: file | |
logAppend: true | |
path: /var/log/mongodb/mongod.log | |
logRotate: reopen | |
processManagement: | |
pidFilePath: /var/run/mongodb/mongod.pid |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# nano /lib/systemd/system/mongod.service | |
[Service] | |
RuntimeDirectory=mongodb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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