3 Star 6 Fork 4

winlinvip / srs.wiki

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
v3_EN_LogRotate.md 1.86 KB
一键复制 编辑 原始数据 按行查看 历史
winlinvip 提交于 2022-01-06 11:57 . Update

HOME > EN > Log Rotate

LogRotate

SRS always writes log to a single log file srs.log, so it will become very larger. We can use rotate the log to zip or remove it.

  1. First, move the log file to another tmp log file:mv objs/srs.log /tmp/srs.`date +%s`.log
  2. Then, send signal to SRS. SRS will close the previous file fd and reopen the log file:killall -s SIGUSR1
  3. Finally, zip or remove the tmp log file.

Use logrotate

Recommend to use logrotate to manage log files.

  1. Install logrotate:
sudo yum install -y logrotate
  1. Config logrotate to manage SRS log file:
cat << END > /etc/logrotate.d/srs
/usr/local/srs/objs/srs.log {
    daily
    dateext
    compress
    rotate 7
    size 1024M
    sharedscripts
    postrotate
        kill -USR1 \`cat /usr/local/srs/objs/srs.pid\`
    endscript
}
END

Note: Run logrotate manually by logrotate -f /etc/logrotate.d/srs

CopyTruncate

For SRS2, we could use copytruncate, but it's strongly not recommended because the logs maybe dropped, so it's only a workaround for server not supported SIGUSR1 such as SRS2.

Yes, SRS3 surely supports copytruncate and it's not recommended.

The config is bellow, from PR#1561 by wnpllrzodiac:

cat << END > /etc/logrotate.d/srs
/usr/local/srs/objs/srs.log {
    daily
    dateext
    compress
    rotate 7
    size 1024M
    copytruncate
}
END

Winlin 2016.12

1
https://gitee.com/winlinvip/srs-wiki.git
git@gitee.com:winlinvip/srs-wiki.git
winlinvip
srs-wiki
srs.wiki
master

搜索帮助