使用橡胶在 ec2 上部署后不断出现 504 网关超时

发布于 2025-01-08 16:46:47 字数 319 浏览 0 评论 0原文

我使用橡胶宝石在 ec2 上部署我的应用程序。 我按照此处的说明操作: http://ramenlab.wordpress.com/2011/06/24/deploying-your-rails-app-to-aws-ec2-using-rubber/
该过程似乎成功完成,但当我尝试使用该应用程序时,我不断收到 504 网关超时消息。 为什么会发生这种情况以及如何解决它?

I used the rubber gem to deploy my application on ec2.
I followed the instructions here: http://ramenlab.wordpress.com/2011/06/24/deploying-your-rails-app-to-aws-ec2-using-rubber/.
The process seems to finish successfully but when I try to use the app I keep getting 504 gateway time-out.
Why is this happening and how do I fix it?

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

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

发布评论

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

评论(2

心安伴我暖 2025-01-15 16:46:47

Matthew Conway 的回答(转贴如下):https://groups.google.com/forum/?fromgroups#!searchin/rubber-ec2/504/rubber-ec2/AtEoOf-T9M0/zgda0Fo1qeIJ

注意:即使使用此代码,您需要做类似的事情:

>上限部署:更新

> FILTER=app01,app02 上限部署:重新启动

> FILTER=app03,app04 上限部署:重新启动


我认为这是一个 Rails 应用程序? Rails 堆栈的加载速度非常慢,因此加载时间的延迟可能就是您所看到的。 Passenger 本来应该通过零停机功能 v3 来改善这一点,但他们似乎违背了这一点,并且只会在未来的某个不确定的时间点将其作为某些未定义的付费版本的一部分提供。

我所做的是拥有多个应用程序服务器实例并按顺序重新启动它们,以便我可以继续在其中一个实例上提供流量,而其他实例则重新启动。不适用于单个实例,但大多数生产设置无论如何都需要多个实例来实现冗余/可靠性。这目前不是橡胶的一部分,但我让它为我的应用程序部署脚本设置,并将在某个时候将其合并 - 我的配置如下所示。

马特

橡胶-passenger.yml:

roles:
  passenger:
    rolling_restart_port: "#{passenger_listen_port}"

  web_tools:
    rolling_restart_port: "#{web_tools_port}"

部署-apache.rb:

on :load do
  rubber.serial_task self, :serial_restart, :roles => [:app, :apache] do
    rsudo "service apache2 restart"
  end
  rubber.serial_task self, :serial_reload, :roles => [:app, :apache] do
    # remove file checked by haproxy to take server out of pool, wait some
    # secs for haproxy to realize it
    maybe_sleep = " && sleep 5" if RUBBER_ENV == 'production'
    rsudo "rm -f #{previous_release}/public/httpchk.txt #{current_release}/public/httpchk.txt#{maybe_sleep}"

    rsudo "if ! ps ax | grep -v grep | grep -c apache2 &> /dev/null; then service apache2 start; else service apache2 reload; fi"

    # Wait for passenger to startup before adding host back into haproxy pool
    logger.info "Waiting for passenger to startup"

    opts = get_host_options('rolling_restart_port') {|port| port.to_s}
    rsudo "while ! curl -s -f http://localhost:$CAPISTRANO:VAR$/ &> /dev/null; do echo .; done", opts

    # Touch the file so that haproxy adds this server back into the pool.
    rsudo "touch #{current_path}/public/httpchk.txt#{maybe_sleep}"
  end
end

after "deploy:restart", "rubber:apache:reload"


desc "Starts the apache web server"
task :start, :roles => :apache do
  rsudo "service apache2 start"
  opts = get_host_options('rolling_restart_port') {|port| port.to_s}
  rsudo "while ! curl -s -f http://localhost:$CAPISTRANO:VAR$/ &> /dev/null; do echo .; done", opts
  rsudo "touch #{current_path}/public/httpchk.txt"
end

Answer from Matthew Conway (reposted below): https://groups.google.com/forum/?fromgroups#!searchin/rubber-ec2/504/rubber-ec2/AtEoOf-T9M0/zgda0Fo1qeIJ

Note: Even with this code you need to do something like:

> cap deploy:update

> FILTER=app01,app02 cap deploy:restart

> FILTER=app03,app04 cap deploy:restart


I assume this is a rails application? The rails stack is notoriously slow to load up, so this delay in load time is probably what you are seeing. Passenger was supposed to make this better with the zero downtime feature v3, but they seemed to have reneged on that and are only going to be offering it as part of some undefined paid version at some undefined point n the future.

What I do is have multiple app server instances and restart them serially so that I can continue to serve traffic on one, while the others are restarting. Doesn't work with a single instance, but most production setups need multiple instances for redundancy/reliability anyway. This isn't currently part of rubber, but I have it deploy scripts setup for my app and will merge it in at some point - my config looks something like the below.

Matt

rubber-passenger.yml:

roles:
  passenger:
    rolling_restart_port: "#{passenger_listen_port}"

  web_tools:
    rolling_restart_port: "#{web_tools_port}"

deploy-apache.rb:

on :load do
  rubber.serial_task self, :serial_restart, :roles => [:app, :apache] do
    rsudo "service apache2 restart"
  end
  rubber.serial_task self, :serial_reload, :roles => [:app, :apache] do
    # remove file checked by haproxy to take server out of pool, wait some
    # secs for haproxy to realize it
    maybe_sleep = " && sleep 5" if RUBBER_ENV == 'production'
    rsudo "rm -f #{previous_release}/public/httpchk.txt #{current_release}/public/httpchk.txt#{maybe_sleep}"

    rsudo "if ! ps ax | grep -v grep | grep -c apache2 &> /dev/null; then service apache2 start; else service apache2 reload; fi"

    # Wait for passenger to startup before adding host back into haproxy pool
    logger.info "Waiting for passenger to startup"

    opts = get_host_options('rolling_restart_port') {|port| port.to_s}
    rsudo "while ! curl -s -f http://localhost:$CAPISTRANO:VAR$/ &> /dev/null; do echo .; done", opts

    # Touch the file so that haproxy adds this server back into the pool.
    rsudo "touch #{current_path}/public/httpchk.txt#{maybe_sleep}"
  end
end

after "deploy:restart", "rubber:apache:reload"


desc "Starts the apache web server"
task :start, :roles => :apache do
  rsudo "service apache2 start"
  opts = get_host_options('rolling_restart_port') {|port| port.to_s}
  rsudo "while ! curl -s -f http://localhost:$CAPISTRANO:VAR$/ &> /dev/null; do echo .; done", opts
  rsudo "touch #{current_path}/public/httpchk.txt"
end
谁许谁一生繁华 2025-01-15 16:46:47

我遇到了同样的错误并解决了问题。
这是“haproxy”超时。它是由Rubber安装的负载均衡器。
它设置为30000ms,您应该在rubber 配置文件中更改它。

祝你好运!

I got the same error and solved the problem.
It was "haproxy" timeout. It is a load balancer installed by Rubber.
It is set to 30000ms, you should change it in rubber configuration file.

Good luck!

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