haproxy 可以用来平衡 unix 套接字吗?

haproxy 可以用来平衡 unix 套接字吗?

.sock在 nginx 中,将其配置为代理 unix文件相当简单

例如:

upstream bla {
      server unix:///home/sam/Source/bla/tmp/sockets/thin1.sock;
      server unix:///home/sam/Source/bla/tmp/sockets/thin2.sock;
 }

haProxy 中是否有类似的语法来启用平衡本地.sock文件?

答案1

简短回答:是的,从 1.5 版开始

让我们看看服务器关键字参数文档:

<address> is the IPv4 or IPv6 address of the server. Alternatively, a
          resolvable hostname is supported, but this name will be resolved
          during start-up. Address "0.0.0.0" or "*" has a special meaning.
          It indicates that the connection will be forwarded to the same IP
          address as the one from the client connection. This is useful in
          transparent proxy architectures where the client's connection is
          intercepted and haproxy must forward to the original destination
          address. This is more or less what the "transparent" keyword does
          except that with a server it's possible to limit concurrency and
          to report statistics. Optionally, an address family prefix may be
          used before the address to force the family regardless of the
          address format, which can be useful to specify a path to a unix
          socket with no slash ('/'). Currently supported prefixes are :
                - 'ipv4@'  -> address is always IPv4
                - 'ipv6@'  -> address is always IPv6
                - 'unix@'  -> address is a path to a local unix socket
                - 'abns@'  -> address is in abstract namespace (Linux only)
          Any part of the address string may reference any number of
          environment variables by preceding their name with a dollar
          sign ('$') and optionally enclosing them with braces ('{}'),
          similarly to what is done in Bourne shell.

因此,您可以用前导斜杠指定 unix 套接字的路径,或者明确添加地址系列前缀:

server nginx1 /run/nginx/default.sock
server nginx2 [email protected]

答案2

正如量子所说,它需要 IPv4 地址,但使用索卡特要将 unix scoket 中继到 TCP,也许您可​​以使用 HAProxy。

socat TCP-LISTEN:1234,reuseaddr,fork UNIX-CLIENT:/tmp/foo

答案3

据我所知,HAProxy 不支持它。根据文档,您必须指定服务器的 IPv4 或 IPv6(或主机名)。

相关内容