繁体   English   中英

AWS Elastic Beanstalk - Ruby 3.0 在 64 位亚马逊上运行 Linux 2/3.4.4 - 100.0% 的请求失败并显示 HTTP 5xx

[英]AWS Elastic Beanstalk - Ruby 3.0 running on 64bit Amazon Linux 2/3.4.4 - 100.0 % of the requests are failing with HTTP 5xx

今天对我们所有人来说又是美好的一天:)

我正在尝试使用运行在 64 位 Amazon Linux 2/3.4.4 上的 AWS EB Ruby 3.0 和 Ruby-on-Rails v6.0.4.4 应用程序,但直到现在,我还没有设法让它工作

在环境状态下,我得到:

100.0 % of the requests are failing with HTTP 5xx

也在 /var/log/nginx/error.log 中

[error] 2459#2459: *596 connect() to unix:///var/run/puma/my_app.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 172.31.34.113, server: _, request: "POST / HTTP/1.1", upstream: "http://unix:///var/run/puma/my_app.sock:/", host: "52.29.66.93"

在 /var/log/puma/puma.log 中

[4898] ! Unable to start worker
[4898] /opt/rubies/ruby-3.0.3/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:309:in `check_for_activated_spec!'
[4898] Early termination of worker

pumactl看起来不错

[ec2-user@ip-172-31-xx-xx ~]$ pumactl -V
5.6.2

如果我检查流程:

ps aux | grep puma
    healthd  25925  0.0  3.6 828800 36624 ?        Ssl  09:39   0:15 puma 5.3.2 (tcp://127.0.0.1:22221) [healthd]
    webapp   26497  0.2  2.2 255768 22912 ?        Ss   09:40   1:07 puma 5.6.2 (unix:///var/run/puma/my_app.sock) [current]
    webapp   28653 64.0  2.1 327180 21668 ?        Rl   16:08   0:00 puma: cluster worker 0: 26497 [current]
    ec2-user 28656  0.0  0.0 119420   924 pts/0    S+   16:08   0:00 grep --color=auto puma

所以美洲狮在跑……对吗?

此外,还有另一个 puma v5.3.2

也许其他 puma 版本是出于其他原因(健康服务)使用的?

在 Rails 应用程序中,我有以下内容:

.ebextensions/02_yarn.config

commands:

  01_node_get:
    cwd: /tmp
    command: 'curl --silent --location https://rpm.nodesource.com/setup_14.x | sudo bash -'
  02_node_install:
    cwd: /tmp
    command: 'yum -y install nodejs'
  03_yarn_get:
    cwd: /tmp
    # don't run the command if yarn is already installed (file /usr/bin/yarn exists)
    test: '[ ! -f /usr/bin/yarn ] && echo "yarn not installed"'
    command: 'sudo wget https://dl.yarnpkg.com/rpm/yarn.repo -O /etc/yum.repos.d/yarn.repo'
  04_yarn_install:
    cwd: /tmp
    test: '[ ! -f /usr/bin/yarn ] && echo "yarn not installed"'
    command: 'sudo yum -y install yarn'
  05_mkdir_webapp_dir:
    command: "mkdir /home/webapp"
    ignoreErrors: true
  06_chown_webapp_dir:
    command: "chown webapp:webapp /home/webapp"
    ignoreErrors: true
  07_chmod_webapp_dir:
    command: "chmod 0744 /home/webapp"
    ignoreErrors: true
  08_chmod_logs:
    command: "chown webapp:webapp -R /var/app/current/log/"
    ignoreErrors: true
  09_create_log_file:
    command: "touch /var/app/current/log/production.log"
    ignoreErrors: true
  10_chown_log_production:
    command: "chown webapp:webapp /var/app/current/log/production.log"
    ignoreErrors: true
  11_chmod_log_dir:
    command: "chmod 0664 -R /var/app/current/log/"
    ignoreErrors: true
  12_update_bundler:
    command: "gem update bundler"
    ignoreErrors: true
  13_chown_current:
    command: "chown webapp:webapp -R /var/app/current/"
    ignoreErrors: true
  14_chmod_current:
    command: "chmod 0755 -R /var/app/current/"
    ignoreErrors: true
  15_chown_current:
    command: "chown webapp:webapp -R /var/app/ondeck/"
    ignoreErrors: true
  16_chown_current:
    command: "chmod 0644 -R /var/app/ondeck/"
    ignoreErrors: true

container_commands:

  17_install_webpack:
    command: "npm install --save-dev webpack"
  18_precompile:
    command: "bundle exec rake assets:precompile"

.ebextensions/03_nginx.config

files:
  "/etc/nginx/conf.d/02_app_server.conf":
    mode: "000644"
    owner: root
    group: root
    content: |
      # The content of this file is based on the content of /etc/nginx/conf.d/webapp_healthd.conf

      # Change the name of the upstream because it can't have the same name
      # as the one defined by default in /etc/nginx/conf.d/webapp_healthd.conf
      upstream new_upstream_name {
        server unix:///var/run/puma/my_app.sock;
      }

      # Change the name of the log_format because it can't have the same name
      # as the one defined by default in /etc/nginx/conf.d/webapp_healthd.conf
      log_format new_log_name_healthd '$msec"$uri"'
                      '$status"$request_time"$upstream_response_time"'
                      '$http_x_forwarded_for';

      server {
        listen 80;
        server_name _ localhost; # need to listen to localhost for worker tier

        if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") {
          set $year $1;
          set $month $2;
          set $day $3;
          set $hour $4;
        }

        access_log  /var/log/nginx/access.log  main;
        # Match the name of log_format directive which is defined above
        access_log /var/log/nginx/healthd/application.log.$year-$month-$day-$hour new_log_name_healthd;

        location / {
          # Match the name of upstream directive which is defined above
          proxy_pass http://new_upstream_name;
          proxy_set_header Host $host;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        location /assets {
          alias /var/app/current/public/assets;
          gzip_static on;
          gzip on;
          expires max;
          add_header Cache-Control public;
        }

        location /public {
          alias /var/app/current/public;
          gzip_static on;
          gzip on;
          expires max;
          add_header Cache-Control public;
        }

        location /packs {
          alias /var/app/current/public/packs;
          gzip_static on;
          gzip on;
          expires max;
          add_header Cache-Control public;
        }
      }

container_commands:
  01_restart_nginx:
    command: "sudo service nginx reload"

任何想法为什么它不起作用?

.ebextensions/03_nginx.configfiles部分中有/etc/nginx/conf.d/02_app_server.conf的条目,但没有这样的文件:

ls -ls /etc/nginx/conf.d/
total 8
0 drwxr-xr-x 2 root root  45 Apr  8 15:42 elasticbeanstalk
4 -rw-r--r-- 1 root root  62 Apr  8 15:42 elasticbeanstalk-nginx-ruby-upstream.conf
4 -rw-r--r-- 1 root root 147 Apr  8 15:42 healthd_logformat.conf

这个可以吗?

非常感谢您的帮助和支持以及您宝贵的时间

我希望我们所有人都能在我们的生活中一切顺利和精彩的延续......

由于您使用的是Amazon Linux 2 ,因此您的 nginx 设置将永远不起作用。 这是因为它们适用于 AL1,但您使用的是 AL2。 您的所有 nginx 设置都应通过.platform/nginx/conf.d/定义,而不是.ebextentions ,如文档中所述。

暂无
暂无

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

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