简体   繁体   English

使用Capistrano部署后,无法在运行Puma 3.6的AWS EC2实例的生产环境中访问Rails 5 App

[英]Can't access the Rails 5 App in production on AWS EC2 instance running Puma 3.6 after deployment with Capistrano

I have a very simple app with only a header test to be rendered on a home page that should be accessible at my server public IP, something like this: 我有一个非常简单的应用程序,只在首页上呈现了标题测试,应该可以在服务器的公共IP上访问它,如下所示:

http://54.88.181.57:3000

In development the app is working: 在开发中,该应用正在运行:

http://localhost:3000/

rendering the very simple message: 呈现非常简单的消息:

Tasks home page

In production Puma is available here: 在生产中,Puma可在此处获得:

$ ps -ef | grep puma
deploy    5653     1  0 16:23 ?        00:00:01 puma 3.6.0 (unix:///home/deploy/tasks/shared/tmp/sockets/puma.sock) [20160924162316]                                 

The instance is a AWS EC2 Ubuntu 14.04 There are no issues with the DB which is a AWS RDS Postgresql database (accordingly with the production.log) and I can access it anytime using: 该实例是AWS EC2 Ubuntu 14.04,该数据库没有问题,该数据库是AWS RDS Postgresql数据库(根据production.log),我可以随时使用以下方式访问它:

$ psql --host tasks.cbb3snhbk4wo.us-east-1.rds.amazonaws.com --port 5432 --username tasks --dbname tasks
Password for user tasks: 
psql (9.3.14, server 9.5.2)
WARNING: psql major version 9.3, server major version 9.5.
         Some psql features might not work.
SSL connection (cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256)
Type "help" for help.

tasks=> \dt
               List of relations
 Schema |         Name         | Type  | Owner 
--------+----------------------+-------+-------
 public | ar_internal_metadata | table | tasks
 public | schema_migrations    | table | tasks
(2 rows)

tasks=> \q

There are no error messages reports in the log files, below is the content of the log files. 日志文件中没有错误消息报告,以下是日志文件的内容。

$ pwd
/home/deploy/tasks/current/log

$ cat production.log 
D, [2016-09-24T12:16:07.190313 #30239] DEBUG -- :    (2.5ms)  SELECT pg_try_advisory_lock(2768007245500244475);
D, [2016-09-24T12:16:07.200361 #30239] DEBUG -- :   ActiveRecord::SchemaMigration Load (2.7ms)  SELECT "schema_migrations".* FROM "schema_migrations"
D, [2016-09-24T12:16:07.220410 #30239] DEBUG -- :   ActiveRecord::InternalMetadata Load (1.5ms)  SELECT  "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2  [["key", :environment], ["LIMIT", 1]]
D, [2016-09-24T12:16:07.226223 #30239] DEBUG -- :    (1.3ms)  BEGIN
D, [2016-09-24T12:16:07.228361 #30239] DEBUG -- :    (1.4ms)  COMMIT
D, [2016-09-24T12:16:07.229899 #30239] DEBUG -- :    (1.4ms)  SELECT pg_advisory_unlock(2768007245500244475)
D, [2016-09-24T14:10:42.585283 #1857] DEBUG -- :    (2.6ms)  SELECT pg_try_advisory_lock(2768007245500244475);
D, [2016-09-24T14:10:42.603894 #1857] DEBUG -- :   ActiveRecord::SchemaMigration Load (5.2ms)  SELECT "schema_migrations".* FROM "schema_migrations"
D, [2016-09-24T14:10:42.626674 #1857] DEBUG -- :   ActiveRecord::InternalMetadata Load (1.6ms)  SELECT  "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2  [["key", :environment], ["LIMIT", 1]]
D, [2016-09-24T14:10:42.639144 #1857] DEBUG -- :    (1.6ms)  BEGIN
D, [2016-09-24T14:10:42.641200 #1857] DEBUG -- :    (1.2ms)  COMMIT
D, [2016-09-24T14:10:42.642593 #1857] DEBUG -- :    (1.3ms)  SELECT pg_advisory_unlock(2768007245500244475)
D, [2016-09-24T15:32:06.662915 #2622] DEBUG -- :    (2.6ms)  SELECT pg_try_advisory_lock(2768007245500244475);
D, [2016-09-24T15:32:06.672595 #2622] DEBUG -- :   ActiveRecord::SchemaMigration Load (2.4ms)  SELECT "schema_migrations".* FROM "schema_migrations"
D, [2016-09-24T15:32:06.702690 #2622] DEBUG -- :   ActiveRecord::InternalMetadata Load (1.6ms)  SELECT  "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2  [["key", :environment], ["LIMIT", 1]]
D, [2016-09-24T15:32:06.708799 #2622] DEBUG -- :    (1.3ms)  BEGIN
D, [2016-09-24T15:32:06.710904 #2622] DEBUG -- :    (1.3ms)  COMMIT
D, [2016-09-24T15:32:06.712580 #2622] DEBUG -- :    (1.5ms)  SELECT pg_advisory_unlock(2768007245500244475)
D, [2016-09-24T15:44:15.659955 #3517] DEBUG -- :    (1.3ms)  SELECT pg_try_advisory_lock(2768007245500244475);
D, [2016-09-24T15:44:15.669138 #3517] DEBUG -- :   ActiveRecord::SchemaMigration Load (1.8ms)  SELECT "schema_migrations".* FROM "schema_migrations"
D, [2016-09-24T15:44:15.682996 #3517] DEBUG -- :   ActiveRecord::InternalMetadata Load (1.4ms)  SELECT  "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2  [["key", :environment], ["LIMIT", 1]]
D, [2016-09-24T15:44:15.694242 #3517] DEBUG -- :    (1.2ms)  BEGIN
D, [2016-09-24T15:44:15.696341 #3517] DEBUG -- :    (1.2ms)  COMMIT
D, [2016-09-24T15:44:15.697750 #3517] DEBUG -- :    (1.3ms)  SELECT pg_advisory_unlock(2768007245500244475)
D, [2016-09-24T16:03:29.398817 #4802] DEBUG -- :    (1.3ms)  SELECT pg_try_advisory_lock(2768007245500244475);
D, [2016-09-24T16:03:29.407495 #4802] DEBUG -- :   ActiveRecord::SchemaMigration Load (1.6ms)  SELECT "schema_migrations".* FROM "schema_migrations"
D, [2016-09-24T16:03:29.421703 #4802] DEBUG -- :   ActiveRecord::InternalMetadata Load (1.6ms)  SELECT  "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2  [["key", :environment], ["LIMIT", 1]]
D, [2016-09-24T16:03:29.432893 #4802] DEBUG -- :    (1.6ms)  BEGIN
D, [2016-09-24T16:03:29.435183 #4802] DEBUG -- :    (1.5ms)  COMMIT
D, [2016-09-24T16:03:29.436803 #4802] DEBUG -- :    (1.5ms)  SELECT pg_advisory_unlock(2768007245500244475)
D, [2016-09-24T16:23:25.345080 #5561] DEBUG -- :    (1.4ms)  SELECT pg_try_advisory_lock(2768007245500244475);
D, [2016-09-24T16:23:25.353737 #5561] DEBUG -- :   ActiveRecord::SchemaMigration Load (1.4ms)  SELECT "schema_migrations".* FROM "schema_migrations"
D, [2016-09-24T16:23:25.368330 #5561] DEBUG -- :   ActiveRecord::InternalMetadata Load (1.6ms)  SELECT  "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2  [["key", :environment], ["LIMIT", 1]]
D, [2016-09-24T16:23:25.379551 #5561] DEBUG -- :    (1.5ms)  BEGIN
D, [2016-09-24T16:23:25.381611 #5561] DEBUG -- :    (1.3ms)  COMMIT
D, [2016-09-24T16:23:25.383051 #5561] DEBUG -- :    (1.3ms)  SELECT pg_advisory_unlock(2768007245500244475)

$ cat puma_access.log 
=== puma startup: 2016-09-24 12:16:08 +0000 ===
=== puma startup: 2016-09-24 14:10:43 +0000 ===
=== puma startup: 2016-09-24 15:32:08 +0000 ===
=== puma startup: 2016-09-24 15:44:17 +0000 ===
=== puma startup: 2016-09-24 16:03:30 +0000 ===
=== puma startup: 2016-09-24 16:23:26 +0000 ===

$ cat puma_error.log 
=== puma startup: 2016-09-24 12:16:08 +0000 ===
* Listening on unix:///home/deploy/tasks/shared/tmp/sockets/puma.sock
- Gracefully stopping, waiting for requests to finish
=== puma shutdown: 2016-09-24 13:45:35 +0000 ===
- Goodbye!
=== puma startup: 2016-09-24 14:10:43 +0000 ===
* Listening on unix:///home/deploy/tasks/shared/tmp/sockets/puma.sock
* Restarting...
Refreshing Gemfile
Puma starting in single mode...
* Version 3.6.0 (ruby 2.3.1-p112), codename: Sleepy Sunday Serenity
* Min threads: 0, max threads: 8
* Environment: production
* Daemonizing...
=== puma startup: 2016-09-24 15:32:08 +0000 ===
* Inherited unix:///home/deploy/tasks/shared/tmp/sockets/puma.sock
* Restarting...
Refreshing Gemfile
Puma starting in single mode...
* Version 3.6.0 (ruby 2.3.1-p112), codename: Sleepy Sunday Serenity
* Min threads: 0, max threads: 8
* Environment: production
* Daemonizing...
=== puma startup: 2016-09-24 15:44:17 +0000 ===
* Inherited unix:///home/deploy/tasks/shared/tmp/sockets/puma.sock
* Restarting...
Refreshing Gemfile
Puma starting in single mode...
* Version 3.6.0 (ruby 2.3.1-p112), codename: Sleepy Sunday Serenity
* Min threads: 0, max threads: 8
* Environment: production
* Daemonizing...
=== puma startup: 2016-09-24 16:03:30 +0000 ===
* Inherited unix:///home/deploy/tasks/shared/tmp/sockets/puma.sock
* Restarting...
Refreshing Gemfile
Puma starting in single mode...
* Version 3.6.0 (ruby 2.3.1-p112), codename: Sleepy Sunday Serenity
* Min threads: 0, max threads: 8
* Environment: production
* Daemonizing...
=== puma startup: 2016-09-24 16:23:26 +0000 ===
* Inherited unix:///home/deploy/tasks/shared/tmp/sockets/puma.sock

And this is my puma.rb config file: 这是我的puma.rb配置文件:

$ cat /home/deploy/tasks/current/config/puma.rb 

app_dir = File.expand_path("../..", __FILE__)
shared_dir = "#{app_dir}/shared"

threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i
threads threads_count, threads_count

port        ENV.fetch("PORT") { 3000 }
environment ENV.fetch("RAILS_ENV") { "development" }

workers ENV.fetch("WEB_CONCURRENCY") { 2 }
preload_app!

# Set up socket location
bind "unix://#{shared_dir}/sockets/puma.sock"

# Logging
stdout_redirect "#{shared_dir}/log/puma.stdout.log", "#{shared_dir}/log/puma.stderr.log", true

# Set master PID and state locations
pidfile "#{shared_dir}/pids/puma.pid"
state_path "#{shared_dir}/pids/puma.state"
activate_control_app

on_worker_boot do
  ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
end

plugin :tmp_restart

Don't know what is not right here and why I cannot access my app in production using the serve public IP and port 3000? 不知道这里有什么不正确的地方,为什么我不能使用服务公共IP和端口3000访问生产中的应用程序?

First, verify that Puma is indeed listening on port 3000 by running this command on the server: 首先,通过在服务器上运行以下命令来验证Puma确实在侦听端口3000:

netstat -an | grep 3000

You should see something like this: 您应该会看到以下内容:

tcp        0      0 0.0.0.0:3000    0.0.0.0:*    LISTEN

If Puma is listening on port 3000, then perhaps a firewall or other security policy is blocking access. 如果Puma正在侦听端口3000,则可能是防火墙或其他安全策略阻止了访问。

If Puma is not listening on port 3000, then I suspect the config/puma.rb file that you pasted in your question is not actually being loaded. 如果Puma没有在端口3000上侦听,那么我怀疑您粘贴在问题中的config/puma.rb文件实际上没有被加载。 As evidence, I see in the logs that Puma is binding to unix:///home/deploy/tasks/shared/tmp/sockets/puma.sock , but in the puma.rb you've specified shared/sockets/puma.sock (without the tmp ). 作为证据,我在日志中看到Puma绑定到unix:///home/deploy/tasks/shared/tmp/sockets/puma.sock ,但是在puma.rb您指定了shared/sockets/puma.sock (没有tmp )。

You haven't explained how exactly you started Puma, but whatever method you are using, make sure Puma is being sent the -C flag with the path to the puma.rb that you would like it to use. 您尚未解释启动Puma的确切方式,但是无论使用puma.rb ,请确保正在向Puma发送-C标志以及您要使用的puma.rb的路径。

If you are using the capistrano3-puma gem, then refer also to this related answer: Capistrano doesn't create puma.pid file 如果您使用的是capistrano3-puma gem,则也请参考以下相关答案: Capistrano不会创建puma.pid文件

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

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