如何在Ubuntu上读取MongoDB日志编号

huangapple go评论133阅读模式
英文:

How to Read Mongodb log number ubuntu

问题

在Ubuntu服务器上,我实施了logrotate以轮换日志文件,但我注意到一个问题,日志文件旁边的数字太大,我不理解如何读取日志旁边的数字“52548376”或它代表什么。

关于此问题是否有任何帮助,或者有关如何阅读它的解释?

以下是我的logrotate配置:

/var/log/mongodb/*.log {
   rotate 7
   daily
   size 100M
   missingok
   create 0600 mongodb mongodb
   delaycompress
   compress
   sharedscripts
   postrotate
     /bin/kill -SIGUSR1 $(pgrep -f mongod)
   endscript
}

我注意到它应该在达到100MB后轮换日志。

英文:

So i have a log at ubuntu server that i implemented logrotate to rotate the log, but i notice one things that the number is too big and i dont understand how to read the number beside the log
如何在Ubuntu上读取MongoDB日志编号

Any help on this? or any explanation to how to read it "52548376" or what does it stand for

here is my configuration for logrotate:

/var/log/mongodb/*.log{
   rotate 7
   daily
   size 100M
   missingok
   create 0600 mongodb mongodb
   delaycompress
   compress
   sharedscripts
   postrotate
     /bin/kill -SIGUSR1 $(pgrep -f mongod)
   endscript
}

i notice that it should rotate the log after it reached 100MB

答案1

得分: 1

这是字节大小。

52548376字节等于52兆字节,但您设置了100兆字节的限制,那么为什么您期望进行日志轮换呢?

我建议不要使用kill -SIGUSR1 $(pgrep -f mongod),而是使用

kill -SIGUSR1 $(/usr/sbin/pidof mongod)

或者更好的是

if /usr/sbin/pidof -s mongod > /dev/null ; then kill -USR1 $(/usr/sbin/pidof mongod) ; fi

您指定了daily,这意味着日志文件每天都会轮换,无论大小是否达到100兆字节。只有在一天内运行logrotate多次时,使用dailysize才有意义。

选项create是不必要的。mongod会自动创建新的日志文件。相反,我建议添加notifempty

英文:

That's the file size in Bytes.

52548376 Bytes are 52MByte but you set a limit of 100MByte, so why do you expect a log rotation?

Instead of kill -SIGUSR1 $(pgrep -f mongod) I would suggest

kill -SIGUSR1 $( /usr/sbin/pidof mongod )

or even better

if /usr/sbin/pidof -s mongod > /dev/null ; then kill -USR1 $( /usr/sbin/pidof mongod ) ; fi

You specified daily which means the logfile is rotated daily, no matter whether the size reached 100MB or not. Using daily and size makes only sense if you run logrotate more than once a day.

Option create is not needed. mongod creates a new logfile automatically. Instead I would add notifempty

huangapple
  • 本文由 发表于 2023年3月15日 19:01:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/75743825.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定