【问题标题】:Reload docker logging configuration without daemon restart在不重启守护进程的情况下重新加载 docker 日志记录配置
【发布时间】:2018-03-12 13:42:48
【问题描述】:

我有一些正在运行的 kubernetes 集群,它可能会产生大量日志。 Kubernetes 运行在 docker 之上,所以我想我需要 configure dockerd to rollout logs

我找到了一些用于 dockerd 日志记录驱动程序的设置:

{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10k",
    "max-file": "2"
  }
}

在 docker service restart 的情况下,更改会成功应用。

du /var/lib/docker/containers/container_hash/container_hash* -h

显示按适当大小分割成块的日志文件。

但我不想重启守护进程,所以尝试重新加载配置:

sudo kill -SIGHUP $(pidof dockerd)

在系统日志中我发现:

Mar 12 15:38:16 kso-gl dockerd[5331]: time="2018-03-12T15:38:16.446894155+02:00" level=info msg="Got signal to reload configuration, reloading fr
om: /etc/docker/daemon.json"

所以,我假设配置已重新加载。不幸的是,它没有效果。即使是新容器。 看起来与日志记录驱动程序相关的子系统忽略了重新加载配置。

【问题讨论】:

  • 也许您可以在运行容器时通过 --log-opt max-size=10m --log-opt max-file=10 指定日志记录参数

标签: docker logging kubernetes


【解决方案1】:

遗憾的是,配置重新加载 SIGHUP 功能似乎不支持所有配置选项。

https://docs.docker.com/v17.09/engine/reference/commandline/dockerd/#miscellaneous-options 的文档(请参阅“配置重新加载行为”部分)告诉我们,可以通过这种方式重新加载的唯一受支持的配置选项是:

The list of currently supported options that can be reconfigured is this:

debug: it changes the daemon to debug mode when set to true.
cluster-store: it reloads the discovery store with the new address.
cluster-store-opts: it uses the new options to reload the discovery store.
cluster-advertise: it modifies the address advertised after reloading.
labels: it replaces the daemon labels with a new set of labels.
live-restore: Enables keeping containers alive during daemon downtime.
max-concurrent-downloads: it updates the max concurrent downloads for each pull.
max-concurrent-uploads: it updates the max concurrent uploads for each push.
default-runtime: it updates the runtime to be used if not is specified at container creation. It defaults to “default” which is the runtime shipped with the official docker packages.
runtimes: it updates the list of available OCI runtimes that can be used to run containers
authorization-plugin: specifies the authorization plugins to use.
allow-nondistributable-artifacts: Replaces the set of registries to which the daemon will push nondistributable artifacts with a new set of registries.
insecure-registries: it replaces the daemon insecure registries with a new set of insecure registries. If some existing insecure registries in daemon’s configuration are not in newly reloaded insecure resgitries, these existing ones will be removed from daemon’s config.
registry-mirrors: it replaces the daemon registry mirrors with a new set of registry mirrors. If some existing registry mirrors in daemon’s configuration are not in newly reloaded registry mirrors, these existing ones will be removed from daemon’s config.

如您所见,其中不包括 log-driverlog-opts 配置参数。

目前我不知道如何在不重新启动的情况下重新加载日志记录配置。

【讨论】:

  • 如果您不想重新启动容器,这似乎是一个可能的解决方案: 1. 使用 SIGHUP 使用实时配置重新加载更改“实时恢复”选项。 2. 更改日志选项 3. 重新启动 docker 守护程序我没有测试过这个,但它似乎可以工作 - 在
  • 感谢@Adriaan,但是,重点是避免重新启动 docker 守护进程。
  • 对我来说,关键是不要重新启动由 docker 守护进程管理的所有容器——并且这个解决方案将在守护进程重新启动并重新加载配置时保持所有容器运行。我知道严格来说他要求不重新启动守护进程,但实际上最可能的原因是不想重新启动容器..
猜你喜欢
  • 2010-09-15
  • 2018-09-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-10
  • 2012-07-10
  • 2016-09-20
相关资源
最近更新 更多