2016-09-24 1 views
0

J'ai une application très simple avec seulement un test d'en-tête à rendre sur une page d'accueil qui devrait être accessible à mon serveur public IP, quelque chose comme ceci:Impossible d'accéder à l'application Rails 5 en production sur l'instance AWS EC2 exécutant Puma 3.6 après le déploiement avec Capistrano

http://54.88.181.57:3000 

Dans le développement de l'application fonctionne:

http://localhost:3000/ 

rendu le message très simple:

Tasks home page 

Dans la production Puma est disponible ici:

$ 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]         

L'instance est une Ubuntu AWS EC2 14,04 Il n'y a aucun problème avec la base de données qui est une base de données AWS RDS Postgresql (en conséquence avec le production.log) et je peut y accéder à tout moment à l'aide:

$ 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 

il n'y a pas de rapports des messages d'erreur dans les fichiers journaux, ci-dessous est le contenu des fichiers journaux.

$ 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 

Et voici mon puma.rb fichier de configuration:

$ 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 

Je ne sais pas ce qui est pas ici et pourquoi je ne peux pas accéder à mon application dans la production en utilisant le servir IP publique et le port 3000?

Répondre

1

Tout d'abord, vérifiez que Puma est en effet à l'écoute sur le port 3000 en exécutant cette commande sur le serveur:

netstat -an | grep 3000 

Vous devriez voir quelque chose comme ceci:

tcp  0  0 0.0.0.0:3000 0.0.0.0:* LISTEN 

Si Puma écoute sur le port 3000, alors peut-être un pare-feu ou une autre politique de sécurité bloque l'accès.

Si Puma n'écoute pas sur le port 3000, alors je soupçonne que le fichier config/puma.rb que vous avez collé dans votre question n'est pas réellement chargé. Comme preuve, je vois dans les journaux que Puma se lie à unix:///home/deploy/tasks/shared/tmp/sockets/puma.sock, mais dans le puma.rb vous avez spécifié shared/sockets/puma.sock (sans le tmp).

Vous n'avez pas expliqué comment exactement vous avez démarré Puma, mais quelle que soit la méthode que vous utilisez, assurez-vous que Puma reçoit le drapeau -C avec le chemin d'accès au puma.rb que vous souhaitez utiliser.

Si vous utilisez la gemme capistrano3-pumas, puis reportez-vous aussi à cette réponse connexe: Capistrano doesn't create puma.pid file

+0

Il a travaillé seulement après avoir fait les modifications suivantes: 1. utilisées «/tmp » lorsque cela est nécessaire; 2. Placez le fichier puma.rb dans les fichiers linked_files dans le fichier Capistrano deploy.rb; 3. simplifié le fichier puma.rb du serveur; 4. processus puma arrêtés (tués); 5. a commencé puma avec une commande spécifiant le port explicite 300 depuis que j'ai remarqué que sans ce puma a été démarré sur les ports au-dessus de 50 000, j'ai utilisé la commande: $ HOME/.rbenv/bin/rbenv exec bundle exec pumactl -S/home/deploy /tasks/shared/tmp/pids/puma.state restart -p 3000 –

+0

6.Maintenant, j'ai netstat -an | grep 3000 tcp 0 0 0.0.0.0:3000 0.0.0.0:* LISTEN mais uniquement après l'ajout d'une règle TCP personnalisée pour le port 3000 Anywhere dans le groupe de sécurité du serveur. –

+0

Pour démarrer/redémarrer Puma, j'ai utilisé les commandes du dossier "/ home/deploy/tasks/current" pour éviter les messages d'erreur tels que ".bundle not found" ou "Gemfile not found". –