rsyslog omfile写入失败

发布于 2022-09-12 02:44:30 字数 2257 浏览 11 评论 0

问题描述

我配置了local0级别的消息全部都往/root/workspace/local1中写入,同时使用imfile的input读取/root/workspace/local1的内容并写入到/root/workspace/local2文件中

问题现象:
local1中每次运行php脚本都可以看到结果,但是local2中只有每次启动的一瞬间才会有数据写入,之后没有任何改变。

相关代码

rsyslog配置信息

$ModLoad imuxsock 
module(load = "mmjsonparse")
module(load="imfile" )
module(load="omuxsock")
module(load="omfile")

$DebugFile /var/log/rsyslog.debug
$DebugLevel 1

global(WorkDirectory = "/data1/rsyslog/workdir")

template (
  name = "msg_with_control_flags_tpl"
  type = "string"
  string = "<%pri%>%timereported% %$.control_flags% %syslogtag% %$!%\n"
)

if $syslogfacility-text == 'local0' then {
    call rule1
}

ruleset(name="rule1") {
 action(type="omfile" file="/root/workspace/local1")
}

input(type="imfile" file="/root/workspace/local1" Ruleset="rule2" tag="file" Facility="local1")

ruleset(name="rule2") {
action(type="omfile" file="/root/workspace/local2" ioBufferSize = "64K" template="msg_with_control_flags_tpl" dirCreateMode="0700" FileCreateMode="0644")
}

php的测试脚本

<?php
 openlog('USER-LOG', LOG_PID, LOG_LOCAL0);
 syslog(LOG_INFO, 'ERROR!!!');

问题出现的平台版本及自己尝试过哪些方法

rsyslog版本信息

rsyslogd  8.2004.0 (aka 2020.04) compiled with:
        PLATFORM:                               x86_64-redhat-linux-gnu
        PLATFORM (lsb_release -d):
        FEATURE_REGEXP:                         Yes
        GSSAPI Kerberos 5 support:              No
        FEATURE_DEBUG (debug build, slow code): No
        32bit Atomic operations supported:      Yes
        64bit Atomic operations supported:      Yes
        memory allocator:                       system default
        Runtime Instrumentation (slow code):    No
        uuid support:                           Yes
        systemd support:                        No
        Config file:                            /etc/rsyslog.conf
        PID file:                               /var/run/syslogd.pid
        Number of Bits in RainerScript integers: 64

See https://www.rsyslog.com for more information.

系统发型版本

CentOS release 6.7 (Final)
Kernel \r on an \m

你期待的结果是什么?实际看到的错误信息又是什么?

local2文件有更新

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墟烟 2022-09-19 02:44:30

补充未提到的信息,centos运行在docker中

问题原因

该问题大概率是由于imfile默认使用ifnotiy方式来获取文件更新信息,而docker对于非挂载目录无法获取到更新,导致问题。

解决方案

  1. 将要监听的文件放在挂载目录下
  2. 使用poll方式来获取更新
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文