2015-07-11 54 views
3

我在我的項目中使用akka 2.4-M2。我想用docker部署我的項目。但是,當我使用boot2docker測試這兩個節點時,出現了一個問題。我的節點無法連接到種子節點。docker中的akka​​節點明確解除關聯

在build.sbt的配置如下:

lazy val `topGatewayFrontend` = (project in file("topGatewayFrontend")) 
    .enablePlugins(PlayScala) 
    .enablePlugins(DockerPlugin) 
    .settings(
    name := "topGatewayFrontend", 
    libraryDependencies ++= (Dependencies.topGatewayFrontend ++ Seq(cache,  ws)), 
    dockerExposedPorts := Seq(9000) 
) 

lazy val `topGatewayBackend` = (project in file("topGatewayBackend")) 
    .enablePlugins(JavaAppPackaging) 
    .enablePlugins(DockerPlugin) 
    .enablePlugins(UniversalPlugin) 
    .settings(
    name := "topGatewayBackend", 
    javaOptions in run ++= Seq(
     "-Djava.library.path=./sigar", 
     "-Xms128m", "-Xmx512m"), 
    // this enables custom javaOptions 
    fork in run := true, 
    libraryDependencies ++= Dependencies.topGatewayBackend ++ Seq(ws), 
    dockerExposedPorts := Seq(9527) 
).dependsOn(auditApi).aggregate(auditApi) 

在topGatewayFrontend遠程configeration是:

akka{ 
    remote { 
    log-sent-messages = on 
    log-received-messages = on 
    netty.tcp { 
     hostname = ${?HOSTNAME} 
     port = 9527     # external (logical) port 
     bind-hostname = 0.0.0.0 
     bind-port = 0 
    } 
    } 
    cluster { 
    seed-nodes = ["akka.tcp://[email protected]"${?HOSTNAME}":9527"] 
    roles = [topGatewayBackend] 
    } 
} 

在topGatewayBackend是:

akka{ 
    remote { 
    log-sent-messages = on 
    log-received-messages = on 
    netty.tcp { 
     hostname = ${?HOSTNAME} 
     port = 0    # external (logical) port 
     bind-hostname = 0.0.0.0 
     bind-port = 0 
    } 
    } 
    cluster { 
    seed-nodes = ["akka.tcp://[email protected]"${?HOSTNAME}":9527"] 
    roles = [topGatewayFrontend] 
    } 
} 

而且我得到的日誌如下:

在後端:

[INFO] [07/12/2015 03:13:37.568] [application-akka.actor.default-dispatcher-16] [akka.cluster.Cluster(akka://application)] Cluster Node [akka.tcp://[email protected]:9527] - Metrics collection has started successfully 
[INFO] [07/12/2015 03:13:38.107] [application-akka.actor.default-dispatcher-16] [akka.cluster.Cluster(akka://application)] Cluster Node [akka.tcp://[email protected]:9527] - Leader is moving node [akka.tcp://[email protected]:9527] to [Up] 
[INFO] [07/12/2015 03:13:38.112] [application-akka.actor.default-dispatcher-4] [akka.tcp://[email protected]:9527/user/cluster-monitor] Member up akka.tcp://[email protected]:9527 with roles Set(topGatewayBackend) 

在前端:

[INFO] [07/12/2015 03:13:47.558] [main] [akka.remote.Remoting] Starting remoting 
[INFO] [07/12/2015 03:13:47.842] [main] [akka.remote.Remoting] Remoting started; listening on addresses :[akka.tcp://[email protected]:34354] 
[INFO] [07/12/2015 03:13:47.883] [main] [akka.cluster.Cluster(akka://application)] Cluster Node [akka.tcp://[email protected]:34354] - Starting up... 
[INFO] [07/12/2015 03:13:48.057] [main] [akka.cluster.Cluster(akka://application)] Cluster Node [akka.tcp://[email protected]:34354] - Registered cluster JMX MBean [akka:type=Cluster] 
[INFO] [07/12/2015 03:13:48.058] [main] [akka.cluster.Cluster(akka://application)] Cluster Node [akka.tcp://[email protected]:34354] - Started up successfully 
[INFO] [07/12/2015 03:13:48.251] [application-akka.actor.default-dispatcher-17] [akka.cluster.Cluster(akka://application)] Cluster Node [akka.tcp://[email protected]:34354] - Metrics collection has started successfully 
[WARN] [07/12/2015 03:13:48.509] [application-akka.remote.default-remote-dispatcher-5] [akka.tcp://[email protected]:34354/system/endpointManager/reliableEndpointWriter-akka.tcp%3A%2F%2Fapplication%40192.168.59.103%3A9527-0] Association with remote system [akka.tcp://[email protected]:9527] has failed, address is now gated for [5000] ms. Reason: [Association failed with [akka.tcp://[email protected]:9527]] Caused by: [The remote system explicitly disassociated (reason unknown).] 

問題是,[公會失敗,[akka.tcp://[email protected]:9527]產生的原因:[該遠程系統明確地解離(原因未知)]

搬運工運行命令是: docker run -e HOSTNAME=192.168.59.103 -p 9527:9527 docker.fenxibao.com/topgatewaybackend:1.0-SNAPSHOTdocker run -p 9000:9000 -e HOSTNAME=192.168.59.103 docker.fenxibao.com/topgatewayfrontend:1.0-SNAPSHOT

我想知道我能做些什麼來使前端與後端成功關聯。

預先感謝您的耐心解答。

回答

3

檢查此爲如何泊塢窗內運行阿卡集羣:http://blog.michaelhamrah.com/2014/06/akka-clustering-with-sbt-docker-and-sbt-native-packager/

一個簡短的回答是,阿卡羣集需要地址是內部和外部相一致。因此,當您在Docker中啓動akka應用程序時,您需要使用爲您的容器動態創建的內部IP地址。

您需要有一個啓動腳本是這樣的:

#!/bin/bash 

CLUSTER_IP=`/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1 }'` [email protected]  

把它放進你的泊塢窗的容器,並在阿卡配置其羣集主機地址使用CLUSTER_IP環境變量。

更新: 在Docker 1.10+版本中,由於添加了新的網絡功能,因此不需要啓動腳本。您可以使用容器的名稱作爲參考,並且碼頭工人會爲您修復地址。

+0

在你的更新中,你的意思是你可以說'hostname = my-container-name'? – BatteryAcid

+0

它可以是你的容器名稱,取決於你如何啓動你的容器,在我的情況下,我通常使用docker-compose來管理和啓動我的所有容器,在這種情況下,hostname =服務名 – waterscar

+0

你能提供關於爲什麼Akka有這個要求嗎? – Edmondo1984