Akka跨服务器远程部署Actor失败求助:提示不允许远程部署回退本地
远程部署Akka Actor失败问题解决
问题背景
拥有两台服务器:
- Server1: 10.7.44.49
- Server2: 10.7.44.71
两台服务器分别运行ActorSystem:
akka://Test@10.7.44.49:5555 akka://Test@10.7.44.71:5555
尝试从Server2向Server1远程部署SimpleActor,两种方式均失败:
- 配置文件方式(Server2的配置):
deployment { /simpleActor { remote = "akka://Test@10.7.44.49:5555" } }
- 编程方式:
val address = AddressFromURIString("akka://Test@10.7.44.49:5555") val actorRef = system.actorOf(Props[SimpleActor]().withDeploy(Deploy(scope = RemoteScope(address))))
两种方式均收到警告:
[WARN] [09/07/2022 13:36:53.156] [sbt-bg-threads-1] [akka.remote.RemoteActorRefProvider] Remote deploy of [akka://Test/user/simpleActor] is not allowed, falling back to local.
解决方案
该警告的核心原因是目标ActorSystem(Server1的Test系统)未开启远程部署权限,或两台系统的安全/网络配置不匹配,具体解决步骤如下:
1. 开启目标ActorSystem的远程部署权限
修改Server1的Akka配置,针对不同传输层添加允许远程部署的配置:
- 若使用Akka 2.6+默认的Artery传输层:
akka { actor { provider = remote } remote { artery { enabled = on transport = tcp canonical.hostname = "10.7.44.49" canonical.port = 5555 allow-remote-deployment = on # 关键配置:允许远程部署 } } }
- 若使用旧版Netty远程传输:
akka { actor { provider = remote } remote { netty.tcp { canonical.hostname = "10.7.44.49" canonical.port = 5555 allow-remote-deployment = on } } }
2. 确保安全配置兼容
如果启用了SSL/TLS等安全机制,需保证Server1与Server2的安全配置互相匹配。测试环境可临时关闭SSL验证(生产环境不推荐):
akka.remote.artery.ssl { enabled = off }
3. 验证Actor类的跨节点可访问性
SimpleActor类必须在两台服务器的类路径中存在,且版本一致。使用sbt、Maven等构建工具时,需确保两台服务器运行的jar包包含该Actor类。
4. 检查网络连通性
确认Server2能正常访问Server1的5555端口,无防火墙、安全组拦截。可通过以下命令测试:
telnet 10.7.44.49 5555 # 或使用nc命令 nc -zv 10.7.44.49 5555
验证部署
完成以上配置后,重启两台服务器的ActorSystem,再次执行远程部署操作,警告将消失,SimpleActor会成功部署到Server1的ActorSystem中。
内容的提问来源于stack exchange,提问作者andreacappelletti97
相关产品推荐
相关产品推荐

