大网数据广告活动
服务器运维问答

HAProxy tcp-check expect rstring not working as expected

· 52CE 我爱测

We have a status page that returns either "OK" or "Fail". We set up the tcp-check to look for "OK", which unfortunately doesn't work because it also matches "HTTP/1.1 200 OK" I was thinking I could use rstring with a pattern like…

问题原文

原帖链接 · PlantationGator · CC BY-SA 4.0

We have a status page that returns either "OK" or "Fail". We set up the tcp-check to look for "OK", which unfortunately doesn't work because it also matches "HTTP/1.1 200 OK" I was thinking I could use rstring with a pattern like .*^OK$. However, this never matches, even though it works when I test the pattern against this response:

HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/plain; charset=utf-8
Server: Microsoft-IIS/8.5
X-ServerName: myserver
X-AspNet-Version: 4.0.30319
Date: Wed, 20 Mar 2019 16:23:48 GMT
Content-Length: 2

OK

Does tcp-check expect rstring not work the way I think it does? Maybe there is a small detail that I'm missing? Here is what I'm trying in the haproxy config:

This does not work (the probe fails for both OK and Fail responses) (I'm changing server names and IPs, just assume those are valid)

option tcp-check
tcp-check connect
tcp-check send GET\ /status.ashx\ HTTP/1.0\r\n\r\n
tcp-check expect rstring .*^OK$

server myserver1 1.2.3.4:80 check
server myserver2 1.2.3.5:80 check

The following always says both servers are online, whether the probe returns OK or Fail, because of the issue I mentioned earlier with "200 OK":

option tcp-check
tcp-check connect
tcp-check send GET\ /offline.txt\ HTTP/1.0\r\n\r\n
tcp-check expect string 404 - File or directory not found.

tcp-check connect
tcp-check send GET\ /status.ashx\ HTTP/1.0\r\n\r\n
tcp-check expect rstring OK

server myserver1 1.2.3.4:80 check
server myserver2 1.2.3.5:80 check

So plain "OK" works with rstring, but when I try to apply a pattern it doesn't work the way I expect.

已采纳解答

原帖链接 · PlantationGator · CC BY-SA 4.0

After more testing and trial and error I figured out the discrepancy that I was seeing was due to the multiline regex option. Without the multiline option set, my pattern doesn't work. So HAProxy must not use this option. Incidentally, in this case the pattern OK$ works because it interprets this to mean that the entire string ends with OK. If there is a Fail returned, the earlier line ending with OK doesn't match, so the probe works as expected.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-03-20)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。