泊坞窗中的akka​​节点显式取消关联

前端之家收集整理的这篇文章主要介绍了泊坞窗中的akka​​节点显式取消关联 前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我在我的项目中使用akka 2.4-M2.我想用docker部署我的项目.但是,当我使用boot2docker测试两个节点时,会出现问题.我的节点无法连接到种子节点.

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中的远程配置为:

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://application@"${?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://application@"${?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://application@192.168.59.103: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://application@192.168.59.103:9527] - Leader is moving node [akka.tcp://application@192.168.59.103:9527] to [Up]
[INFO] [07/12/2015 03:13:38.112] [application-akka.actor.default-dispatcher-4] [akka.tcp://application@192.168.59.103:9527/user/cluster-monitor] Member up akka.tcp://application@192.168.59.103: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://application@192.168.59.103:34354]
[INFO] [07/12/2015 03:13:47.883] [main] [akka.cluster.Cluster(akka://application)] Cluster Node [akka.tcp://application@192.168.59.103:34354] - Starting up...
[INFO] [07/12/2015 03:13:48.057] [main] [akka.cluster.Cluster(akka://application)] Cluster Node [akka.tcp://application@192.168.59.103: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://application@192.168.59.103: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://application@192.168.59.103:34354] - Metrics collection has started successfully
[WARN] [07/12/2015 03:13:48.509] [application-akka.remote.default-remote-dispatcher-5] [akka.tcp://application@192.168.59.103:34354/system/endpointManager/reliableEndpointWriter-akka.tcp%3A%2F%2Fapplication%40192.168.59.103%3A9527-0] Association with remote system [akka.tcp://application@192.168.59.103:9527] has Failed,address is now gated for [5000] ms. Reason: [Association Failed with [akka.tcp://application@192.168.59.103:9527]] Caused by: [The remote system explicitly disassociated (reason unknown).]

问题是[关联失败[akka.tcp://application@192.168.59.103:9527]]由以下原因引起:[远程系统显式取消关联(原因未知).]

docker run命令为:
docker run -e HOSTNAME = 192.168.59.103 -p 9527:9527 docker.fenxibao.com/topgatewaybackend:1.0-SNAPSHOT和docker run -p 9000:9000 -e HOSTNAME = 192.168.59.103 docker.fenxibao.com/topgatewayfrontend:1.0-快照

我想知道如何使前端与后端成功关联.

预先感谢您的耐心解答.

最佳答案
检查此如何在docker中运行akka集群:http://blog.michaelhamrah.com/2014/06/akka-clustering-with-sbt-docker-and-sbt-native-packager/

一个简单的答案是,akka群集要求该地址必须与内部和外部地址一致.因此,在docker中启动akka应用程序时,需要使用为容器动态创建的内部ip地址.

您需要具有以下启动脚本:

#!/bin/bash

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

将其放入您的docker容器中,并在akka配置中使用CLUSTER_IP环境变量作为其群集主机地址.

更新:
在docker 1.10版本中,由于添加了新的网络功能,因此不需要启动脚本.您可以只使用容器的名称作为参考,而docker会为您修复地址.

原文链接:https://www.f2er.com/docker/532576.html

猜你在找的Docker相关文章