Git 将 PHP 应用程序部署到多个 EC2 节点

发布于 2024-10-30 04:05:18 字数 267 浏览 1 评论 0原文

我读过很多关于使用 Git 部署网站的更新后挂钩的文章,但我不明白这是如何在 EC2 上完成的。

我想使用 EC2 的 Auto Scaling 功能根据服务器的 AMI 自动在负载均衡器后面添加微型/小型节点。

我怎样才能做到这一点:

  1. 我的节点在启动时自动从存储库获取最新版本的站点

  2. 将更新推送到所有节点(如果可能,立即触发更新),甚至是动态添加的节点(因此没有超出 AMI 已包含内容的配置)。

I've been reading a lot of articles that talk about post-update hooks to deploy websites using Git, however I don't understand how this is done on EC2.

I want to use the Auto Scaling feature of EC2 to automatically add micro/small nodes behind my load balancer based off an AMI of my server.

How can I make it so:

  1. My nodes automatically fetch the latest version of the site from the repository upon starting

  2. Push updates to all nodes (trigger update immediately if possible), even the ones that are dynamically added (therefore no configuration beyond what the AMI already contained).

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

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

发布评论

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

评论(1

氛圍 2024-11-06 04:05:18

就自动化工具而言,您可以使用 puppet 或 Chef 来完成工作。这些背后的公司也提供托管服务:

我们个人使用 scalarium 来部署我们的服务器并自动缩放它们。

如果这不是您想要的,您可以为 Chef 编写自己的脚本以部署在实例上。已经有一个可以很好地与 git 配合使用的部署资源。我可能会推荐chef-solo,因为这不需要运行chef-server(也有很多依赖项和需要管理)或类似littlechef 它允许您运行类似厨师服务器的设置,但没有运行厨师服务器的负担。

例如,目标是设置 Amazon 用于自动扩展的私有 AMI。

该 AMI 将安装您的服务(HTTP 等)、Ruby 和 Chef(gem install Chef)以及您需要的任何其他内容,然后依次运行脚本以进一步设置您的实例并部署代码来自吉特。

如果您沿着这条路径走下去,您当然可以根据 AMI 的需要设置尽可能多的服务,然后您只需要 Chef 来部署代码。

下面是一个使用厨师食谱从 GIT 检查代码的示例:

git "/var/www/example.org" do
  repository "git://github.com/yourname/example.git"
  revision "production"
  action :sync
end

这将从 git 检查您的生产分支。

由于默认情况下以 root 身份运行,因此您的部署密钥应该位于 /root/.ssh/id_rsa 中。您可以在创建私有 AMI 之前执行此操作。您还可以在部署之前从安全位置获取密钥:(

directory "/root/.ssh/" do
  action :create
end

execute "download my deploy key" do
  command "wget https://secure.location/id_rsa -O /root/.ssh/id_rsa"
  not_if do File.exists?("/root/.ssh/id_rsa") end
end

我刚刚输入了此内容,我还没有运行它 - 但我几乎确定它应该可以工作,因为我们在非 EC2 上做了非常类似的事情 -主机。)

如果您不运行 Chef-server 或 Little-chef,我会使用 capistrano 再次执行 Chef-solo – 例如,检查代码的新版本。 Capistrano 会向实例发送命令(通过 ssh),为此我可能会使用 ssh 密钥设置一个无密码帐户等。

如果您需要更多指示,请告诉我!

As far as automation tools are concerned you could use puppet or chef to get the job done. The companies behind those offer hosted services as well:

Personally we use scalarium to deploy our servers and to autoscale them.

If that's not what you want, you could for example write your own scripts for chef to deploy on an instance. There's already a deploy resource which works very well with git. I'd probably recommend chef-solo since this wouldn't require running chef-server (has lots of dependencies and needs management as well) or something like littlechef which allows you to run a chef-server-like setup but without the burdon of running chef-server.

The objective would be to for example setup a private AMI which Amazon uses to autoscale.

This AMI would have your services (HTTP, etc.), ruby and chef installed (gem install chef) and whatever else you need and then in turn run the scripts to further setup your instance and deploy the code from GIT.

If you go down this path you can of course setup as many services as required with the AMI and then you would only need chef to deploy the code.

Here's an example to check out code from GIT using a chef recipe:

git "/var/www/example.org" do
  repository "git://github.com/yourname/example.git"
  revision "production"
  action :sync
end

This would check out your production branch from git.

Since this runs as root by default, you should have your deploykey in /root/.ssh/id_rsa. You could do that before you create the private AMI. You could also fetch the key from a secure location before you deploy:

directory "/root/.ssh/" do
  action :create
end

execute "download my deploy key" do
  command "wget https://secure.location/id_rsa -O /root/.ssh/id_rsa"
  not_if do File.exists?("/root/.ssh/id_rsa") end
end

(I just typed this out, I haven't run this – but I'm almost sure it should work since we do something very similar on non-EC2-hosts.)

If you don't run chef-server or little-chef, I'd use capistrano to execute chef-solo again – e.g. to check out a new revision of the code. Capistrano would send commands to the instance (via ssh), for which I'd probably setup a password-less account with an ssh key, etc..

Let me know if you need more pointers!

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