如何使用 Akka 将 play 应用程序配置为集群中的 运行
How to configure play application with Akka to run in a cluster
我有一个 PlayFramework (play-scala) 应用程序,我想 运行 在集群中。所以我可能有几个 docker 这个应用程序图像的容器 运行ning。我提前不知道这些的IP地址,因为云服务提供商可以动态启动和停止它们,所以我无法指定种子节点。此外,所有 application.conf
文件对于应用程序的每个实例都应该相同吗?
如何配置 play 应用程序以使应用程序的每个实例都能发现并加入 Akka 集群?
我看过:
https://www.playframework.com/documentation/2.7.x/ScalaAkka#Akka-Cluster
https://github.com/lregnier/play-akka-cluster-aws
我必须使用 Akka Cluster Bootstrap 因为我不能指定种子节点吗?
在 application.conf
文件中包含以下内容是否足够(取自 Cluster Usage:
akka {
actor {
provider = "cluster"
}
remote {
log-remote-lifecycle-events = off
netty.tcp {
hostname = "127.0.0.1"
port = 0
}
}
cluster {
seed-nodes = [
"akka.tcp://ClusterSystem@127.0.0.1:2551",
"akka.tcp://ClusterSystem@127.0.0.1:2552"]
# auto downing is NOT safe for production deployments.
# you may want to use it during development, read more about it in the docs.
#
# auto-down-unreachable-after = 10s
}
}
但是没有种子节点?如果是,节点如何发现并加入集群?
鉴于要求,最好的选择可能是使用 Akka Cluster Bootstrap
. To run container-based services, service discovery
using AWS ECS
or Kubernetes
可能更接近您的需要。
Akka Cluster Bootstrap
通过自动集群 bootstrap 机制满足您对没有 pre-assigned 种子节点的需求。每个节点通过其公开的 HTTP 端点相互探测,如果不存在 seed nodes
(即不存在集群),具有 "lowest" 地址的节点将使自己成为 seed node
提示其他节点加入新形成的集群。有关详细信息,请参阅此 Akka doc re: cluster bootstrap.
如 Akka 文档中所述,Akka Cluster Bootstrap
取决于模块 Akka Discovery
和 Akka Management
:
libraryDependencies ++= Seq(
"com.lightbend.akka.management" %% "akka-management-cluster-bootstrap" % "1.0.1",
"com.typesafe.akka" %% "akka-discovery" % "2.5.21"
)
对于service discovery using ECS
,将aws-api-ecs
或aws-api-ecs-async
(对于non-blocking IO)分配给application.conf
中的akka.discovery.method
,这可能看起来像以下:
akka {
cluster {
seed-nodes = []
seed-nodes = ${?SEED_NODES}
}
# ...
management {
cluster.bootstrap {
contact-point-discovery {
required-contact-point-nr = 2
required-contact-point-nr = ${?REQUIRED_CONTACT_POINTS}
}
}
# ...
}
discovery {
method = aws-api-ecs-async
aws-api-ecs-async {
cluster = "my-ecs-cluster"
}
}
}
对于 service discovery using Kubernetes
,akka.discovery.method
应该在 application.conf
中分配 kubernetes-api
,可能如下所示:
akka {
cluster {
seed-nodes = []
seed-nodes = ${?SEED_NODES}
}
# ...
management {
cluster.bootstrap {
contact-point-discovery {
required-contact-point-nr = 2
required-contact-point-nr = ${?REQUIRED_CONTACT_POINTS}
}
}
# ...
}
discovery {
method = kubernetes-api
kubernetes-api {
pod-namespace = "default"
pod-namespace = ${?K8S_NAMESPACE}
pod-label-selector = "app=akka-cluster"
pod-label-selector = ${?K8S_SELECTOR}
pod-port-name = "cluster-mgmt-port"
pod-port-name = ${?K8S_MANAGEMENT_PORT}
}
}
}
我有一个 PlayFramework (play-scala) 应用程序,我想 运行 在集群中。所以我可能有几个 docker 这个应用程序图像的容器 运行ning。我提前不知道这些的IP地址,因为云服务提供商可以动态启动和停止它们,所以我无法指定种子节点。此外,所有 application.conf
文件对于应用程序的每个实例都应该相同吗?
如何配置 play 应用程序以使应用程序的每个实例都能发现并加入 Akka 集群?
我看过:
https://www.playframework.com/documentation/2.7.x/ScalaAkka#Akka-Cluster
我必须使用 Akka Cluster Bootstrap 因为我不能指定种子节点吗?
在 application.conf
文件中包含以下内容是否足够(取自 Cluster Usage:
akka {
actor {
provider = "cluster"
}
remote {
log-remote-lifecycle-events = off
netty.tcp {
hostname = "127.0.0.1"
port = 0
}
}
cluster {
seed-nodes = [
"akka.tcp://ClusterSystem@127.0.0.1:2551",
"akka.tcp://ClusterSystem@127.0.0.1:2552"]
# auto downing is NOT safe for production deployments.
# you may want to use it during development, read more about it in the docs.
#
# auto-down-unreachable-after = 10s
}
}
但是没有种子节点?如果是,节点如何发现并加入集群?
鉴于要求,最好的选择可能是使用 Akka Cluster Bootstrap
. To run container-based services, service discovery
using AWS ECS
or Kubernetes
可能更接近您的需要。
Akka Cluster Bootstrap
通过自动集群 bootstrap 机制满足您对没有 pre-assigned 种子节点的需求。每个节点通过其公开的 HTTP 端点相互探测,如果不存在 seed nodes
(即不存在集群),具有 "lowest" 地址的节点将使自己成为 seed node
提示其他节点加入新形成的集群。有关详细信息,请参阅此 Akka doc re: cluster bootstrap.
如 Akka 文档中所述,Akka Cluster Bootstrap
取决于模块 Akka Discovery
和 Akka Management
:
libraryDependencies ++= Seq(
"com.lightbend.akka.management" %% "akka-management-cluster-bootstrap" % "1.0.1",
"com.typesafe.akka" %% "akka-discovery" % "2.5.21"
)
对于service discovery using ECS
,将aws-api-ecs
或aws-api-ecs-async
(对于non-blocking IO)分配给application.conf
中的akka.discovery.method
,这可能看起来像以下:
akka {
cluster {
seed-nodes = []
seed-nodes = ${?SEED_NODES}
}
# ...
management {
cluster.bootstrap {
contact-point-discovery {
required-contact-point-nr = 2
required-contact-point-nr = ${?REQUIRED_CONTACT_POINTS}
}
}
# ...
}
discovery {
method = aws-api-ecs-async
aws-api-ecs-async {
cluster = "my-ecs-cluster"
}
}
}
对于 service discovery using Kubernetes
,akka.discovery.method
应该在 application.conf
中分配 kubernetes-api
,可能如下所示:
akka {
cluster {
seed-nodes = []
seed-nodes = ${?SEED_NODES}
}
# ...
management {
cluster.bootstrap {
contact-point-discovery {
required-contact-point-nr = 2
required-contact-point-nr = ${?REQUIRED_CONTACT_POINTS}
}
}
# ...
}
discovery {
method = kubernetes-api
kubernetes-api {
pod-namespace = "default"
pod-namespace = ${?K8S_NAMESPACE}
pod-label-selector = "app=akka-cluster"
pod-label-selector = ${?K8S_SELECTOR}
pod-port-name = "cluster-mgmt-port"
pod-port-name = ${?K8S_MANAGEMENT_PORT}
}
}
}