在 Amazon EC2 上为 Java Web 应用程序构建简单、可扩展集群的最佳实践

发布于 2024-08-26 21:12:55 字数 380 浏览 6 评论 0原文

我想构建一个 Java Web 应用程序并将其部署在 EC2 上。它将用 Java 编写并使用 MySQL。我希望获得有关实际部署过程和配置的一些指导。我对以下主题特别感兴趣:

  • 机器映像(DIY 与现成的)
  • mysql 复制和备份到 S3
  • 不间断地将应用程序部署和重新部署到 EC2 的方法
  • 防火墙?
  • 负载平衡和自动扩展
  • cloudtools(或替代工具)

I want to build a Java web app and deploy it on EC2. It will be written in Java and will use MySQL. I was hoping to get some pointers on the actual deployment process and configuration. In particular I'm interested in the following topics:

  • machine images (DIY vs ready made)
  • mysql replication and backup to S3
  • ways of deploying and redeploying the app to EC2 without interruptions
  • firewalls?
  • load balancing and auto scaling
  • cloudtools (or alternative tools)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆伤 2024-09-02 21:12:55

我只能根据经验谈谈你们讨论的一些要点。我不得不删除指向各种亚马逊产品的超链接,因为我是 Stackoverflow 的新手,并且没有足够的代表来发布多个链接。

机器映像:虽然您当然可以从自己的机器映像开始,并使用 EC2 AMI 工具将其转换为 AMI,但我更喜欢从 Amazon 的现成映像之一开始,然后对其进行自定义以满足我的需求。这样做的好处是,您已经知道将部署基础映像,您更有可能在论坛上或从 EC2 工作人员那里获得帮助,并且您不必经历设置物理机或您自己的虚拟机,以便捆绑图像并上传它。如果您使用 EC2 API 工具,则可以使用 ec2-describe-images -o amazon 获取可用基础映像的列表。

MySQL 复制和备份:查看新的 Amazon Relational Database Service。它旨在与 MySQL 配合使用,可以执行自动备份,并且可以轻松扩展。

防火墙:使用 API 工具可以轻松处理实例的防火墙。例如,您可以创建一个组,

ec2-add-group condor –d “Condor Workers”

为该组设置防火墙规则(不好的示例 - 打开 CIDR 范围的所有 UDP 和 TCP 端口),

ec2-authorize condor -P tcp -p 0-65535 -s 129.127.0.0/16
ec2-authorize condor -P udp -p 0-65535 -s 129.127.0.0/16

然后作为该组的一部分启动您的实例,以便它们继承防火墙规则。

ec2-run-instances ami-12345678 –g condor –k mykeypair

棘手的部分是走向另一个方向——允许您的 EC2 实例与您的公司/学校/个人网络进行通信。由于您不知道您的实例在启动之前将拥有什么 IP(Amazon Elastic IP 可以在一定程度上缓解这种情况),因此您通常被迫允许 EC2 云的某些子网。

您还可以在实例上设置 Iptables 或其他防火墙。

负载均衡:考虑 Amazon Elastic Load Balancing。如果这不适合您的需求,您可以创建自己的“虚拟集群”并使用您喜欢的任何框架。

I can only speak to a few of your discussion points from experience. I've had to strip out hyperlinks to the various Amazon products because I'm new to Stackoverflow and don't have enough rep to post more than one link.

Machine Images: While you can certainly start with your own machine image and convert it to an AMI with the EC2 AMI Tools, I prefer starting with one of Amazon's ready made images and customizing it to suit my needs. The advantage here is that you already know that the base image will deploy, you're more likely to get help on the forum or from the EC2 staff, and you don't have to go through the trouble of setting up a physical machine or your own VM in order to bundle the image and upload it. If you're using the EC2 API Tools, you can get a list of the available base images with ec2-describe-images -o amazon.

MySQL Replication and Backup: Check out the new(ish) Amazon Relational Database Service. It's designed to work with MySQL, can perform automatic backups, and scales easily.

Firewalls: Handling the firewalls for your instances is easy with the API tools. For example, you can create a group,

ec2-add-group condor –d “Condor Workers”

setup firewall rules for that group (bad example - opens all UDP and TCP ports for a CIDR range),

ec2-authorize condor -P tcp -p 0-65535 -s 129.127.0.0/16
ec2-authorize condor -P udp -p 0-65535 -s 129.127.0.0/16

and then launch your instances as part of the group, so that they inherit the firewall rules.

ec2-run-instances ami-12345678 –g condor –k mykeypair

The tricky part is going the other direction -- allowing your EC2 instances to communicate with your company/school/personal network. Since you don't know what IP your instances will have before they start (Amazon Elastic IP can alleviate this to some extent) you're generally forced to allow some subnet of the EC2 cloud.

You can also setup Iptables or additional firewalls on your instances.

Load Balancing: Consider Amazon Elastic Load Balancing. If that doesn't suit your needs, you can create your own "virtual cluster" and use whatever framework you like.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文