我是akka的新手。 具有一个种子节点和一个非种子节点的非常简单的配置。
请在下面找到操作顺序: -
- 种子节点已启动: -
醇>
val pConfig = ConfigFactory.load("application.conf").getConfig("PrimaryNode")
val demoSystem = ActorSystem("DemoSystem", pConfig)
[INFO] [04/01/2017 23:42:48.438] [run-main-0] [akka.remote.Remoting] Starting remoting
[INFO] [04/01/2017 23:42:48.673] [run-main-0] [akka.remote.Remoting] Remoting started; listening on addresses :[akka.tcp://DemoSystem@127.0.0.1:2551]
[INFO] [04/01/2017 23:42:48.688] [run-main-0] [akka.cluster.Cluster(akka://DemoSystem)] Cluster Node [akka.tcp://DemoSystem@127.0.0.1:2551] - Starting up...
[INFO] [04/01/2017 23:42:48.759] [run-main-0] [akka.cluster.Cluster(akka://DemoSystem)] Cluster Node [akka.tcp://DemoSystem@127.0.0.1:2551] - Registered cluster JMX MBean [akka:type=Cluster]
[INFO] [04/01/2017 23:42:48.759] [run-main-0] [akka.cluster.Cluster(akka://DemoSystem)] Cluster Node [akka.tcp://DemoSystem@127.0.0.1:2551] - Started up successfully
[INFO] [04/01/2017 23:42:48.776] [DemoSystem-akka.actor.default-dispatcher-3] [akka.cluster.Cluster(akka://DemoSystem)] Cluster Node [akka.tcp://DemoSystem@127.0.0.1:2551] - Metrics will be retreived from MBeans, and may be incorrect on som
e platforms. To increase metric accuracy add the 'sigar.jar' to the classpath and the appropriate platform-specific native libary to 'java.library.path'. Reason: java.lang.ClassNotFoundException: org.hyperic.sigar.Sigar
[INFO] [04/01/2017 23:42:48.779] [DemoSystem-akka.actor.default-dispatcher-3] [akka.cluster.Cluster(akka://DemoSystem)] Cluster Node [akka.tcp://DemoSystem@127.0.0.1:2551] - Metrics collection has started successfully
p: akka.actor.ActorSystem = akka://DemoSystem
[INFO] [04/01/2017 23:42:48.795] [DemoSystem-akka.actor.default-dispatcher-2] [akka.cluster.Cluster(akka://DemoSystem)] Cluster Node [akka.tcp://DemoSystem@127.0.0.1:2551] - Node [akka.tcp://DemoSystem@127.0.0.1:2551] is JOINING, rol
es []
[INFO] [04/01/2017 23:42:48.805] [DemoSystem-akka.actor.default-dispatcher-2] [akka.cluster.Cluster(akka://DemoSystem)] Cluster Node [akka.tcp://DemoSystem@127.0.0.1:2551] - Leader is moving node [akka.tcp://DemoSystem@127.0.0.1:2551] to [U
p]
- 非种子节点已启动: -
醇>
val sConfig = ConfigFactory.load("application.conf").getConfig("SecondaryNode")
val secSystem = ActorSystem("DemoSystem", sConfig)
[INFO] [04/01/2017 23:44:15.530] [run-main-0] [akka.remote.Remoting] Starting remoting
[INFO] [04/01/2017 23:44:15.845] [run-main-0] [akka.remote.Remoting] Remoting started; listening on addresses :[akka.tcp://DemoSystem@127.0.0.1:49169]
[INFO] [04/01/2017 23:44:15.847] [run-main-0] [akka.remote.Remoting] Remoting now listens on addresses: [akka.tcp://DemoSystem@127.0.0.1:49169]
[INFO] [04/01/2017 23:44:15.854] [run-main-0] [akka.cluster.Cluster(akka://DemoSystem)] Cluster Node [akka.tcp://DemoSystem@127.0.0.1:49169] - Starting up...
[INFO] [04/01/2017 23:44:15.929] [run-main-0] [akka.cluster.Cluster(akka://DemoSystem)] Cluster Node [akka.tcp://DemoSystem@127.0.0.1:49169] - Registered cluster JMX MBean [akka:type=Cluster]
[INFO] [04/01/2017 23:44:15.929] [run-main-0] [akka.cluster.Cluster(akka://DemoSystem)] Cluster Node [akka.tcp://DemoSystem@127.0.0.1:49169] - Started up successfully
[INFO] [04/01/2017 23:44:15.945] [DemoSystem-akka.actor.default-dispatcher-3] [akka.cluster.Cluster(akka://DemoSystem)] Cluster Node [akka.tcp://DemoSystem@127.0.0.1:49169] - Metrics will be retreived from MBeans, and may be incorrect on some platforms. To increase metric accuracy add the 'sigar.jar' to the classpath and the appropriate platform-specific native libary to 'java.library.path'. Reason: java.lang.ClassNotFoundException: org.hyperic.sigar.Sigar
[INFO] [04/01/2017 23:44:15.951] [DemoSystem-akka.actor.default-dispatcher-3] [akka.cluster.Cluster(akka://DemoSystem)] Cluster Node [akka.tcp://DemoSystem@127.0.0.1:49169] - Metrics collection has started successfully
s: akka.actor.ActorSystem = akka://DemoSystem
[INFO] [04/01/2017 23:44:16.265] [DemoSystem-akka.actor.default-dispatcher-14] [akka.cluster.Cluster(akka://DemoSystem)] Cluster Node [akka.tcp://DemoSystem@127.0.0.1:49169] - Welcome from [akka.tcp://DemoSystem@127.0.0.1:2551]
种子节点将非种子节点移动到up(启动后的种子节点日志) 非种子节点): -
[INFO] [04/01/2017 23:44:16.190] [DemoSystem-akka.actor.default-dispatcher-14] [akka.cluster.Cluster(akka://DemoSystem)] Cluster Node [akka.tcp://DemoSystem@127.0.0.1:2551] - Node [akka.tcp://DemoSystem@127.0.0.1:49169] is JOINING, roles []
[INFO] [04/01/2017 23:44:16.782] [DemoSystem-akka.actor.default-dispatcher-25] [akka.cluster.Cluster(akka://DemoSystem)] Cluster Node [akka.tcp://DemoSystem@127.0.0.1:2551] - Leader is moving node [akka.tcp://DemoSystem@127.0.0.1:49169] to [Up]
- 现在种子节点被杀死(登录非种子节点说,该种子节点是quaretined): -
醇>
............
............
[WARN] [04/01/2017 23:46:14.301] [DemoSystem-akka.remote.default-remote-dispatcher-6] [akka.tcp://DemoSystem@127.0.0.1:49169/system/endpointManager/reliableEndpointWriter-akka.tcp%3A%2F%2FDemoSystem%40127.0.0.1%3A2551-2] Association with remote system [akka.tcp://DemoSystem@127.0.0.1:2551] has failed, address is now gated for [5000] ms. Reason: [Association failed with [akka.tcp://DemoSystem@127.0.0.1:2551]] Caused by: [Connection refused: no further information: /127.0.0.1:2551]
[INFO] [04/01/2017 23:46:14.959] [DemoSystem-akka.actor.default-dispatcher-21] [akka.cluster.Cluster(akka://DemoSystem)] Cluster Node [akka.tcp://DemoSystem@127.0.0.1:49169] - Leader is auto-downing unreachable node [akka.tcp://DemoSystem@127.0.0.1:2551]
[INFO] [04/01/2017 23:46:14.960] [DemoSystem-akka.actor.default-dispatcher-20] [akka.cluster.Cluster(akka://DemoSystem)] Cluster Node [akka.tcp://DemoSystem@127.0.0.1:49169] - Marking unreachable node [akka.tcp://DemoSystem@127.0.0.1:2551] as [Down]
[INFO] [04/01/2017 23:46:15.953] [DemoSystem-akka.actor.default-dispatcher-21] [akka.cluster.Cluster(akka://DemoSystem)] Cluster Node [akka.tcp://DemoSystem@127.0.0.1:49169] - Leader is removing unreachable node [akka.tcp://DemoSystem@127.0.0.1:2551]
[WARN] [04/01/2017 23:46:15.953] [DemoSystem-akka.remote.default-remote-dispatcher-5] [akka.remote.Remoting] Association to [akka.tcp://DemoSystem@127.0.0.1:2551] having UID [-273153546] is irrecoverably failed. UID is now quarantined and all messages to this UID will be delivered to dead letters. Remote actorsystem must be restarted to recover from this situation.
现在,当我在非种子节点控制台上检查以下内容时: -
- 哪个节点是领导者
醇>
领航船成功转移到非种子节点
scala> val cluster = Cluster(secSystem)
scala> cluster.state
res1: akka.cluster.ClusterEvent.CurrentClusterState = CurrentClusterState(TreeSet(Member(address = akka.tcp://DemoSystem@127.0.0.1:49169, status = Up)),Set(),Set(akka.tcp://DemoSystem@127.0.0.1:49169),Some(akka.tcp://DemoSystem@127.0.0.1:49169),Map())
scala> cluster.state.leader
res2: Option[akka.actor.Address] = Some(akka.tcp://DemoSystem@127.0.0.1:49169)
- 哪个节点是种子节点: -
醇>
种子节点仍然指向死节点
scala> cluster.settings.SeedNodes
res0: scala.collection.immutable.IndexedSeq[akka.actor.Address] = Vector(akka.tcp://DemoSystem@127.0.0.1:2551)
我在想,非种子节点将被选为新的种子节点,但事实并非如此。
另外,请在下面找到两个节点的配置: -
PrimaryNode {
akka {
actor {
provider = "akka.cluster.ClusterActorRefProvider"
}
remote {
log-remote-lifecycle-events = off
enabled-transports = ["akka.remote.netty.tcp"]
netty.tcp {
hostname = "127.0.0.1"
port = 2551
}
}
cluster {
seed-nodes = ["akka.tcp://DemoSystem@127.0.0.1:2551"]
auto-down-unreachable-after = 10s
}
}
}
SecondaryNode {
akka {
actor {
provider = "akka.cluster.ClusterActorRefProvider"
}
remote {
enabled-transports = ["akka.remote.netty.tcp"]
netty.tcp {
hostname = "127.0.0.1"
port = 49169
}
}
cluster {
seed-nodes = ["akka.tcp://DemoSystem@127.0.0.1:2551"]
auto-down-unreachable-after = 10s
}
}
}
请赐教。为什么在前一个种子节点被杀死后,非种子节点未被选为新的种子节点。
答案 0 :(得分:1)
很抱歉,我现在的时间很少,我会用几句话来尽力而为。
没有种子节点选举这样的事情。
一旦启动了akka群集,每个群集成员可以充当加入节点的种子节点,即,被任何加入节点用作初始联系点。这种情况在没有配置的情况下发生,因为所有集群节点都在侦听传入连接。
在群集启动之前,(第一个)种子节点非常重要,因为它需要是启动群集时可用的初始节点的一部分。没有该节点,群集就无法启动。但是一旦启动(如上所述),该种子节点就会消失,一切都会好起来。
这很可能是cluster.settings.SeedNodes
的值未更改或未更新的原因。初始群集设置后,它没有任何影响。
参考: