日誌分割工具logrotate

日誌分割工具logrotate

nginx
tee /etc/logrotate.d/nginx <<-EOF
/data/wwwlogs/*main.log {
  daily
  rotate 5
  missingok
  dateext
  compress
  notifempty
  sharedscripts
  postrotate
    [ -e /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`
  endscript
}
EOF
other tools
tee /etc/logrotate.d/mymon <<-EOF
/home/work/gopath/src/github.com/open-falcon/mymon/mymon.log {
  daily
  rotate 5
  missingok
  dateext
  compress
  notifempty
  sharedscripts
  postrotate
  endscript
}
EOF
logrotate -d /etc/logrotate.d/mymon             #測試
logrotate -vf /etc/logrotate.d/mymon            #強制執行
簡單說明參數
daily                 #每日執行,weekly,yearly
  rotate 5              #保存幾份
  missingok             #忽略logrotate執行時的錯誤
  dateext               #日期方式命令保存的文件
  compress              #壓縮
  notifempty            #檢查日誌文件是否爲空,空不執行
  sharedscripts         
  postrotate            #其餘命令
相關文章
相關標籤/搜索