【发布时间】:2022-07-13 14:34:21
【问题描述】:
如何在 rsyslog 配置中启用日志轮换。 rsyslog官方文档中描述的使用输出通道的方法对我不起作用。
rsyslog 官方文档中给出的输出通道脚本在这里:https://www.rsyslog.com/doc/master/tutorials/log_rotation_fix_size.html
module(load="imudp" TimeRequery="500")
module(load="omstdout")
module(load="omelasticsearch")
module(load="mmjsonparse")
module(load="mmutf8fix")
ruleset(name="prismaudit_rs") {
action(type="omfile" dirCreateMode="0777" fileCreateMode="0777" file="/logs/prismaudit.log")
}
$outchannel log_rotation,/logs/prismaudit.log, 3000,/etc/log_rotation_script
*.* :omfile:$log_rotation
#input(type="imptcp" port="514")
input(type="imudp" port="514" ruleset="prismaudit_rs")
这是我正在使用的代码的 sn-p。我还尝试在规则集中添加代码的输出通道部分(在操作语句之后)。
我的日志轮换脚本: mv -f /logs/prismaudit.log /logs/log_rotation.log.1
【问题讨论】:
-
@Dan 我已经在我的问题中添加了它。
-
请将
/etc/log_rotation_script的内容添加到您的问题中。 -
另外,您的 logrotation 语句中的文件大小 (3000) 以 bytes 为单位定义。所以它会在文件大小达到 3000 字节 或 3 KB 后旋转文件。
-
@eDonkey 上面添加的脚本是 /etc/log_rotation_script。此外,文件在 3kb 大小后没有旋转,更多数据被转储到同一个文件中。
-
@KumarRounak 我有确切的问题,你有好的解决方案吗?
标签: java rsyslog logrotate log-rotation