前提・実現したいこと
Cloud9にて作成したRailsアプリをEC2経由でAWSにデプロイしようと試みております。
途中unicornをインストールしたのですが、
起動時にエラーが吐かれてしまい自身で調べても解決しなかったためご質問させていただきたいです。
発生している問題・エラーメッセージ
console
1[ec2-user@ip-172-31-36-245 git_toreka]$ bundle exec unicorn_rails -c config/unicorn.rb -E production -D 2master failed to start, check stderr log for details
エラー場所を確認
E, [2021-01-12T12:51:35.080644 #14762] ERROR -- : Access denied for user 'toreka'@'localhost' (using password: NO) (Mysql2::Error::ConnectionError) . . . E, [2021-01-13T12:26:53.188705 #27496] ERROR -- : Your password has expired. To log in you must change it using a client that supports expired passwords. (Mysql2::Error) . . . E, [2021-01-14T04:52:37.948095 #1474] ERROR -- : Your password has expired. To log in you must change it using a client that supports expired passwords. (Mysql2::Error) . . . E, [2021-01-14T05:58:16.048889 #2037] ERROR -- : Your password has expired. To log in you must change it using a client that supports expired passwords. (Mysql2::Error) . . .
このような形でMysqlにおけるエラーが複数記載されている形です。
試したこと
1つ目にあるAccess denied for user 'toreka'@'localhost' (using password: NO)
の箇所を直すことができれば他エラーも解消するのではないかと考えたためその点に絞って考えてみました。
「パスワードがないから開かない」とあるようなのでパスワードの設定を確認して見ました。
[ec2-user@ip-172-31-36-245 git_toreka]$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 14 Server version: 8.0.22 MySQL Community Server - GPL Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
mysqlには実際に入ることができます。
パスワードの設定はできています。
database.yml
に記載しているパスワードの記載が正しいかも確認してみました。
##database.yml . . . production: <<: *default database: <%= Rails.application.credentials.db[:database] %> username: <%= Rails.application.credentials.db[:username] %> password: <%= Rails.application.credentials.db[:password] %> socket: <%= Rails.application.credentials.db[:socket] %>
##credentials.yml db: database: dbname username: root password: xxxxxxxx socket: /var/lib/mysql/mysql.sock
パスワードも入力しておりました。
config/unicorn.rb
の中身も念のため貼っておきます。
##config/unicorn.rb [ec2-user@ip-172-31-36-245 git_toreka]$ cat config/unicorn.rb app_path = File.expand_path('../../', __FILE__) #アプリケーションサーバの性能を決定する worker_processes 1 #アプリケーションの設置されているディレクトリを指定 working_directory app_path #Unicornの起動に必要なファイルの設置場所を指定 pid "#{app_path}/tmp/pids/unicorn.pid" #ポート番号を指定 listen 3000 #エラーのログを記録するファイルを指定 stderr_path "#{app_path}/log/unicorn.stderr.log" #通常のログを記録するファイルを指定 stdout_path "#{app_path}/log/unicorn.stdout.log" #Railsアプリケーションの応答を待つ上限時間を設定 timeout 60 #以下は応用的な設定なので説明は割愛 preload_app true GC.respond_to?(:copy_on_write_friendly=) && GC.copy_on_write_friendly = true check_client_connection false run_once = true before_fork do |server, worker| defined?(ActiveRecord::Base) && ActiveRecord::Base.connection.disconnect! if run_once run_once = false # prevent from firing again end old_pid = "#{server.config[:pid]}.oldbin" if File.exist?(old_pid) && server.pid != old_pid begin sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU Process.kill(sig, File.read(old_pid).to_i) rescue Errno::ENOENT, Errno::ESRCH => e logger.error e end end end after_fork do |_server, _worker| defined?(ActiveRecord::Base) && ActiveRecord::Base.establish_connection end
上記確認をしたり修正等も加えてみたりしましたがエラー内容が改善されません。
恐れ入りますが解消方法お分かりの方ご教示いただけますと幸いです。
補足情報(FW/ツールのバージョンなど)
mysql Ver 8.0.22 for Linux on x86_64 (MySQL Community Server - GPL)
Rails 5.2.4.4
ruby 2.5.1
unicorn v5.4.1
nginx version: nginx/1.18.0
追記(0119更新)
tarminal
1ec2-user:~/environment $ cd ~/.ssh 2ec2-user:~/.ssh $ ssh -i torekabodymake_keypair.pem ec2-user@54.249.173.184 3Last login: Mon Jan 18 11:09:48 2021 from 18.183.138.44 4 5 __| __|_ ) 6 _| ( / Amazon Linux 2 AMI 7 ___|\___|___| 8 9https://aws.amazon.com/amazon-linux-2/ 10[ec2-user@ip-172-31-36-245 ~]$ cd /var/www/git_toreka 11[ec2-user@ip-172-31-36-245 git_toreka]$ bundle exec unicorn_rails -c config/unicorn.rb -E production -D 12master failed to start, check stderr log for details
[ec2-user@ip-172-31-36-245 git_toreka]$ less log/unicorn.stderr.log I, [2021-01-19T02:44:32.809591 #29445] INFO -- : Refreshing Gem list NoMethodError: Cannot load database configuration: undefined method `[]' for nil:NilClass (erb):52:in `<main>' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/2.5.0/erb.rb:876:in `eval' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/2.5.0/erb.rb:876:in `result' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.4.4/lib/rails/application/configuration.rb:172:in `database_con figuration' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.4.4/lib/active_record/railtie.rb:133:in `block (2 levels) i n <class:Railtie>' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.4.4/lib/active_support/lazy_load_hooks.rb:71:in `instance_ eval' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.4.4/lib/active_support/lazy_load_hooks.rb:71:in `block in execute_hook' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.4.4/lib/active_support/lazy_load_hooks.rb:62:in `with_exec ution_control' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.4.4/lib/active_support/lazy_load_hooks.rb:67:in `execute_h ook' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.4.4/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.4.4/lib/active_support/lazy_load_hooks.rb:51:in `each' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.4.4/lib/active_support/lazy_load_hooks.rb:51:in `run_load_ hooks' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.
[ec2-user@ip-172-31-36-245 git_toreka]$ rails db:migrate RAILS_ENV=production rails aborted! NoMethodError: Cannot load database configuration: undefined method `[]' for nil:NilClass (erb):52:in `<main>' /var/www/git_toreka/app/models/application_record.rb:1:in `<top (required)>' /var/www/git_toreka/app/models/user.rb:1:in `<top (required)>' /var/www/git_toreka/config/routes.rb:4:in `block in <top (required)>' /var/www/git_toreka/config/routes.rb:1:in `<top (required)>' /var/www/git_toreka/config/environment.rb:5:in `<top (required)>' /var/www/git_toreka/bin/rails:9:in `<top (required)>' /var/www/git_toreka/bin/spring:15:in `<top (required)>' bin/rails:3:in `load' bin/rails:3:in `<main>' Caused by: NoMethodError: undefined method `[]' for nil:NilClass (erb):52:in `<main>' /var/www/git_toreka/app/models/application_record.rb:1:in `<top (required)>' /var/www/git_toreka/app/models/user.rb:1:in `<top (required)>' /var/www/git_toreka/config/routes.rb:4:in `block in <top (required)>' /var/www/git_toreka/config/routes.rb:1:in `<top (required)>' /var/www/git_toreka/config/environment.rb:5:in `<top (required)>' /var/www/git_toreka/bin/rails:9:in `<top (required)>' /var/www/git_toreka/bin/spring:15:in `<top (required)>' bin/rails:3:in `load' bin/rails:3:in `<main>' Tasks: TOP => db:migrate => db:load_config => environment (See full trace by running task with --trace) [ec2-user@ip-172-31-36-245 git_toreka]$
なおdatabaseはcreateされています
mysql> SHOW DATABASES LIKE 'git_toreka'; +-----------------------+ | Database (git_toreka) | +-----------------------+ | git_toreka | +-----------------------+ 1 row in set (0.01 sec) mysql>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/01/18 02:10
2021/01/18 02:42
2021/01/18 06:23 編集
2021/01/18 08:56
2021/01/18 08:57
2021/01/18 12:03
2021/01/18 14:20 編集
2021/01/19 03:18
2021/01/19 03:29
2021/01/19 11:34