I configured logrotate, it’s seems to me that works but other the .gz files that contains the mongd.log there are files with 0 bytes in size of the past mongod.log files. What I have to do to have the compressed file fo the logs. Thank you in advance.
-rw-r----- 1 mongod mongod 0 Sep 18 00:00 mongod.log.2023-09-18T00-00-02
-rw-r----- 1 mongod mongod 0 Sep 19 00:00 mongod.log.2023-09-19T00-00-01
-rw-r----- 1 mongod mongod 0 Sep 20 00:00 mongod.log.2023-09-20T00-00-01
-rw-r----- 1 mongod mongod 0 Sep 22 00:00 mongod.log.2023-09-22T00-00-01
-rw-r----- 1 mongod mongod 0 Sep 23 00:00 mongod.log.2023-09-23T00-00-02
-rw-r----- 1 mongod mongod 0 Sep 24 00:00 mongod.log.2023-09-24T00-00-01
-rw------- 1 mongod mongod 32992 Sep 25 00:00 mongod.log-20230925_00.gz
-rw-r----- 1 mongod mongod 0 Sep 25 00:00 mongod.log.2023-09-25T00-00-01
-rw------- 1 mongod mongod 33062 Sep 26 00:00 mongod.log-20230926_00.gz
-rw-r----- 1 mongod mongod 0 Sep 26 00:00 mongod.log.2023-09-26T00-00-01
-rw------- 1 mongod mongod 33001 Sep 27 00:00 mongod.log-20230928_00.gz
systemLog:
destination: file
logAppend: true
logRotate: rename
path: /var/log/mongodb/mongod.log
timeStampFormat: iso8601-utc
/var/log/mongodb/mongod.log {
daily
rotate 5
dateext
dateformat -%Y%m%d_%H
compress
delaycompress
missingok
create640 mongod mongod
sharedscripts
postrotate
/bin/kill -USR1 cat /var/run/mongodb/mongod.pid 2>/dev/null
>/dev/null 2>&1
endscript
Hello everything is fine? I hope so
You can try to do it like this:
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
logRotate: reopen
processManagement:
pidFilePath: /var/run/mongodb/mongod.pid
And logrotate.conf
/var/log/mongodb/mongod.log {
daily
size 100M
rotate 10
missingok
compress
delaycompress
notifempty
create 640 mongod mongod
sharedscripts
postrotate
/bin/kill -SIGUSR1 `cat /var/run/mongodb/mongod.pid 2>/dev/null` >/dev/null 2>&1
endscript
}
This is just an example and you can adjust size, retention, among other things however you prefer.
1 Like
First of all I wanto to thank you for your reply.
I’m sorry but the change proposed it didn’t work for me.
Following the mongod.conf section about the system log, the list of the files that I got and the logroate.d config file. Where am I wrong?
systemLog:
destination: file
logAppend: true
logRotate: reopen
path: /var/log/mongodb/mongod.log
timeStampFormat: iso8601-utc
total 992
-rw-r----- 1 mongod mongod 231214 Oct 5 08:52 mongod.log
-rw-r----- 1 mongod mongod 0 Sep 30 00:00 mongod.log.2023-09-30T00-00-01
-rw------- 1 mongod mongod 33606 Oct 1 00:00 mongod.log-20231001_00.gz
-rw-r----- 1 mongod mongod 0 Oct 1 00:00 mongod.log.2023-10-01T00-00-01
-rw------- 1 mongod mongod 33562 Oct 2 00:00 mongod.log-20231002_00.gz
-rw-r----- 1 mongod mongod 0 Oct 2 00:00 mongod.log.2023-10-02T00-00-01
-rw------- 1 mongod mongod 37762 Oct 3 00:00 mongod.log-20231003_00.gz
-rw-r----- 1 mongod mongod 0 Oct 3 00:00 mongod.log.2023-10-03T00-00-01
-rw------- 1 mongod mongod 37930 Oct 4 00:00 mongod.log-20231004_00.gz
-rw-r----- 1 mongod mongod 626234 Oct 5 00:00 mongod.log-20231005_00
daily
rotate 5
dateext
dateformat -%Y%m%d_%H
compress
delaycompress
missingok
create640 mongod mongod
sharedscripts
postrotate
/bin/kill -USR1 cat /var/run/mongodb/mongod.pid 2>/dev/null
>/dev/null 2>&1
endscript