前提
GitHub上に展開されているRailsアプリケーションをEC2インスタンスとRDSを使用して、デプロイさせたいです。
必要な以下のパッケージをEC2インスタンスにインストールし、RDSとの接続を確認し、データベースを作成しました。
ですが、指定のポートで接続をしているにも関わらずエラーが発生してしまい上手にデプロイできません。
〇環境について
・仮想サーバー:EC2インスタンス
(Webアプリケーションサーバーを想定しています)
・DBサーバー:RDS ポート:3306
シングルAZ構成です。
(※各セキュリティグループはIPv4,6それぞれフルオープンにしています)
ruby:2.6.3
Rails:6.1.3.1
Node:v15.14.0
yarn:1.22.18
DB エンジン:MySQL
わからないなりに調べて進めていたのですが、今回のエラーについては解決の糸口が見えないため、相談させていただきました。
よろしくお願いします。
実現したいこと
本件のエラーを解決したうえで、RailsアプリケーションをEC2上で起動させたいです。
発生している問題・エラーメッセージ
$rails s -b abc-hogehoge-tech-20220731.gdlffleafllflslfj.ap-northeast-1.rds.amazonaws.com
Cannot assign requested address - bind(2) for "abc-hogehoge-tech-20220731.gdlffleafllflslfj.ap-northeast-1.rds.amazonaws.com" port 3000 (Errno::EADDRNOTAVAIL)
試したこと
以下、ポートを指定して実行して挙動を確認してみました。
$rails s -b -p 3306 abc-hogehoge-tech-20220731.gdlffleafllflslfj.ap-northeast-1.rds.amazonaws.com
Cannot assign requested address - bind(2) for "abc-hogehoge-tech-20220731.gdlffleafllflslfj.ap-northeast-1.rds.amazonaws.com" port 3306 (Errno::EADDRNOTAVAIL)
操作ログ
■1<Railsアプリケーションの環境を準備する>
①gitのインストール
②rbenvのインストール
③ruby-buildのインストール
④次にrbenv の初期化スクリプトを .bash_profile へ追加するコマンドを入力。
・echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
・echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
・source ~/.bash_profile $ rbenv --version
⑤rbenv、Rubyのインストール
rbenv install 2.6.3
⇒エラー対応で以下の操作を実施。
・sudo yum install -y openssl-devel
・sudo yum install -y patch
・sudo yum install gcc
・sudo yum install readline-devel
⇒Installed ruby-2.6.3 to /home/ec2-user/.rbenv/versions/2.6.3⇒インストール成功
⑥Rubyのバージョン確認
⇒エラー対応で以下の操作を実施。
・rbenv local 2.6.3
⑦RubyGems(gemコマンド)自体のバージョンアップ
■2:Railsアプリケーションの入手
①GitHubから「git cone」でアプリケーションを入手。
②bundlerを使ってGemfileからgemをインストール。
⇒エラー対応で以下の操作を実施。
・sudo yum install mysql-devel
・sudo yum install -y gcc-c++
③Railsをインストール
<コマンド>gem install rails
■3:yarnのインストール
①nvmインストール
・source ~/.nvm/nvm.sh
・vi /home/ec2-user/.bash_profile
【参考】https://www.aska-ltd.jp/jp/blog/154
・nvm ls-remote
・nvm install 15.14.0
②使用するnvmの指定
・nvm use 15.14.0
③yarnのインストール
・npm install -g yarn
■4:database.ymlの編集
①以下のように編集
# MySQL. Versions 5.5.8 and up are supported. # # Install the MySQL driver # gem install mysql2 # # Ensure the MySQL gem is defined in your Gemfile # gem 'mysql2' # # And be sure to use new-style password hashing: # https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html # default: &default adapter: mysql encoding: utf8mb4 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> username: admin password: *********** port : 3306 host : abc-hogehoge-tech-20220731.gdlffleafllflslfj.ap-northeast-1.rds.amazonaws.com development: <<: *default database: raisetech_live8_sample_app_development # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: <<: *default database: raisetech_live8_sample_app_test # As with config/credentials.yml, you never want to store sensitive information, # like your database password, in your source code. If your source code is # ever seen by anyone, they now have access to your database. # # Instead, provide the password or a full connection URL as an environment # variable when you boot the app. For example: # # DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase" # # If the connection URL is provided in the special DATABASE_URL environment # variable, Rails will automatically merge its configuration values on top of # the values provided in this file. Alternatively, you can specify a connection # URL environment variable explicitly: # # production: # url: <%= ENV['MY_APP_DATABASE_URL'] %> # # Read https://guides.rubyonrails.org/configuring.html#configuring-a-database # for a full overview on how database connection configuration can be specified. # production: <<: *default database: raisetech_live8_sample_app_production
②データベースの作成
・bundle exec rails db:create
・bundle exec rails db:migrate
③本エラーにぶつかりました。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2022/08/27 06:22
2022/08/27 13:17