【问题标题】:Enable log rotation in rsyslog在 rsyslog 中启用日志轮换
【发布时间】: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


【解决方案1】:

首先,我认为您误解了那里的某些内容,应该再次阅读文档。

日志轮换不起作用,因为您当前在/etc/log_rotation_script 中的内容应该在/etc/rsyslog.conf/etc/rsydlog.d/filename.conf 中,因为在那里处理了rsyslog 的配置。

/etc/log_rotation_script 的唯一目的是将“完整”(当前达到 3KB 的限制)文件移动到另一个文件/位置。


它看起来像:

/etc/rsyslog.conf(简体)

# Load modules
module(load="imudp")

# Set the default permissions for all log files
module(load="builtin:omfile"
    fileOwner="root"
    fileGroup="adm"
    fileCreateMode="0777"
    dirCreateMode="0777")

# Receive logs over udp from somewhere
input(type="imudp" address="127.0.0.1" port="514")

# log everything to /logs/prismaudit.log by using the output channel
*.* :omfile:$log_rotation

# If max file size (50MB) is reached execute /path/to/log_rotation_script
$outchannel log_rotation,/logs/prismaudit.log, 52428800,/path/to/log_rotation_script

/path/to/log_rotation_script

# move original log to (a kind of) backup log file
mv -f /logs/prismaudit.log /logs/prismaudit.log.1

编辑:

另一个问题是:“这行:*.* :omfile:$log_rotation 如何确保将日志写入/logs/prismaudit.log?”

这一行(1)

`*.* :omfile:$log_rotation` 

还有这一 (2) 个:

action(type="omfile" file="/logs/prismaudit.log")

正在做一些完全不同的事情,除了两者都将日志写入同一个文件。

第一行 (1) 使用 输出通道。输出通道只能写入文件并携带filename(内容被写入的地方)、maximum file sizecommand,当达到此文件大小时发出。

第二行 (2) 是一个动作,可用于各种任务。但在这种情况下,它只是写入file 参数中描述的文件。

【讨论】:

  • 嘿,我错误地告诉了关于日志轮换脚本的事情。我已经用日志轮换脚本更新了这个问题。另外,还有一个疑问:这行:. :omfile:$log_rotation 如何确保将 flog 写入 /logs/prismaudit.log 位置。
猜你喜欢
  • 2013-09-30
  • 1970-01-01
  • 2015-10-15
  • 2014-02-19
  • 1970-01-01
  • 2020-07-15
  • 2017-03-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多