如何为 traefik 启用 logrotation?
How to enable logrotation for traefik?
如何为日志文件启用日志轮换,例如access.log.
这是内置的吗?
文档只说 "This allows the logs to be rotated and processed by an external program, such as logrotate"
似乎没有 logrotation built-in 所以我在挂载了 traefik_access.log
的主机上启用了 logrotation。
为了在 traefik 在 docker 容器中 运行 时工作,您必须卷挂载包含日志文件 (/opt/traefik/logs
) 的目录,而不是日志文件本身 (/traefik_access.log
).
volumes:
- /opt/traefik/logs:/logs
我的 logrotate-config for traefik 1.7.4 运行 在容器中,卷安装到“/opt/traefik/logs”:
/opt/traefik/logs/*.log {
daily
rotate 30
missingok
notifempty
compress
dateext
dateformat .%Y-%m-%d
create 0644 root root
postrotate
docker kill --signal="USR1" $(docker ps | grep traefik | awk '{print }')
endscript
}
Log Rotation
Traefik will close and reopen its log files, assuming they're configured, on receipt of a USR1
signal. This allows the logs to be rotated and processed by an external program, such as logrotate
.
https://docs.traefik.io/v1.6/configuration/logs/#log-rotation
如果你是 运行 Traefik 在 Docker 容器中,那么你可以这样做:
检查是否安装了 logrotate
logrotate --version
在 /etc/logrotate.d/
中创建文件
vi /etc/logrotate.d/traefik
放下面的脚本,不要忘记填写容器名称
/var/log/traefik/*.log {
size 10M
rotate 5
missingok
notifempty
postrotate
docker kill --signal="USR1" <container-name>
endscript
}
运行!
logrotate /etc/logrotate.conf --debug
logrotate /etc/logrotate.conf
如何为日志文件启用日志轮换,例如access.log.
这是内置的吗?
文档只说 "This allows the logs to be rotated and processed by an external program, such as logrotate"
似乎没有 logrotation built-in 所以我在挂载了 traefik_access.log
的主机上启用了 logrotation。
为了在 traefik 在 docker 容器中 运行 时工作,您必须卷挂载包含日志文件 (/opt/traefik/logs
) 的目录,而不是日志文件本身 (/traefik_access.log
).
volumes:
- /opt/traefik/logs:/logs
我的 logrotate-config for traefik 1.7.4 运行 在容器中,卷安装到“/opt/traefik/logs”:
/opt/traefik/logs/*.log {
daily
rotate 30
missingok
notifempty
compress
dateext
dateformat .%Y-%m-%d
create 0644 root root
postrotate
docker kill --signal="USR1" $(docker ps | grep traefik | awk '{print }')
endscript
}
Log Rotation
Traefik will close and reopen its log files, assuming they're configured, on receipt of a
USR1
signal. This allows the logs to be rotated and processed by an external program, such aslogrotate
.
https://docs.traefik.io/v1.6/configuration/logs/#log-rotation
如果你是 运行 Traefik 在 Docker 容器中,那么你可以这样做:
检查是否安装了 logrotate
logrotate --version
在 /etc/logrotate.d/
中创建文件vi /etc/logrotate.d/traefik
放下面的脚本,不要忘记填写容器名称
/var/log/traefik/*.log {
size 10M
rotate 5
missingok
notifempty
postrotate
docker kill --signal="USR1" <container-name>
endscript
}
运行!
logrotate /etc/logrotate.conf --debug
logrotate /etc/logrotate.conf