Zabbix Server behind HAProxy



嗨,我的zabbix服务器基础设施看起来像这样:

两个Zabbix服务器位于主动/被动模式下的HAProxy服务器后面。HAPROXY的一部分.cfg来自HAProxy服务器之一。

frontend ha-monit-app
bind :10051
mode tcp
default_backend monit-app
backend monit-app
server monit-app-01 10.164.0.10:10051 check
server monit-app-02 10.156.0.10:10051 check backup

有两个具有相同配置的HAProxy服务器,并使用故障转移IP172.31.255.254进行交换,我已经检查了nmap和ping是否可以从其他节点获得故障转移ip,特别是来自zabbix Web服务器(前端(,以下是这些结果:

PING 172.31.255.254 (172.31.255.254) 56(84) bytes of data.
64 bytes from 172.31.255.254: icmp_seq=1 ttl=64 time=1.43 ms
64 bytes from 172.31.255.254: icmp_seq=2 ttl=64 time=0.284 ms
64 bytes from 172.31.255.254: icmp_seq=3 ttl=64 time=0.326 ms
64 bytes from 172.31.255.254: icmp_seq=4 ttl=64 time=0.306 ms
64 bytes from 172.31.255.254: icmp_seq=5 ttl=64 time=0.277 ms
--- 172.31.255.254 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4054ms
rtt min/avg/max/mdev = 0.277/0.525/1.433/0.454 ms

nmap -Pn -p 10051 172.31.255.254

Starting Nmap 7.40 ( https://nmap.org ) at 2018-06-15 00:59 CEST
Nmap scan report for 172.31.255.254
Host is up (0.0012s latency).
PORT STATE SERVICE
10051/tcp open zabbix-trapper
Nmap done: 1 IP address (1 host up) scanned in 0.29 seconds
telnet 172.31.255.254 10051
Trying 172.31.255.254...
Connected to 172.31.255.254.
Escape character is '^]'.
^CConnection closed by foreign host.

所以一切看起来都不错。这就是为什么在zabbix.conf的前端服务器上.php我设置了以下值:

$ZBX_SERVER         = '172.31.255.254';
$ZBX_SERVER_PORT    = '10051';
$ZBX_SERVER_NAME    = 'Zabbix GCP HAProxy';

但我看到这在前端根本不起作用 这是一个Zabbix前端/Zabbix服务器的状态

我正在添加 tcpdump

=========== tcpdump ==============
Listening on Active HAProxy (10.164.0.3 / 172.31.255.254 Floating IP) for Active Zabbix Server (monit-app-01 - 10.156.0.10) 
tcpdump -n host 10.156.0.10
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
10:11:44.301714 IP 10.164.0.3.60374 > 10.156.0.10.10051: Flags [S], seq 904325550, win 28400, options [mss 1420,sackOK,TS val 11110278 ecr 0,nop,wscale 7], length 0
10:11:44.308930 IP 10.156.0.10.10051 > 10.164.0.3.60374: Flags [S.], seq 1332485152, ack 904325551, win 28160, options [mss 1420,sackOK,TS val 12859862 ecr 11110278,nop,wscale 7], length 0
10:11:44.309007 IP 10.164.0.3.60374 > 10.156.0.10.10051: Flags [R.], seq 1, ack 1, win 222, options [nop,nop,TS val 11110280 ecr 12859862], length 0
10:11:46.309574 IP 10.164.0.3.60378 > 10.156.0.10.10051: Flags [S], seq 355584253, win 28400, options [mss 1420,sackOK,TS val 11110780 ecr 0,nop,wscale 7], length 0
10:11:46.316691 IP 10.156.0.10.10051 > 10.164.0.3.60378: Flags [S.], seq 3081623376, ack 355584254, win 28160, options [mss 1420,sackOK,TS val 12860364 ecr 11110780,nop,wscale 7], length 0
10:11:46.316769 IP 10.164.0.3.60378 > 10.156.0.10.10051: Flags [R.], seq 1, ack 1, win 222, options [nop,nop,TS val 11110782 ecr 12860364], length 0

Listening on Active HAProxy (10.164.0.3 / 172.31.255.254 Floating IP) for Zabbix Frontend (monit-front-01 - 10.164.0.7)
sudo tcpdump -n host 10.164.0.7
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
10:18:44.549679 IP 10.164.0.7.56084 > 172.31.255.254.10051: Flags [S], seq 3124977895, win 28400, options [mss 1420,sackOK,TS val 10621333 ecr 0,nop,wscale 7], length 0
10:18:44.549729 IP 172.31.255.254.10051 > 10.164.0.7.56084: Flags [S.], seq 1251960166, ack 3124977896, win 28160, options [mss 1420,sackOK,TS val 11215340 ecr 10621333,nop,wscale 7], length 0
10:18:44.550406 IP 10.164.0.7.56084 > 172.31.255.254.10051: Flags [.], ack 1, win 222, options [nop,nop,TS val 10621334 ecr 11215340], length 0
10:18:44.550576 IP 10.164.0.7.56084 > 172.31.255.254.10051: Flags [P.], seq 1:80, ack 1, win 222, options [nop,nop,TS val 10621334 ecr 11215340], length 79
10:18:44.550587 IP 172.31.255.254.10051 > 10.164.0.7.56084: Flags [.], ack 80, win 220, options [nop,nop,TS val 11215340 ecr 10621334], length 0
10:18:44.550620 IP 172.31.255.254.10051 > 10.164.0.7.56084: Flags [F.], seq 1:189, ack 80, win 220, options [nop,nop,TS val 11215340 ecr 10621334], length 188
10:18:44.550843 IP 10.164.0.7.56084 > 172.31.255.254.10051: Flags [F.], seq 80, ack 190, win 231, options [nop,nop,TS val 10621334 ecr 11215340], length 0
10:18:44.550849 IP 172.31.255.254.10051 > 10.164.0.7.56084: Flags [.], ack 81, win 220, options [nop,nop,TS val 11215340 ecr 10621334], length 0
10:18:47.820231 IP 10.164.0.7.56092 > 172.31.255.254.10051: Flags [S], seq 3701025043, win 28400, options [mss 1420,sackOK,TS val 10622151 ecr 0,nop,wscale 7], length 0
10:18:47.820304 IP 172.31.255.254.10051 > 10.164.0.7.56092: Flags [S.], seq 3543291301, ack 3701025044, win 28160, options [mss 1420,sackOK,TS val 11216157 ecr 10622151,nop,wscale 7], length 0
10:18:47.820562 IP 10.164.0.7.56092 > 172.31.255.254.10051: Flags [.], ack 1, win 222, options [nop,nop,TS val 10622151 ecr 11216157], length 0
10:18:47.820665 IP 10.164.0.7.56092 > 172.31.255.254.10051: Flags [P.], seq 1:80, ack 1, win 222, options [nop,nop,TS val 10622151 ecr 11216157], length 79
10:18:47.820672 IP 172.31.255.254.10051 > 10.164.0.7.56092: Flags [.], ack 80, win 220, options [nop,nop,TS val 11216158 ecr 10622151], length 0
10:18:47.820707 IP 172.31.255.254.10051 > 10.164.0.7.56092: Flags [F.], seq 1:189, ack 80, win 220, options [nop,nop,TS val 11216158 ecr 10622151], length 188
10:18:47.820947 IP 10.164.0.7.56092 > 172.31.255.254.10051: Flags [F.], seq 80, ack 190, win 231, options [nop,nop,TS val 10622151 ecr 11216158], length 0
10:18:47.820957 IP 172.31.255.254.10051 > 10.164.0.7.56092: Flags [.], ack 81, win 220, options [nop,nop,TS val 11216158 ecr 10622151], length 0

我在代理中得到NOSRV.log

=============== HAProxy =============
Jun 15 10:34:49 ha-monit-app-01-6zxn haproxy[1471]: 10.164.0.7:58088 [15/Jun/2018:10:34:49.680] ha-monit-app monit-app/<NOSRV> -1/-1/0 188 PR 0/0/0/0/3 0/0
Jun 15 10:34:50 ha-monit-app-01-6zxn haproxy[1471]: 10.164.0.7:58096 [15/Jun/2018:10:34:50.646] ha-monit-app monit-app/<NOSRV> -1/-1/0 188 PR 0/0/0/0/3 0/0
Jun 15 10:35:00 ha-monit-app-01-6zxn haproxy[1471]: 10.164.0.7:58112 [15/Jun/2018:10:35:00.927] ha-monit-app monit-app/<NOSRV> -1/-1/0 188 PR 1/1/1/0/3 0/0
Jun 15 10:35:00 ha-monit-app-01-6zxn haproxy[1471]: 10.164.0.7:58110 [15/Jun/2018:10:35:00.927] ha-monit-app monit-app/<NOSRV> -1/-1/0 188 PR 0/0/0/0/3 0/0
Jun 15 10:35:11 ha-monit-app-01-6zxn haproxy[1471]: 10.164.0.7:58130 [15/Jun/2018:10:35:11.839] ha-monit-app monit-app/<NOSRV> -1/-1/0 188 PR 0/0/0/0/3 0/0
Jun 15 10:35:11 ha-monit-app-01-6zxn haproxy[1471]: 10.164.0.7:58132 [15/Jun/2018:10:35:11.853] ha-monit-app monit-app/<NOSRV> -1/-1/0 188 PR 0/0/0/0/3 0/0
Jun 15 10:35:22 ha-monit-app-01-6zxn haproxy[1471]: 10.164.0.7:58150 [15/Jun/2018:10:35:22.672] ha-monit-app monit-app/<NOSRV> -1/-1/0 188 PR 1/1/1/0/3 0/0
Jun 15 10:35:22 ha-monit-app-01-6zxn haproxy[1471]: 10.164.0.7:58148 [15/Jun/2018:10:35:22.672] ha-monit-app monit-app/<NOSRV> -1/-1/0 188 PR 0/0/0/0/3 0/0
Jun 15 10:35:32 ha-monit-app-01-6zxn haproxy[1471]: 10.164.0.7:58182 [15/Jun/2018:10:35:32.712] ha-monit-app monit-app/<NOSRV> -1/-1/0 188 PR 0/0/0/0/3 0/0
Jun 15 10:35:33 ha-monit-app-01-6zxn haproxy[1471]: 10.164.0.7:58196 [15/Jun/2018:10:35:33.793] ha-monit-app monit-app/<NOSRV> -1/-1/0 188 PR 0/0/0/0/3 0/0
Jun 15 10:35:43 ha-monit-app-01-6zxn haproxy[1471]: 10.164.0.7:58204 [15/Jun/2018:10:35:43.707] ha-monit-app monit-app/<NOSRV> -1/-1/0 188 PR 0/0/0/0/3 0/0
Jun 15 10:35:44 ha-monit-app-01-6zxn haproxy[1471]: 10.164.0.7:58212 [15/Jun/2018:10:35:44.742] ha-monit-app monit-app/<NOSRV> -1/-1/0 188 PR 0/0/0/0/3 0/0

来自统计数据的HAProxy状态

解决了

后端部分缺少明显的参数

模式: TCP

defaults
log global
mode    http
option  httplog
option  dontlognull
timeout connect 5000
timeout client  50000
timeout server  50000
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http
frontend ha-monit-app
bind :10051
mode tcp
default_backend monit-app
backend monit-app
mode tcp <-- this one
server monit-app-01 10.156.0.10:10051 check
server monit-app-02 10.164.0.10:10051 check backup
listen stats 
bind :80
mode http
stats enable
stats uri /
stats hide-version
stats realm Zabbix Server HAProxy
stats auth xxxx:xxxx

它在后端使用http,因为它是来自

defaults
mode http

最新更新