简体   繁体   English

Amazon WebServices 中 Tomcat 上 J2EE webapp 的设计注意事项

[英]Design considerations for J2EE webapp on Tomcat in Amazon WebServices

My project is looking to deploy a new j2ee application to Amazon's cloud.我的项目希望将新的 j2ee 应用程序部署到 Amazon 的云中。 ElasticBeanstalk supports Tomcat apps, which seems perfect. ElasticBeanstalk 支持 Tomcat 应用程序,这看起来很完美。 Are there any particular design considerations to keep in mind when writing said app that might differ from just a standalone tomcat on a server?在编写可能与服务器上的独立 tomcat 不同的应用程序时,是否有任何特殊的设计注意事项需要牢记?

For example, I understand that the server is meant to scale automatically.例如,我知道服务器旨在自动扩展。 Is this like a cluster?这像一个集群吗? Our application framework tends to like to stick state in the HttpSession, is that a problem?我们的应用程序框架倾向于在 HttpSession 中粘贴状态,这是一个问题吗? Or when it says it scales automatically, does that just mean memory and CPU?或者当它说它会自动扩展时,这是否只是意味着内存和 CPU?

Automatic scaling on AWS is done via adding more servers, not adding more CPU/RAM. AWS 上的自动扩展是通过添加更多服务器来完成的,而不是添加更多 CPU/RAM。 You can add more CPU/RAM manually, but it requires shutting down the server for a minute to make the change, and then configuring any software running on the server to take advantage of the added RAM, so that's not the way automatic scaling is done.您可以手动添加更多 CPU/RAM,但需要关闭服务器一分钟才能进行更改,然后配置服务器上运行的任何软件以利用添加的 RAM,因此这不是自动扩展的方式.

Elastic Beanstalk is basically a management interface for Amazon EC2 servers, Elastic Load Balancers and Auto Scaling Groups. Elastic Beanstalk 基本上是 Amazon EC2 服务器、弹性负载均衡器和 Auto Scaling 组的管理界面。 It sets all that up for you and provides a convenient way of deploying new versions of your application easily.它为您设置了所有这些,并提供了一种轻松部署应用程序新版本的便捷方式。 Elastic Beanstalk will create EC2 servers behind an Elastic Load Balancer and use an Auto Scaling configuration to add more servers as your application load increases. Elastic Beanstalk 将在 Elastic Load Balancer 后面创建 EC2 服务器,并使用 Auto Scaling 配置在应用程序负载增加时添加更多服务器。 It handles adding the servers to the load balancer when they are ready to receive traffic, and removing them from the load balancer and deleting the extra servers when they are no longer needed.当它们准备好接收流量时,它处理将服务器添加到负载平衡器,并在不再需要它们时将它们从负载平衡器中移除并删除额外的服务器。

For your Java application running on Tomcat you have a few options to handle horizontal scaling well.对于在 Tomcat 上运行的 Java 应用程序,您有几个选项可以很好地处理水平缩放。 You can enable sticky sessions on the Load Balancer so that all requests from a specific user will go to the same server, thus keeping the HttpSession tied to the user.您可以在负载均衡器上启用粘性会话,以便来自特定用户的所有请求都将转到同一服务器,从而使 HttpSession 与用户绑定。 The main problem with this is that if a server is removed from the pool you may lose some HttpSessions and cause any users that were "stuck" to that server to be logged out of your application.这样做的主要问题是,如果从池中删除服务器,您可能会丢失一些 HttpSession,并导致任何“卡住”到该服务器的用户从您的应用程序中注销。 The solution to this is to configure your Tomcat instances to store sessions in a shared location.对此的解决方案是配置 Tomcat 实例以将会话存储在共享位置。 There are Tomcat session store implementations out there that work with AWS services like ElastiCache ( Redis ) and DynamoDB .有 Tomcat 会话存储实现可以与 ElastiCache ( Redis ) 和DynamoDB等 AWS 服务配合使用 I would recommend using one of those, probably the Redis implementation if you aren't already familiar with DynamoDB.如果您还不熟悉 DynamoDB,我建议您使用其中之一,可能是 Redis 实现。


Another consideration for moving a Java application to AWS is that you cannot use any tools or libraries that rely on multi-cast.将 Java 应用程序迁移到 AWS 的另一个考虑因素是您不能使用任何依赖于多播的工具或库。 You may not be using multi-cast for anything, but in my experience every Java app I've had to migrate to AWS relied on multi-cast for clustering and I had to modify it to use a different clustering method.您可能不会为任何事情使用多播,但根据我的经验,我不得不迁移到 AWS 的每个 Java 应用程序都依赖多播进行集群,我不得不修改它以使用不同的集群方法。

Also, for a successful migration to AWS I suggest you read up a bit on VPCs, private IP versus public IP, and Security Groups.此外,为了成功迁移到 AWS,我建议您阅读一些有关 VPC、私有 IP 与公共 IP 以及安全组的信息。 A solid understanding of those topics is key to setting up your network so that your web servers can communicate with your DB and cache servers in a secure and performant manner.充分理解这些主题是设置网络的关键,这样您的 Web 服务器就可以以安全且高效的方式与数据库和缓存服务器进行通信。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM