java 集群中的spring boot应用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32947194/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
spring boot application in cluster
提问by mahendra kawde
I am developing a spring boot application.
我正在开发一个 Spring Boot 应用程序。
Since spring boot created a .jar file for an application. I want to cluster this particular application on different server. Lets say I build a jar file and ran a project then it should run in cluster mode from number of defined servers and should be able to serve end user needs.
由于 spring boot 为应用程序创建了一个 .jar 文件。我想在不同的服务器上集群这个特定的应用程序。假设我构建了一个 jar 文件并运行了一个项目,然后它应该从多个定义的服务器以集群模式运行,并且应该能够满足最终用户的需求。
My jar will reside on only one server but it will be clustered across number of servers. When end user calls a web service from my spring boot app he never know from where it is getting called.
我的 jar 将仅驻留在一台服务器上,但它将跨多个服务器集群。当最终用户从我的 Spring Boot 应用程序调用 Web 服务时,他永远不知道从哪里调用它。
The reason behind clustering is suppose any of the server goes down in future, end user will still be able to access web services from another server. But I don't know how to make it clustered.
集群背后的原因是假设任何服务器将来出现故障,最终用户仍然可以从另一台服务器访问 Web 服务。但我不知道如何使它聚集。
Can any one please give me insight on this ?
任何人都可以让我对此有所了解吗?
回答by dunni
If you want to have it clustered, you just run your Spring Boot application on multiple servers (of course, the JAR must be present on those servers, otherwise you can't run it). You would then place a loadbalancer in front of the application servers to distribute the load.
如果你想让它集群化,你只需在多台服务器上运行你的 Spring Boot 应用程序(当然,JAR 必须存在于这些服务器上,否则你无法运行它)。然后,您将在应用程序服务器前面放置一个负载均衡器来分配负载。
回答by Bassem Reda Zohdy
If all services you are going to expose are stateless so you only need to use load balancer in front of your nodes for ex. apache or nginx, if your services are stateful "store any state [session, store data in db]" so you have to use distributed cache or in memory data grid:
如果您要公开的所有服务都是无状态的,那么您只需要在节点前使用负载均衡器即可。apache 或 nginx,如果您的服务是有状态的“存储任何状态 [会话,将数据存储在数据库中]”,那么您必须使用分布式缓存或内存数据网格:
- for session you can use spring-session project which could used rails to store sessions.
- for store data in DB you need to cluster DB it self and can use distributed cache above your DB layer like Hazelcast.
- 对于会话,您可以使用 spring-session 项目,该项目可以使用 rails 来存储会话。
- 要将数据存储在 DB 中,您需要自行对 DB 进行集群,并且可以在 DB 层之上使用分布式缓存,例如 Hazelcast。
回答by jtkSource
Look into spring cloud, they have used some netflix
open software along with amazons to create 12 factor apps for micro services.
Ideally you would need a load balancer, service registry that can help you achieve multiple instances of spring boot. I believe you have to add a dependency called eureka.
Check the below link
看看 spring cloud,他们已经使用一些netflix
开放软件和亚马逊一起为微服务创建了 12 因素应用程序。理想情况下,您需要一个负载均衡器、服务注册中心来帮助您实现 Spring Boot 的多个实例。我相信您必须添加一个名为 eureka 的依赖项。检查以下链接
回答by u262742
You can deploy it in cloud foundry and use autoscale function to increase your application instances.
您可以将其部署在 Cloud Foundry 中并使用自动缩放功能来增加您的应用程序实例。