【问题标题】:how akka frontend node connect to cluster after restarting all down backend nodes?重新启动所有后端节点后,akka 前端节点如何连接到集群?
【发布时间】:2025-12-22 11:35:06
【问题描述】:

以官方示例akka-sample-cluster-java进行演示:
1.首先,启动前端节点

sbt 'runMain sample.cluster.factorial.FactorialFrontendMain'

2。分别启动两个也是种子节点的后端节点

sbt 'runMain sample.cluster.factorial.FactorialBackendMain 2551'
sbt 'runMain sample.cluster.factorial.FactorialBackendMain 2551'

现在一切都应该没问题。

[info] [INFO] [05/11/2017 17:40:42.822] [ClusterSystem-akka.actor.default-dispatcher-3] [akka.cluster.Cluster(akka://ClusterSystem)] Cluster Node 
[akka.tcp://ClusterSystem@127.0.0.1:2551] - Node 
[akka.tcp://ClusterSystem@127.0.0.1:2552] is JOINING, roles [backend]
[info] [INFO] [05/11/2017 17:40:43.349] [ClusterSystem-akka.actor.default-dispatcher-4] [akka.cluster.Cluster(akka://ClusterSystem)] Cluster Node 
[akka.tcp://ClusterSystem@127.0.0.1:2551] - Leader is moving node 
[akka.tcp://ClusterSystem@127.0.0.1:2551] to [Up]
[info] [INFO] [05/11/2017 17:40:43.349] [ClusterSystem-akka.actor.default-dispatcher-4] [akka.cluster.Cluster(akka://ClusterSystem)] Cluster Node 
[akka.tcp://ClusterSystem@127.0.0.1:2551] - Leader is moving node 
[akka.tcp://ClusterSystem@127.0.0.1:2552] to [Up]
[info] [INFO] [05/11/2017 17:40:43.349] [ClusterSystem-akka.actor.default-dispatcher-4] [akka.cluster.Cluster(akka://ClusterSystem)] Cluster Node     
[akka.tcp://ClusterSystem@127.0.0.1:2551] - Leader is moving node         
[akka.tcp://ClusterSystem@127.0.0.1:56431] to [Up]

但是,当我停止两个后端节点(通过 ctrl + c)并再次重新启动它们时,任一后端节点的状态始终为“加入”,并且无法更改为“启动”。

[info] [INFO] [05/11/2017 17:39:32.356] [ClusterSystem-akka.actor.default-dispatcher-4] [akka.cluster.Cluster(akka://ClusterSystem)] Cluster Node [akka.tcp://ClusterSystem@127.0.0.1:2551] - Node [akka.tcp://ClusterSystem@127.0.0.1:2551] is JOINING, roles [backend]
[info] [INFO] [05/11/2017 17:39:35.637] [ClusterSystem-akka.actor.default-dispatcher-3] [akka.cluster.Cluster(akka://ClusterSystem)] Cluster Node 
[akka.tcp://ClusterSystem@127.0.0.1:2551] - Node 
[akka.tcp://ClusterSystem@127.0.0.1:56431] is JOINING, roles [frontend]

前端节点如何在不重启前端节点的情况下自动加入种子节点?它在重新启动前端节点时起作用。

【问题讨论】:

    标签: akka cluster-computing frontend backend seed


    【解决方案1】:

    一旦集群形成,集群中的节点将停止寻找(其他)种子节点:种子节点仅用于集群的初始形成。

    如果您想在此示例中重新启动“后端”节点并让它们加入已经运行的“前端”节点,则“后端”节点必须启动与“前端”节点的连接,而不是相反反之亦然。换句话说:“前端”节点然后充当这些新启动的后端节点的种子节点。

    在此示例中,这有点棘手,因为“前端”节点未侦听可预测的端口号。

    如果您进行调整以实现此目的,请记住,此示例使用“自动关闭”作为关闭策略。这意味着当集群领导者有一段时间无法到达某个节点时,它将将该节点标记为(永久)“关闭”。即使节点返回,它也不能再以其原始地址加入集群,该地址现在被永久禁止进入集群(以防止某些未定义的行为和“脑裂”问题)。

    请注意,在生产环境中,您可能不会使用自动关闭功能,而是运行一个工具,该工具可以“从外部”查看您的节点,并决定哪些节点仅视为“无法访问”,哪些节点需要永久停用。

    【讨论】:

    • 感谢您的回答!