简体   繁体   English

如何通过 unix sock 将 haproxy 信息日志发送到 rsyslog?

[英]How to send haproxy info log to rsyslog via unix sock?

Hi i'm trying to config haproxy/rsyslog so that ONLY haproxy info log is sent to ryslog via unix sock.嗨,我正在尝试配置 haproxy/rsyslog,以便只有 haproxy info日志通过 unix 袜子发送到 ryslog。

Here my config:这是我的配置:

haproxy config代理配置

frontend MY_FRONT_END
    log 127.0.0.1 /var/log/haproxy/dev/log info
    bind *:12080
    default_backend HTTP_BACKEND

rsyslog config rsyslog 配置

$ModLoad imuxsock
$InputUnixListenSocketCreatePath on
$InputUnixListenSocketHostName localhost
$AddUnixListenSocket /var/log/haproxy/dev/log
*.info /var/log/haproxy/access.log

However, what i see in the log is not just haproxy log, the log contain all the info that not relate to haproxy (the first three log lines)但是,我在日志中看到的不仅仅是 haproxy 日志,该日志包含所有与 haproxy 无关的信息(前三行日志)

Dec 28 20:28:12 localhost sudo:   testaccount : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/bin/sh -c ip addr show
Dec 28 20:28:12 localhost sudo:   testaccount : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/bin/sh -c ip route
Dec 28 20:28:13 localhost sudo:   testaccount : TTY=pts/1 ; PWD=/var/log/haproxy ; USER=root ; COMMAND=/sbin/service haproxy restart
Dec 28 20:28:13 localhost polkitd[59350]: Registered Authentication Agent for unix-process:32995:43061437 (system bus name :1.28346 [/usr/bin/pkttyagent --notify-fd 5 --fallback], object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_CA.UTF-8)
Dec 28 20:28:13 localhost systemd: Stopping HAProxy Load Balancer...
Dec 28 20:28:13 localhost haproxy: [WARNING] 362/202813 (30706) : Exiting Master process...
Dec 28 20:28:13 localhost haproxy: [NOTICE] 362/202813 (30706) : haproxy version is 2.2.6
Dec 28 20:28:13 localhost haproxy: [NOTICE] 362/202813 (30706) : path to executable is /usr/local/sbin/haproxy
Dec 28 20:28:13 localhost haproxy: [ALERT] 362/202813 (30706) : Current worker #1 (30708) exited with code 143 (Terminated)
Dec 28 20:28:13 localhost haproxy: [WARNING] 362/202813 (30706) : All workers exited. Exiting... (0)
Dec 28 20:28:13 localhost systemd: Starting HAProxy Load Balancer...
Dec 28 20:28:13 localhost haproxy[33016]: Proxy MY_FRONT_END started.
Dec 28 20:28:13 localhost haproxy[33016]: Proxy HTTP_BACKEND started.
Dec 28 20:28:13 localhost haproxy: [NOTICE] 362/202813 (33016) : New worker #1 (33018) forked
Dec 28 20:28:13 localhost systemd: Started HAProxy Load Balancer.
Dec 28 20:28:13 localhost polkitd[59350]: Unregistered Authentication Agent for unix-process:32995:43061437 (system bus name :1.28346, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_CA.UTF-8) (disconnected from bus)
Dec 28 20:28:13 localhost sudo:   testaccount : TTY=pts/1 ; PWD=/var/log/haproxy ; USER=root ; COMMAND=/sbin/service rsyslog restart

How do i config to achieve this (only send haproxy info log to rsyslog through unix sock)?我如何配置来实现这一点(仅通过 unix sock 将 haproxy 信息日志发送到 rsyslog)?

The correct answer is probably to use a ruleset to embrace just the imuxsock part, but I don't know how to do that in legacy syntax.正确的答案可能是使用规则集来包含imuxsock部分,但我不知道如何在遗留语法中做到这一点。

A simpler solution that is less optimal is to check for the programname in the log item.一个不太理想的更简单的解决方案是检查日志项中的程序名。 To also match for severity levels 0 to 6 (emerg to info) gives the result:还要匹配严重级别 0 到 6(从出现到信息)给出结果:

if $programname=="haproxy" and $syslogseverity<=6 then /var/log/haproxy/access.log

I'm not sure, but you could alternatively try just moving your configuration earlier in the file, before the standard logging code, but then your haproxy logs would appear in the standard logs too unless you use something like我不确定,但是您也可以尝试在文件中更早的位置,在标准日志记录代码之前移动您的配置,但是除非您使用类似的东西,否则您的 haproxy 日志也会出现在标准日志中

*.info /var/log/haproxy/access.log
*.* stop

where stop stops further processing of that input.其中stop停止对该输入的进一步处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM