【问题标题】:Rsyslog to direct log messages to local syslog host on port 5000 using TCPRsyslog 使用 TCP 将日志消息定向到端口 5000 上的本地 syslog 主机
【发布时间】:2017-07-10 12:55:40
【问题描述】:

我已经为 rsyslog 配置了以下过滤器,将一些 SSH 消息定向到本地系统上的特定 TCP 端口 5000,以便在 5000 上运行的服务将进一步处理 SSH 消息。

if $fromhost-ip == '127.0.0.1' and ( ($msg contains 'SSH') and ($msg contains 'Test') ) then @@127.0.0.1:5000

一切似乎都很好,但是消息没有重定向到端口 5000,如果我们将消息定向到 UDP 端口,它工作正常。

下面是指向 UDP 端口的消息过滤器。

if $fromhost-ip == '127.0.0.1' and ( ($msg contains 'SSH') and ($msg contains 'Test') ) then @127.0.0.1:5000

能否请您告诉我,为什么 TCP 端口不工作而 UDP 端口工作。

【问题讨论】:

  • 可能有防火墙挡住了路。 telnet 127.0.0.1 5000是连接成功还是报错?
  • @MarkPlotnick,Telnet 工作正常。 root@blr09> telnet 127.0.0.1 5000 正在尝试 127.0.0.1... 连接到 127.0.0.1。转义字符是 '^]'。 ^] 远程登录>
  • 你能验证 rsyslog 确实在监听端口吗? netstat -tnlp | grep rsyslog?然后确保也配置了防火墙(即在 fedora 中):firewall-cmd --zone=zone --add-port=5000/tcp
  • @arash,rsyslog 正在 UDP 端口上运行。 root@blr09> netstat -nlp | grep rsyslog udp 0 0 0.0.0.0:27129 0.0.0.0:* 11218/rsyslogd udp 0 0 0.0.0.0:29046 0.0.0.0:* 11218/rsyslogd

标签: linux syslog rsyslog


【解决方案1】:

我认为您可以为此使用隧道。例如

ssh username@serverAddress -L 5000:11.22.33.44:80

    # username - username on server
    # serverAddress - server address
    # 8080: - port on the local machine that will be opened on loopback interface (127.0.0.1)
    # 11.22.33.44 - IP address of the server that we'll create a tunnel to using SSH

在这里查看更多信息:https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-tunneling-on-a-vps

我希望这会有所帮助!

【讨论】:

    【解决方案2】:

    您可能决定使用 RELP 吗? (https://en.wikipedia.org/wiki/Reliable_Event_Logging_Protocol)

    https://linux.die.net/man/5/rsyslog.conf所述

    你需要更换你的 “然后@127.0.0.1:5000” 到 "那么:omrelp:127.0.0.1:5000"

    【讨论】:

    • 当我添加 omrelp 并重新启动 rsyslog 时出现以下错误。 “3 月 2 日 04:40:31 blr09 rsyslogd-2207:在第 1 行或之前解析文件 /etc/rsyslog.d/atl_security.conf 时出错:文件 '/etc/rsyslog.d/atl_security.conf' 中发生错误第 1 行附近 [try rsyslog.com/e/2207]" root@blr09> cat /etc/rsyslog.d/atl_security.conf if $fromhost-ip == '127.0.0.1' and (($msg contains 'SSH') and ($ msg 包含 'Test') ) 然后 :omrelp:127.0.0.1:5000 root@blr09>
    • 能否提供rsyslogd -v的输出
    • root@blr09> rsyslogd -v rsyslogd 7.4.7,编译:FEATURE_REGEXP:是 FEATURE_LARGEFILE:不支持 GSSAPI Kerberos 5:是 FEATURE_DEBUG(调试构建,慢代码):不支持 32 位原子操作:是 支持 64 位原子操作:是 运行时检测(慢代码):不支持 uuid:是 有关更多信息,请参阅 rsyslog.com。 root@blr09>
    • 嗯!我想你使用v8。好的,让我们从头开始rsyslog.com/doc/v7-stable/configuration/index.html 据我了解,您需要另一个替换:“然后@@127.0.0.1:5000”
    • 能否请您详细解释一下替换的情况。
    猜你喜欢
    • 1970-01-01
    • 2019-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-22
    • 2019-09-27
    • 2017-05-31
    相关资源
    最近更新 更多