Scala Akka |如何将多个群集节点作为来自不同JVM的一个群集连接

问题描述

经过2天的尝试和错误,也许有人可以指出我正确的方向。

我希望不同机器上的2个群集节点(在本例中为2个EC2实例)作为1个群集与公共IP(第一个EC2实例中的公共IP)协作。加入节点不应仅局限于EC2。

登录启动器EC2:

[INFO] [08/18/2020 18:02:02.741] [run-main-0] [ArteryTcpTransport(akka://RTJVMCluster)] Remoting started with transport [Artery tcp]; listening on address [akka://[email protected]:2550] and bound to [akka://[email protected]:2550] with UID [235194870536733302]
[INFO] [08/18/2020 18:02:02.779] [run-main-0] [Cluster(akka://RTJVMCluster)] Cluster Node [akka://[email protected]:2550] - Starting up,Akka version [2.6.8] ...
[INFO] [08/18/2020 18:02:03.042] [run-main-0] [Cluster(akka://RTJVMCluster)] Cluster Node [akka://[email protected]:2550] - Registered cluster JMX MBean [akka:type=Cluster]
[INFO] [08/18/2020 18:02:03.042] [run-main-0] [Cluster(akka://RTJVMCluster)] Cluster Node [akka://[email protected]:2550] - Started up successfully
[INFO] [08/18/2020 18:02:03.164] [RTJVMCluster-akka.actor.default-dispatcher-10] [akka://RTJVMCluster/system/cluster/core/daemon/downingProvider] SBR started. Config: stableAfter: 20000 ms,strategy: KeepMajority,selfUniqueAddress: UniqueAddress(akka://[email protected]:2550,235194870536733302),selfDc: default
[INFO] [akkaMemberChanged][08/18/2020 18:02:03.209] [RTJVMCluster-akka.actor.internal-dispatcher-4] [Cluster(akka://RTJVMCluster)] Cluster Node [akka://[email protected]:2550] - Node [akka://[email protected]:2550] is JOINING itself (with roles [dc-default]) and forming new cluster
[INFO] [08/18/2020 18:02:03.211] [RTJVMCluster-akka.actor.internal-dispatcher-4] [Cluster(akka://RTJVMCluster)] Cluster Node [akka://[email protected]:2550] - is the new leader among reachable nodes (more leaders may exist)
[INFO] [akkaMemberChanged][08/18/2020 18:02:03.234] [RTJVMCluster-akka.actor.internal-dispatcher-4] [Cluster(akka://RTJVMCluster)] Cluster Node [akka://[email protected]:2550] - Leader is moving node [akka://[email protected]:2550] to [Up]
[INFO] [08/18/2020 18:02:03.291] [RTJVMCluster-akka.actor.default-dispatcher-10] [akka://RTJVMCluster/system/cluster/core/daemon/downingProvider] This node is now the leader responsible for taking SBR decisions among the reachable nodes (more leaders may exist).
[WARN] [08/18/2020 18:03:10.744] [RTJVMCluster-akka.remote.default-remote-dispatcher-7] [akka.stream.Log(akka://RTJVMCluster/system/Materializers/StreamSupervisor-1)] [outbound connection to [akka://[email protected]:2551],message stream] Upstream failed,cause: StreamTcpException: Tcp command [Connect(18.185.238.129:2551,None,List(),Some(5000 milliseconds),true)] failed because of java.net.ConnectException: Connection refused

登录第二个EC2:

[INFO] [08/18/2020 18:03:09.628] [run-main-0] [ArteryTcpTransport(akka://RTJVMCluster)] Remoting started with transport [Artery tcp]; listening on address [akka://[email protected]:2551] and bound to [akka://[email protected]:2550] with UID [969183754535976376]
[INFO] [08/18/2020 18:03:09.665] [run-main-0] [Cluster(akka://RTJVMCluster)] Cluster Node [akka://[email protected]:2551] - Starting up,Akka version [2.6.8] ...
[INFO] [08/18/2020 18:03:09.772] [run-main-0] [Cluster(akka://RTJVMCluster)] Cluster Node [akka://[email protected]:2551] - Registered cluster JMX MBean [akka:type=Cluster]
[INFO] [08/18/2020 18:03:09.775] [run-main-0] [Cluster(akka://RTJVMCluster)] Cluster Node [akka://[email protected]:2551] - Started up successfully
[INFO] [08/18/2020 18:03:09.917] [RTJVMCluster-akka.actor.default-dispatcher-10] [akka://RTJVMCluster/system/cluster/core/daemon/downingProvider] SBR started. Config: stableAfter: 20000 ms,selfUniqueAddress: UniqueAddress(akka://[email protected]:2551,969183754535976376),selfDc: default
[WARN] [akkaJoinFailed][08/18/2020 18:03:20.156] [RTJVMCluster-akka.actor.internal-dispatcher-2] [Cluster(akka://RTJVMCluster)] Cluster Node [akka://[email protected]:2551] - Couldn't join seed nodes after [2] attempts,will try again. seed-nodes=[akka://[email protected]:2550]

到目前为止,我相信第二个EC2实例可以连接到我启动第一个ActorSystem的第一个EC2实例,但是我不明白为什么连接被拒绝。

Scala应用代码(EC2 1和EC2 2):

package example

import akka.actor.ActorSystem
import com.typesafe.config.ConfigFactory

object Test extends App {
  val config = ConfigFactory.load("configuration.conf")
  ActorSystem("RTJVMCluster",config)
}

configuration.conf | EC2 1 :(此EC2首先启动)

akka {
    actor {
        provider = "cluster"
    }

    remote {
        artery {
            enabled = on
            transport = tcp
            canonical.hostname = "18.185.238.129"      # external (logical) hostname
            canonical.port = 2550

            # EC2 1
            bind.hostname = "172.31.28.140"            # internal (bind) hostname
            bind.port = 2550                           # internal (bind) port
        }
    }

  cluster {
    seed-nodes = ["akka://[email protected]:2550"]
    downing-provider-class = "akka.cluster.sbr.SplitBrainResolverProvider"
  }
}

configuration.conf | EC2 2:

akka {
    actor {
        provider = "cluster"
    }

    remote {
        artery {
            enabled = on
            transport = tcp
            canonical.hostname = "18.185.238.129"      # external (logical) hostname
            canonical.port = 2551

            # EC2 2
            bind.hostname = "172.31.23.84"             # internal (bind) hostname
            bind.port = 2550                           # internal (bind) port
        }
    }

  cluster {
    seed-nodes = ["akka://[email protected]:2550"]
    downing-provider-class = "akka.cluster.sbr.SplitBrainResolverProvider"
  }
}

.jvmopts

-Djava.net.preferIPv4Stack=true
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Xms256m
-Xmx512m

还尝试了其他选项,例如:-Dakka.remote.port = 2550和2551 | -Dcom.sun.management.jmxremote.port = 2550和2551 | -Dcom.sun.management.jmxremote.rmi.port = 2550和2551 | -Djava.rmi.server.hostname = ec2-18-185-238-129.eu-central-1.compute.amazonaws.com

build.sbt

name := "test"
version := "1.0"
scalaVersion := "2.13.3" 

lazy val akkaVersion = "2.6.8"

libraryDependencies ++= Seq(
  "com.typesafe.akka" %% "akka-actor" % akkaVersion,"com.typesafe.akka" %% "akka-stream" % akkaVersion,"com.typesafe.akka" %% "akka-http"   % "10.2.0","com.typesafe.akka" %% "akka-cluster" % akkaVersion,"com.typesafe.akka" %% "akka-remote" % akkaVersion,)

在EC2实例上,所有入站和出站端口都是开放的。

任何有关如何使用公共ip从不同机器连接多个节点的帮助都将受到高度赞赏!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)