HAPROXY:显示从外部检查脚本到 rsyslog 的日志消息
HAPROXY: Display log messages from external check script to rsyslog
我想从 HAPROXY 的外部检查脚本打印一些日志消息到 rsyslog。
现在,我在我的 external-check.sh 脚本中使用了“echo”,但它没有显示回显消息。它只显示 haproxy 日志消息。
这可能吗?
haproxy.cfg
的内容:
global
log 127.0.0.1 local0
external-check
insecure-fork-wanted
defaults
mode http
log global
option httplog
timeout queue 1m
timeout connect 10m
timeout client 1m
timeout server 10m
timeout http-keep-alive 10s
timeout check 10m
timeout tunnel 10m
maxconn 2048
frontend pa
bind *:443
use_backend back-servers
backend back-servers
option external-check
option log-health-checks
external-check command /etc/haproxy/external-check.sh
server PA-A xxx check inter 30s fall 6 rise 1 ssl verify none
server PA-B xxx backup check inter 30s fall 6 rise 1 ssl verify none
/etc/rsyslog.d/haproxy.conf
的内容
$ModLoad imudp
$UDPServerRun 514
$template Haproxy,"%msg%\n"
local0.* -/var/log/haproxy.log
日志输出示例:
Health check for server back-servers/PA-A failed, reason: External check timeout, code: 1, check duration: 30009ms, status: 0/1 DOWN.
Health check for server back-servers/PA-A failed, reason: External check error, code: 1, check duration: 738ms, status: 0/1 DOWN.
Health check for backup server back-servers/PA-B failed, reason: External check timeout, code: 1, check duration: 30022ms, status: 0/1 DOWN.
Health check for backup server back-servers/PA-B failed, reason: External check error, code: 1, check duration: 1590ms, status: 0/1 DOWN
如您所见,我添加到外部检查脚本中的“回显”没有打印消息
我得到了答案:
目前,我正在使用 echo
,但我应该使用 logger
通过 127.0.0.1
将消息从外部脚本记录到 rsyslog 套接字。默认情况下,HAPROXY 不会为我们做这件事。它仅重定向 haproxy.cfg
事件的日志消息,而不重定向外部脚本消息。
诀窍是将所有 echo
消息替换为:
logger -p local0.info -t external-script -n 127.0.0.1 "My message"
我想从 HAPROXY 的外部检查脚本打印一些日志消息到 rsyslog。 现在,我在我的 external-check.sh 脚本中使用了“echo”,但它没有显示回显消息。它只显示 haproxy 日志消息。 这可能吗?
haproxy.cfg
的内容:
global
log 127.0.0.1 local0
external-check
insecure-fork-wanted
defaults
mode http
log global
option httplog
timeout queue 1m
timeout connect 10m
timeout client 1m
timeout server 10m
timeout http-keep-alive 10s
timeout check 10m
timeout tunnel 10m
maxconn 2048
frontend pa
bind *:443
use_backend back-servers
backend back-servers
option external-check
option log-health-checks
external-check command /etc/haproxy/external-check.sh
server PA-A xxx check inter 30s fall 6 rise 1 ssl verify none
server PA-B xxx backup check inter 30s fall 6 rise 1 ssl verify none
/etc/rsyslog.d/haproxy.conf
$ModLoad imudp
$UDPServerRun 514
$template Haproxy,"%msg%\n"
local0.* -/var/log/haproxy.log
日志输出示例:
Health check for server back-servers/PA-A failed, reason: External check timeout, code: 1, check duration: 30009ms, status: 0/1 DOWN.
Health check for server back-servers/PA-A failed, reason: External check error, code: 1, check duration: 738ms, status: 0/1 DOWN.
Health check for backup server back-servers/PA-B failed, reason: External check timeout, code: 1, check duration: 30022ms, status: 0/1 DOWN.
Health check for backup server back-servers/PA-B failed, reason: External check error, code: 1, check duration: 1590ms, status: 0/1 DOWN
如您所见,我添加到外部检查脚本中的“回显”没有打印消息
我得到了答案:
目前,我正在使用 echo
,但我应该使用 logger
通过 127.0.0.1
将消息从外部脚本记录到 rsyslog 套接字。默认情况下,HAPROXY 不会为我们做这件事。它仅重定向 haproxy.cfg
事件的日志消息,而不重定向外部脚本消息。
诀窍是将所有 echo
消息替换为:
logger -p local0.info -t external-script -n 127.0.0.1 "My message"