haproxy在ssh连接[TCP前端/后端]上发送400个错误请求
我在haproxy后面安装了一个SSH服务器 haproxy配置为作为L7负载平衡器服务80/443端口。 我添加了一个TCP前端来绑定端口22,以处理和路由SSH连接haproxy在ssh连接[TCP前端/后端]上发送400个错误请求,ssh,load-balancing,haproxy,openssh,Ssh,Load Balancing,Haproxy,Openssh,我在haproxy后面安装了一个SSH服务器 haproxy配置为作为L7负载平衡器服务80/443端口。 我添加了一个TCP前端来绑定端口22,以处理和路由SSH连接 frontend ssh bind *:22 mode tcp option tcplog use_backend back_ssh backend back_ssh option tcp-check tcp-check expect string SSH-2.0- se
frontend ssh
bind *:22
mode tcp
option tcplog
use_backend back_ssh
backend back_ssh
option tcp-check
tcp-check expect string SSH-2.0-
server ssh_server 172.16.2.5:1222 check
结果如下(400个错误请求)
问题是我是否在第一次配置中遗漏了什么,以及它是如何损坏的?
我更喜欢使用前端/后端格式的配置来遵循我的惯例。代理声明本质上是一种简写,用于声明具有相同名称(
foo
)和隐式default\u后端foo
的前端foo
和后端foo
但重要的是,它还将任何相关的配置指令应用于此构造创建的(隐式)前端和后端
这就是您的配置出现分歧的地方——您没有
模式tcp
——一个适用于前端和后端的指令——在后端代理声明中。由于TCP(第4层平衡)是默认模式,协议流中出现的HTTP意味着您还必须有一个defaults
部分(未显示),该部分设置模式HTTP
,并将后端置于HTTP模式。将模式TCP
添加到后端?模式TCP
是默认模式。使用前端/后端配置时,是否能够在haproxy日志中看到请求?不确定您是否正在登录。如果您需要一些调试帮助,Haproxy有很好的自定义日志选项。@Michael sqlbot我认为如果Haproxy不在tcp模式下,它将忽略tcp检查。因此,这对IMO没有帮助。@Arash很明显,您处于HTTP模式,这可能来自您在问题中忽略的defaults
部分。listen
代理声明只是声明具有相同名称和公共配置的前端
和后端
以及隐式使用后端
的简写。请尝试一下这个建议,而不是放弃它。如果全局变量也覆盖了该选项,您可能还需要选项tcplog
。@Michael sqlbot您完全正确。非常感谢(:我希望你能把它作为答案贴出来,所以我会把它标记出来。
ssh -vvv foo.bar.com
OpenSSH_7.9p1, LibreSSL 2.7.3
debug1: Reading configuration data /Users/arash/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to foo.bar.com port 22.
debug1: Connection established.
debug1: identity file /Users/arash/.ssh/id_rsa type 0
debug1: identity file /Users/arash/.ssh/id_rsa-cert type -1
debug1: identity file /Users/arash/.ssh/id_dsa type -1
debug1: identity file /Users/arash/.ssh/id_dsa-cert type -1
debug1: identity file /Users/arash/.ssh/id_ecdsa type -1
debug1: identity file /Users/arash/.ssh/id_ecdsa-cert type -1
debug1: identity file /Users/arash/.ssh/id_ed25519 type -1
debug1: identity file /Users/arash/.ssh/id_ed25519-cert type -1
debug1: identity file /Users/arash/.ssh/id_xmss type -1
debug1: identity file /Users/arash/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.9
debug1: ssh_exchange_identification: HTTP/1.0 400 Bad request
debug1: ssh_exchange_identification: Cache-Control: no-cache
debug1: ssh_exchange_identification: Connection: close
debug1: ssh_exchange_identification: Content-Type: text/html
debug1: ssh_exchange_identification:
debug1: ssh_exchange_identification: <html><body><h1>400 Bad request</h1>
debug1: ssh_exchange_identification: Your browser sent an invalid request.
debug1: ssh_exchange_identification: </body></html>
ssh_exchange_identification: Connection closed by remote host
listen ssh *:22
mode tcp
option tcplog
option tcp-check
tcp-check expect string SSH-2.0-
server ssh_server 172.16.2.5:1222 check