1
0

More than 3 years have passed since last update.

本番環境でよく使うコマンドまとめ

Last updated at Posted at 2021-08-05

RailsアプリケーションをAWSでデプロイした際、コマンドを何度も調べていたのでまとめました。(自分用メモです)
随時更新していく予定です!

前提条件

  • OS:Linux(CentOS)
  • 言語:HTML,CSS,JavaScript,Ruby,SQL
  • フレームワーク:Ruby on Rails
  • IDE:Cloud9
  • Webサーバー:Nginx
  • アプリケーションサーバー:Puma
  • データベース:MySQL

コマンドまとめ

cloud9のターミナルからEC2へSSHでログイン

$ ssh -i ~/.ssh/キー名.pem ec2-user@IPアドレス

Pumaの起動

# EC2のアプリケーション上で実行
$ rails s -e production

Pumaの停止

# EC2のアプリケーション上で実行
$ kill $(cat tmp/pids/puma.pid)

# 自動起動設定をしている場合はsudoをつける
$ sudo kill $(cat tmp/pids/puma.pid)

Gemファイルのインストール

$ bundle install --path vendor/bundle --without test development

プリコンパイル

$ bundle exec rails assets:precompile RAILS_ENV=production

マイグレート

$ bundle exec rails db:migrate RAILS_ENV=production

本番環境でのエラーログの確認

# EC2アプリケーションのlogディレクトリに移動して実行
$ cat production.log

# 行数を指定して表示
$ tail -n 行数 production.log

MySQLへ接続

# EC2のホームディレクトリで実行
$ mysql -u マスタユーザ名 -p -h エンドポイント

Nginxのアプリケーション名.confファイルの編集

# EC2のアプリケーション上で実行
$ sudo vi /etc/nginx/conf.d/アプリケーション名.conf

Nginxの再起動

# EC2のアプリケーション上で実行
$ sudo systemctl restart nginx

Cloud9から秘密鍵をEC2サーバーに送る

#Cloud9のアプリケーション上で実行
$ scp -i ~/.ssh/キー名.pem ~/.ssh/id_rsa ec2-user@IPアドレス:.ssh/id_rsa
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0