我正在为我正在制作的工具体验 akka 远程功能。实际上,我能够使核心和远程系统在具有不同端口的同一主机中工作。请注意,我的远程服务器在路由器上运行,如 akka 文档中所述。
现在,我正在尝试使用多个 azure 虚拟机进行更好的实验,但我遇到了一些问题。
核心应用程序具有以下配置(出于安全原因,我更改了一些名称):
akka.actor.deployment {
/querierActor/querierPool {
router = round-robin-pool
nr-of-instances = 12
target.nodes = [
"akka.tcp://SYSTEM@remote-srv01.cloudapp.net:2560"
,"akka.tcp://SYSTEM@remote-srv02.cloudapp.net:2560"
,"akka.tcp://SYSTEM@remote-srv03.cloudapp.net:2560"
]
}
}
// remote configuration. Use it for multiple machines calculation
akka {
actor {
provider = "akka.remote.RemoteActorRefProvider"
}
remote {
enabled-transports = ["akka.remote.netty.tcp"]
netty.tcp {
maximum-frame-size = 100MiB
port = 2552
hostname = "0.0.0.0"
}
}
}
而远程主机具有以下配置:
akka.actor.deployment {
/querierActor/querierPool {
router = balancing-pool
nr-of-instances = 15
}
}
akka {
actor {
provider = "akka.remote.RemoteActorRefProvider"
}
remote {
enabled-transports = ["akka.remote.netty.tcp"]
netty.tcp {
maximum-frame-size = 100MiB
hostname = "0.0.0.0"
port = 2560
}
}
}
使用此配置,服务器和远程主机显然能够通信,但远程主机开始记录一些错误:
[ERROR] [01/17/2015 12:55:05.734] [SYSTEM-akka.remote.default-remote-dispatcher-16] [akka.tcp://SYSTEM@0.0.0.0:2560/system/endpointManager/reliableEndpointWriter-akka.tcp%3A%2F%2FSYSTEM%400.0.0.0%3A2552-0/endpointWriter] dropping message [class akka.actor.ActorSelectionMessage] for non-local recipient [Actor[akka.tcp://SYSTEM@remote-srv01.cloudapp.net:2560/]] arriving at [akka.tcp://SYSTEM@remote-srv01.cloudapp.net:2560] inbound addresses are [akka.tcp://SYSTEM@0.0.0.0:2560]
一段时间后,服务器和远程主机开始记录错误并冻结。
服务器错误:
[WARN] [01/17/2015 12:21:05.658] [CRAWLER-LD-akka.remote.default-remote-dispatcher-7] [akka.tcp://SYSTEM@0.0.0.0:2552/system/remote-watcher] Detected unreachable: [akka.tcp://SYSTEM@remote-srv01.cloudapp.net:2560]
[WARN] [01/17/2015 12:21:05.664] [SYSTEM-akka.remote.default-remote-dispatcher-17] [Remoting] Association to [akka.tcp://SYSTEM@remote-srv01.cloudapp.net:2560] with unknown UID is reported as quarantined, but address cannot be quarantined without knowing the UID, gating instead for 5000 ms.
(...)
[INFO] [01/17/2015 12:21:05.712] [SYSTEM-akka.actor.default-dispatcher-6] [akka://SYSTEM/user/querierActor/querierPool] Message [akka.dispatch.sysmsg.DeathWatchNotification] from Actor[akka://SYSTEM/user/querierActor/querierPool#-1217916605] to Actor[akka://SYSTEM/user/querierActor/querierPool#-1217916605] was not delivered. [1] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
(...)
远程错误(多次相似行):
(...)
[ERROR] [01/17/2015 14:21:16.371] [SYSTEM-akka.remote.default-remote-dispatcher-16] [akka.tcp://SYSTEM@0.0.0.0:2560/system/endpointManager/reliableEndpointWriter-akka.tcp%3A%2F%2FSYSTEM%400.0.0.0%3A2552-2/endpointWriter] dropping message [class akka.actor.ActorSelectionMessage] for non-local recipient [Actor[akka.tcp://SYSTEM@remote-srv01.cloudapp.net:2560/]] arriving at [akka.tcp://SYSTEM@remote-srv01.cloudapp.net:2560] inbound addresses are [akka.tcp://SYSTEM@0.0.0.0:2560]
[ERROR] [01/17/2015 14:21:17.388] [SYSTEM-akka.remote.default-remote-dispatcher-16] [akka.tcp://SYSTEM@0.0.0.0:2560/system/endpointManager/reliableEndpointWriter-akka.tcp%3A%2F%2FSYSTEM%400.0.0.0%3A2552-2/endpointWriter] dropping message [class akka.actor.ActorSelectionMessage] for non-local recipient [Actor[akka.tcp://SYSTEM@remote-srv01.cloudapp.net:2560/]] arriving at [akka.tcp://SYSTEM@remote-srv01.cloudapp.net:2560] inbound addresses are [akka.tcp://SYSTEM@0.0.0.0:2560]
[WARN] [01/17/2015 14:21:17.465] [SYSTEM-akka.remote.default-remote-dispatcher-16] [akka.tcp://SYSTEM@0.0.0.0:2560/system/endpointManager/reliableEndpointWriter-akka.tcp%3A%2F%2FSYSTEM%400.0.0.0%3A2552-2] Association with remote system [akka.tcp://SYSTEM@0.0.0.0:2552] has failed, address is now gated for [5000] ms. Reason is: [Disassociated].
[INFO] [01/17/2015 14:21:17.467] [SYSTEM-akka.actor.default-dispatcher-21] [akka://SYSTEM/system/transports/akkaprotocolmanager.tcp0/akkaProtocol-tcp%3A%2F%2FSYSTEM%40186.228.120.115%3A56044-3] Message [akka.remote.transport.AssociationHandle$Disassociated] from Actor[akka://SYSTEM/deadLetters] to Actor[akka://SYSTEM/system/transports/akkaprotocolmanager.tcp0/akkaProtocol-tcp%3A%2F%2FSYSTEM%40186.228.120.115%3A56044-3#-2070785548] was not delivered. [6] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
[INFO] [01/17/2015 14:21:17.468] [SYSTEM-akka.actor.default-dispatcher-21] [akka://SYSTEM/system/transports/akkaprotocolmanager.tcp0/akkaProtocol-tcp%3A%2F%2FSYSTEM%40186.228.120.115%3A56044-3] Message [akka.remote.transport.ActorTransportAdapter$DisassociateUnderlying] from Actor[akka://SYSTEM/deadLetters] to Actor[akka://SYSTEM/system/transports/akkaprotocolmanager.tcp0/akkaProtocol-tcp%3A%2F%2FSYSTEM%40186.228.120.115%3A56044-3#-2070785548] was not delivered. [7] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
(...)
我发现问题可能出在主机名配置中,并尝试将主机名放入服务器和远程主机。但是,在这种情况下,系统甚至不会加载:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'FacadeMemory' defined in file [D:datadevelopmentgitsemantic-web-crawlercrawlerld.coretargetclassesnetdovalewebsemanticslinkedDataRecommenderfacadememoryFacadeMemory.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [facade.memory.FacadeMemory]: Constructor threw exception; nested exception is org.jboss.netty.channel.ChannelException: Failed to bind to: /remote-srv01.cloudapp.net:2560
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1077)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1022)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:706)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:762)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:109)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:952)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:941)
at facade.memory.GUIMain.main(GUIMain.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [facade.memory.FacadeMemory]: Constructor threw exception; nested exception is org.jboss.netty.channel.ChannelException: Failed to bind to: /remote-srv01.cloudapp.net:2560
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:164)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:89)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1070)
... 21 more
Caused by: org.jboss.netty.channel.ChannelException: Failed to bind to: /remote-srv01.cloudapp.net:2560
at org.jboss.netty.bootstrap.ServerBootstrap.bind(ServerBootstrap.java:272)
at akka.remote.transport.netty.NettyTransport$$anonfun$listen$1.apply(NettyTransport.scala:393)
at akka.remote.transport.netty.NettyTransport$$anonfun$listen$1.apply(NettyTransport.scala:389)
at scala.util.Success$$anonfun$map$1.apply(Try.scala:236)
at scala.util.Try$.apply(Try.scala:191)
at scala.util.Success.map(Try.scala:236)
at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:235)
at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:235)
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)
at akka.dispatch.BatchingExecutor$Batch$$anonfun$run$1.processBatch$1(BatchingExecutor.scala:67)
at akka.dispatch.BatchingExecutor$Batch$$anonfun$run$1.apply$mcV$sp(BatchingExecutor.scala:82)
at akka.dispatch.BatchingExecutor$Batch$$anonfun$run$1.apply(BatchingExecutor.scala:59)
at akka.dispatch.BatchingExecutor$Batch$$anonfun$run$1.apply(BatchingExecutor.scala:59)
at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:72)
at akka.dispatch.BatchingExecutor$Batch.run(BatchingExecutor.scala:58)
at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:41)
at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:401)
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
Caused by: java.net.BindException: Cannot assign requested address: bind
at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Net.java:436)
at sun.nio.ch.Net.bind(Net.java:428)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:214)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
at org.jboss.netty.channel.socket.nio.NioServerBoss$RegisterTask.run(NioServerBoss.java:193)
at org.jboss.netty.channel.socket.nio.AbstractNioSelector.processTaskQueue(AbstractNioSelector.java:372)
at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:296)
at org.jboss.netty.channel.socket.nio.NioServerBoss.run(NioServerBoss.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
我不知道我做错了什么。我试图查找有关该问题的信息,但我发现的任何问题都与我的问题有关。我也在 azure 配置上打开了端口。
如何使服务器主机能够与远程主机进行适当的通信?
我能够解决这个问题。
经过一些徒劳的研究,我不得不尝试一些不同的东西。我正在做出一些可能是错误的假设,因为我没有找到任何其他信息。如果您正在阅读此答案并发现任何错误,请告诉我。
问题是框架(显然是sun.nio.ch.Net.bind0,但我没有找到很多关于它的文档)允许以下范围的ips:0.0.0.0(如果您接受来自机器中任何网络接口的连接),127.0.0.0(如果您只使用本地请求 - I guest)和任何计算机网络接口的IP地址。在最后一种情况下,仅允许请求访问此特定接口。
问题是"主机名"属性也用于寻址 Akka 的远程节点。我的意思是,当主机节点调用远程节点时,它会使用此信息来确定完成后需要发送的结果。此外,如果将属性主机名的值设置为 0.0.0.0,并尝试通过其 dns 名称(无法与任何网络接口关联)访问此节点,它将失败。您必须使用与其中一个网络接口相同的 IP 来识别计算机。
因此,我的设置略有变化:
对于主机节点,我进行了以下更改:
(...)
akka.actor.deployment {
/sparqlQuerierMasterActor/sparqlQuerierPool {
router = round-robin-pool
nr-of-instances = 12
target.nodes = [
"akka.tcp://SYSTEM@XXX.XXX.XXX.XXX:2560"
,"akka.tcp://SYSTEM@YYY.YYY.YYY.YYY:2560"
,"akka.tcp://SYSTEM@ZZZ.ZZZ.ZZZ.ZZZ:2560"
]
}
}
(...)
XXX、YYY 和 ZZZ 是远程节点的可访问 IP,这些节点也在网络接口上注册。
远程节点的配置更改为:
(...)
remote {
enabled-transports = ["akka.remote.netty.tcp"]
netty.tcp {
maximum-frame-size = 100MiB
hostname = "YYY.YYY.YYY.YYY"
port = 2560
}
}
(...)
我没有测试是否可以保持以前的 0.0.0.0 配置。也许这是可能的。
该解决方案使我能够使主机和远程节点完美地通信=)