我想从HAPROXY的外部检查脚本打印一些日志消息到rsyslog。目前,我在external-check.sh脚本中使用"echo",但它不会显示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
正如你所看到的,没有我的";回声;(s( 我已经添加到外部检查脚本中
我得到了答案:
目前,我使用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"