How to enable logrotation for traefik?

别等时光非礼了梦想. 提交于 2020-05-26 06:36:38

问题


How do I enable log rotation for log files e.g. access.log.

Is this built in ?

Docs only say "This allows the logs to be rotated and processed by an external program, such as logrotate"


回答1:


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




回答2:


If you are running Traefik in a Docker container then you can do something like this:

Check that logrotate is installed

logrotate --version

Create file in /etc/logrotate.d/

vi /etc/logrotate.d/traefik

Put the following script, do not forget to fill with the container name.

/var/log/traefik/*.log {
  size 10M
  rotate 5
  missingok
  notifempty
  postrotate
    docker kill --signal="USR1" <container-name>
  endscript
}

Run!

logrotate /etc/logrotate.conf --debug 
logrotate /etc/logrotate.conf



回答3:


It seems like theres no logrotation built-in so i enabled logration on the Host that the access.log is mounted to.

My logrotate-config for traefik 1.7.4 running in a container with volume mount to "/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 $1}')
  endscript
 }


来源:https://stackoverflow.com/questions/49450422/how-to-enable-logrotation-for-traefik

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!