MongoDB 日志文件增长

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5004626/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 11:58:44  来源:igfitidea点击:

MongoDB log file growth

mongodb

提问by strickland

Currently my log file sits at 32 meg. Did I miss an option that would split the log file as it grows?

目前我的日志文件大小为 32 兆。我是否错过了在日志文件增长时拆分日志文件的选项?

采纳答案by Andreas Jung

Rotate the logs yourself

自己旋转日志

http://www.mongodb.org/display/DOCS/Logging

http://www.mongodb.org/display/DOCS/Logging

or use 'logrotate' with an appropriate configuration.

或使用具有适当配置的“logrotate”。

回答by pdwalker

You can use logrotate to do this job for you.

您可以使用 logrotate 为您完成这项工作。

Put this in /etc/logrotate.d/mongod(assuming you use Linux and have logrotatedinstalled):

放入/etc/logrotate.d/mongod(假设您使用 Linux 并已logrotated安装):

/var/log/mongo/*.log {
    daily
    rotate 30
    compress
    dateext
    missingok
    notifempty
    sharedscripts
    copytruncate
    postrotate
        /bin/kill -SIGUSR1 `cat /var/lib/mongo/mongod.lock 2> /dev/null` 2> /dev/null || true
    endscript
}

回答by Gates VP

If you think that 32 megs is too large for a log file, you may also want to look inside to what it contains.

如果您认为 32 megs 对于日志文件来说太大,您可能还想查看它包含的内容。

If the logs seem mostly harmless ("open connection", "close connection"), then you may want to start mongodwith the --quietswitch. This will reduce some of the more verbose logging.

如果日志似乎大多是无害的(“开放连接”“密切联系”),那么你可能要开始mongod--quiet开关。这将减少一些更详细的日志记录。

回答by CloudStax

Using logrotate is a good option. while, it will generate 2 log files that fmchan commented, and you will have to follow Brett's suggestion to "add a line to your postrotate script to delete all mongod style rotated logs".

使用 logrotate 是一个不错的选择。同时,它将生成 fmchan 评论的 2 个日志文件,您必须按照 Brett 的建议“在您的 postrotate 脚本中添加一行以删除所有 mongod 样式的旋转日志”。

Also copytruncate is not the best option. There is always a window between copy and truncate. Some mongod logs may get lost. Could check logrotate man page or refer to this copytruncate discussion.

此外,copytruncate 也不是最好的选择。复制和截断之间总是有一个窗口。一些 mongod 日志可能会丢失。可以查看 logrotate 手册页或参考此 copytruncate 讨论

Just provide one more option. You could write a script that sends the rotate signal to mongod and remove the old log files. mongologrotate.shis a simple reference script that I have written. You could write a simple cron job or script to call it periodically like every 30 minutes.

只提供一种选择。您可以编写一个脚本,将旋转信号发送到 mongod 并删除旧的日志文件。mongologrotate.sh是我编写的一个简单的参考脚本。您可以编写一个简单的 cron 作业或脚本来定期调用它,例如每 30 分钟一次。