我正在尝试在 HA 集群中将 syslog-ng 作为 OCF 资源运行。我遇到了一些非常奇怪的行为 - 当我在调试模式下启动单个实例时,过滤器匹配并且它会正确转发。但是,当我删除调试标志时,它只匹配两个过滤器中的一个。因此,它的工作原理如下(主机名和 IP 已被删除):
# pcs status
Cluster name: fwdr
Stack: corosync
Current DC: fwdr-secondary (version 1.1.19-8.el7_6.4-c3c624ea3d) - partition with quorum
Last updated: Thu Sep 5 11:50:18 2019
Last change: Thu Sep 5 10:27:51 2019 by root via cibadmin on fwdr-primary
2 nodes configured
2 resources configured
Online: [ fwdr-primary fwdr-secondary ]
Full list of resources:
virtual_ip (ocf::heartbeat:IPaddr2): Started fwdr-primary
syslog-ng (ocf::heartbeat-git:syslog-ng): Started fwdr-primary
Daemon Status:
corosync: active/enabled
pacemaker: active/enabled
pcsd: active/enabled
syslog-ng.conf:
@version: 3.5
source incoming {
udp(
ip("VIP")
port(514)
flags(no-parse)
);
tcp(
ip("VIP")
port(514)
flags(no-parse)
);
};
filter pi_duplication {
netmask("someip/32")
or netmask("someip/32")
or netmask("someip/32")
...a bunch of these...
or netmask("someip/32")
};
destination dl {
udp(
"<REDACTED:dl hostname>"
port(514)
spoof_source(yes)
template( "${MESSAGE}\n" )
);
};
destination ci {
tcp(
"<REDACTED:ci hostname>"
port(11468)
template( "${MESSAGE}\n" )
);
};
log {
source(incoming);
filter(pi);
destination(ci);
};
现在,禁用 syslog-ng 资源:
# pcs resource disable syslog-ng
...
Full list of resources:
virtual_ip (ocf::heartbeat:IPaddr2): Started fwdr-primary
syslog-ng (ocf::heartbeat-git:syslog-ng): Stopped (disabled)
现在以调试模式启动它:
# syslog-ng -f /etc/syslog-ng/syslog-ng.conf --foreground --debug
Reading path for candidate modules; path='//usr/lib64/syslog-ng'
...
Compiling #unnamed sequence [log] at [/etc/syslog-ng/syslog-ng.conf:6]
Compiling incoming reference [source] at [/etc/syslog-ng/syslog-ng.conf:6]
Compiling incoming sequence [source] at [/etc/syslog-ng/syslog-ng.conf:3]
Compiling #unnamed junction [log] at [/etc/syslog-ng/syslog-ng.conf:3]
Compiling #unnamed single [log] at [/etc/syslog-ng/syslog-ng.conf:4]
Compiling #unnamed single [log] at [/etc/syslog-ng/syslog-ng.conf:1]
Compiling pi_duplication reference [filter] at [/etc/syslog-ng/syslog-ng.conf:6]
Compiling pi_duplication sequence [filter] at [/etc/syslog-ng/syslog-ng.conf:1]
Compiling #unnamed single [log] at [/etc/syslog-ng/syslog-ng.conf:1]
Compiling ci reference [destination] at [/etc/syslog-ng/syslog-ng.conf:6]
Compiling ci sequence [destination] at [/etc/syslog-ng/syslog-ng.conf:5]
Compiling #unnamed junction [log] at [/etc/syslog-ng/syslog-ng.conf:5]
Compiling #unnamed single [log] at [/etc/syslog-ng/syslog-ng.conf:5]
Compiling #unnamed sequence [log] at [/etc/syslog-ng/syslog-ng.conf:7]
Compiling incoming reference [source] at [/etc/syslog-ng/syslog-ng.conf:7]
Compiling dl reference [destination] at [/etc/syslog-ng/syslog-ng.conf:7]
Compiling dl sequence [destination] at [/etc/syslog-ng/syslog-ng.conf:4]
Compiling #unnamed junction [log] at [/etc/syslog-ng/syslog-ng.conf:4]
Compiling #unnamed single [log] at [/etc/syslog-ng/syslog-ng.conf:5]
Syslog connection established; fd='9', server='AF_INET(<REDACTED:dl host's IP>:514)', local='AF_INET(0.0.0.0:0)'
Running application hooks; hook='1'
Running application hooks; hook='3'
syslog-ng starting up; version='3.5.6'
Syslog connection established; fd='8', server='AF_INET(<REDACTED:is host's IP>:11468)', local='AF_INET(0.0.0.0:0)'
Syslog connection accepted; fd='16', client='AF_INET(<REDACTED:ci host's IP>:47876)', local='AF_INET(10.68.233.48:514)'
Incoming log entry; line='<REDACTED>'
Filter rule evaluation begins; rule='pi_duplication', location='/etc/syslog-ng/syslog-ng.conf:17:32'
Filter node evaluation result; result='not-match'
Filter node evaluation result; result='not-match'
Filter node evaluation result; result='not-match', type='OR'
Filter node evaluation result; result='not-match'
Filter node evaluation result; result='not-match', type='OR'
Filter node evaluation result; result='not-match'
Filter node evaluation result; result='not-match', type='OR'
...repeated...
Filter node evaluation result; result='not-match'
Filter node evaluation result; result='not-match', type='OR'
Filter node evaluation result; result='match'
Filter node evaluation result; result='match', type='OR'
Filter node evaluation result; result='match', type='OR'
Filter node evaluation result; result='match', type='OR'
Filter node evaluation result; result='match', type='OR'
Filter node evaluation result; result='match', type='OR'
Filter node evaluation result; result='match', type='OR'
Filter rule evaluation result; result='match', rule='pi_duplication', location='/etc/syslog-ng/syslog-ng.conf:17:32'
依此类推,每条传入线路都匹配并正确发送到两个目标。流量示例,其中源是生成主机,目标是 ci 主机,myvip 是我监听的 VIP,myrealip 是 fwdr-primary 的真实 IP:
# tcpdump -nn -i enp15s0f0 "port 514 or port 11468"
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on enp15s0f0, link-type EN10MB (Ethernet), capture size 262144 bytes
12:03:14.545138 IP source.48100 > myvip.514: Flags [P.], seq 2372587949:2372588369, ack 3533250116, win 29, length 420
12:03:14.545185 IP myvip.514 > source.48100: Flags [R], seq 3533250116, win 0, length 0
12:03:15.227043 IP source.48112 > myvip.514: Flags [S], seq 2965678208, win 14600, options [mss 1460,nop,nop,sackOK,nop,wscale 9], length 0
12:03:15.227107 IP myvip.514 > source.48112: Flags [S.], seq 280396112, ack 2965678209, win 29200, options [mss 1460,nop,nop,sackOK,nop,wscale 7], length 0
12:03:15.260720 IP source.48112 > myvip.514: Flags [.], ack 1, win 29, length 0
12:03:15.260773 IP source.48112 > myvip.514: Flags [P.], seq 1:401, ack 1, win 29, length 400
12:03:15.260796 IP myvip.514 > source.48112: Flags [.], ack 401, win 237, length 0
12:03:15.262926 IP source.48112 > dlhost.514: SYSLOG local0.info, length: 400
12:03:15.263037 IP myrealip.41003 > destination.11468: Flags [P.], seq 2022253190:2022253590, ack 3273547315, win 229, options [nop,nop,TS val 3195491935 ecr 501321261], length 400
12:03:15.263175 IP destination.11468 > myrealip.41003: Flags [.], ack 400, win 235, options [nop,nop,TS val 501331496 ecr 3195491935], length 0
现在,重新启用集群资源:
# pcs resource enable syslog-ng
现在网络一片沉寂:
12:08:24.610741 IP source.48240 > myvip.514: Flags [S], seq 3387574314, win 14600, options [mss 1460,nop,nop,sackOK,nop,wscale 9], length 0
12:08:24.610796 IP myvip.514 > source.48240: Flags [S.], seq 2754922833, ack 3387574315, win 29200, options [mss 1460,nop,nop,sackOK,nop,wscale 7], length 0
12:08:24.644579 IP source.48240 > myvip.514: Flags [.], ack 1, win 29, length 0
12:09:01.941077 IP source.48240 > myvip.514: Flags [P.], seq 1:484, ack 1, win 29, length 483
12:09:01.941127 IP myvip.514 > source.48240: Flags [.], ack 484, win 237, length 0
12:09:01.942064 IP source.48240 > dlhost.514: SYSLOG local0.info, length: 483
(直接从源 > dlhost 发来的数据包是我在 dl 规则上欺骗源的地方)。换句话说,在集群下运行时的跟踪显示它仅匹配 dl 规则,而在调试模式下在前台运行时则正确匹配两个规则!这使得调试非常困难,我无法弄清楚发生了什么。
答案1
从您的 syslog-ng 版本来看,我猜测您正在 RHEL/CentOS 7 上使用来自 EPEL 的 syslog-ng。
现在无法验证,但我有一些遥远的记忆,当 syslog-ng 从 systemd 启动时,SELinux 会阻止网络连接。您应该检查您的审计日志,看看是否有任何与 syslog-ng 相关的内容。
我关于这个主题的博客可能会有所帮助:https://www.syslog-ng.com/community/b/blog/posts/using-syslog-ng-with-selinux-in-enforcing-mode