【问题标题】:Akka behind HAProxyHAProxy 背后的 Akka
【发布时间】:2015-09-20 10:07:51
【问题描述】:

我有 2 个系统:系统 1 正在运行 akka 和 HAProxy,系统 2 正在运行向 akka 发出请求的 REST 组件。

Akka 在系统 1 的 4241 端口上运行。当没有 HAProxy 时,系统 2 能够连接到系统 1。在系统 1 上安装 HAProxy 后,从系统 2 到系统 1 的请求出错,日志如下:

ERROR[deal-akka.actor.default-dispatcher-18] EndpointWriter - 丢弃 非本地消息 [class akka.actor.ActorSelectionMessage] 收件人 [Akka.tcp://akkaSystemName@Server1IP:42431/]] 到达 [akka.tcp://akkaSystemName@Server1IP:42431] 入站地址是 [akka.tcp://akkaSystemName@Server1IP:4241]

HAProxy 在 42431 上运行。

HAProxy 配置如下:

listen akka_tcp :42431
        mode tcp
        option tcplog
        balance leastconn

        server test1 Server1IP:4241 check
        server test2 Server1IP:4241 check

akka 的配置是这样的:

  actor {
    provider = "akka.remote.RemoteActorRefProvider"
  }

  remote {
    netty.tcp {

      hostname = "Server1IP"

      port = 4241

      transport-protocol = tcp

      # Sets the send buffer size of the Sockets,
      # set to 0b for platform default
      send-buffer-size = 52428800b

      # Sets the receive buffer size of the Sockets,
      # set to 0b for platform default
      receive-buffer-size = 52428800b

      maximum-frame-size = 52428800b
    }
  }

任何建议将不胜感激。

【问题讨论】:

    标签: tcp akka haproxy akka-cluster


    【解决方案1】:

    更新答案:

    Akka Remoting 可能不应该与负载均衡器一起使用。看看它的这部分documentation

    Akka Remoting 是一个用于连接actor系统的通信模块 以点对点的方式,它是 Akka 的基础 聚类。远程处理的设计由两个(相关)设计驱动 决定:

    1.相关系统之间的通信是对称的:如果系统A可以连接到系统B,那么系统B也必须能够连接 独立到系统A。

    2. 通信系统的角色在连接模式方面是对称的:没有系统只接受连接, 并且没有只启动连接的系统。

    这些决定的后果是不可能 安全地创建具有预定义角色的纯客户端-服务器设置 (违反假设 2)并使用涉及网络地址的设置 翻译或负载平衡器(违反假设 1)。

    对于客户端-服务器设置,最好使用 HTTP 或 Akka I/O。

    对于您的情况,在系统 1 上使用 Akka HTTP 或 Akka I/O 来接受和回答来自系统 2 的请求似乎是合理的。


    旧答案:

    您必须在 Akka 配置中设置 bind-port 属性。这是Akka documentation的引述:

    # Use this setting to bind a network interface to a different port
    # than remoting protocol expects messages at. This may be used
    # when running akka nodes in a separated networks (under NATs or docker containers).
    # Use 0 if you want a random available port. Examples:
    #
    # akka.remote.netty.tcp.port = 2552
    # akka.remote.netty.tcp.bind-port = 2553
    # Network interface will be bound to the 2553 port, but remoting protocol will
    # expect messages sent to port 2552.
    

    对于您的端口,它应该是这样的:

    port = 42431
    bind-port = 4241
    

    【讨论】:

    • 不,它不起作用。系统 1 未在端口 42431 上启动。它说端口已被使用。在 haproxy.BTW 的上述情况下,我使用的是 akka 2.3.14。
    • 是的,bind-port 选项在版本 2.3.14 中不存在。但这可能对您没有帮助。看看我上面的更新答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多