docker日志驱动程序"json-file"滚动更新时日志丢失 [英] docker log driver "json-file" log loss when rolling update

查看:444
本文介绍了docker日志驱动程序"json-file"滚动更新时日志丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果max-file值设置为2,则将创建两个文件,如下所示.

If the max-file value is set to 2, two files are created as shown below.

11111-json.log
11111-json.log.1

但是在这里,当11111-json.log文件大小为max-size时,11111-json.log的内容将移动到11111-json.log.1,并且11111-json.log的大小变为零. /var/log/容器 此时,我丢失了最后一条日志.

But here, when the 11111-json.log file size is max-size, the contents of 11111-json.log are moved to 11111-json.log.1, and the size of 11111-json.log Becomes zero. /var/log/container At this point I lose the last log.

/var/log/container路径中的日志最终链接到/var/lib/docker/containers/~,因此,如果上述文件以这种方式工作,该日志将丢失.

The log in the /var/log/container path eventually links to /var/lib/docker/containers/~, so if the file mentioned above works that way, the log will be lost.

我怎么不迷路?

推荐答案

根据您的设置,所有日志.log.1,.log.2都存储在/var/lib/docker/containers/...中,并以根据docker文档,您可以在 daemon.json 中更改docker的那些设置:

According to your settings, all logs .log.1, .log.2 are stored in /var/lib/docker/containers/... and as per docker documentation you can change those settings for docker in daemon.json:

 "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3",

在/var/log/containers中,您可以找到指向最后创建的日志文件的链接.

in /var/log/containers you can find link to the last created log file.

根据 flunetd 的文档: 您应该考虑使用 in_tail 选项:

As per documentation for flunetd: You should consider using in_tail option:

in_tail包含在Fluentd的核心中.无需其他安装过程. 当首先用in_tail配置Fluentd时,它将从该日志的末尾开始读取,而不是从开头开始.旋转日志后,Fluentd从头开始读取新文件.它会跟踪当前的inode编号.

in_tail is included in Fluentd's core. No additional installation process is required. When Fluentd is first configured with in_tail, it will start reading from the tail of that log, not the beginning. Once the log is rotated, Fluentd starts reading the new file from the beginning. It keeps track of the current inode number.

请参阅类似的社区帖子

这篇关于docker日志驱动程序"json-file"滚动更新时日志丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆