gpt4 book ai didi

java - 在 rsyslog 中启用日志轮换

转载 作者:行者123 更新时间:2023-12-05 05:42:14 24 4
gpt4 key购买 nike

如何在 rsyslog 配置中启用日志轮换。 rsyslog 官方文档中描述的使用输出 channel 的方法对我不起作用。

rsyslog 官方文档中给出的用于输出 channel 的脚本可在此处获得: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")

这是我正在使用的代码片段。我还尝试在规则集中添加代码的输出 channel 部分(在操作语句之后)。

我的日志轮换脚本:mv -f/logs/prismaudit.log/logs/log_rotation.log.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

关于java - 在 rsyslog 中启用日志轮换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72095695/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com