0
0

More than 3 years have passed since last update.

[2021年最新]小学生でも分かるAWSのデプロイ手順説明書 中編

Last updated at Posted at 2021-02-07

説明書

[2021年最新]小学生でも分かるAWSのデプロイ手順説明書 前編

[2021年最新]小学生でも分かるAWSのデプロイ手順説明書 後編

注意点

  • (EC2)...EC2内で行う。

  • (ローカル)...EC2内で行う。

デプロイ編

手順

1.ライブラリのアップデートを行う(EC2)


$ sudo yum update -y

2.タイムゾーンとロケールの設定を行う(EC2)


$ sudo timedatectl set-timezone Asia/Tokyo
$ sudo localectl set-locale LANG=ja_JP.UTF-8

3.NTPの設定を行う(EC2)


$ yum info chrony
$ chronyc sources -v

4.標準パッケージのインストールを行う(EC2)


$ sudo yum -y install gcc-c++ glibc-headers openssl-devel readline libyaml-devel readline-devel zlib zlib-devel libffi-devel libxml2 libxslt libxml2-devel libxslt-devel git

5.データベースモジュールのインストールを行う(EC2)

  • PostgreSQLの場合

$ sudo yum -y install postgresql-devel
  • MySQLの場合

$ sudo yum -y install mysql-devel

6.Rubyのインストールを行う(EC2)

※今回は2.7.2としてます。自分の環境に合わせて任意で変更お願いします。

  • rbenvのインストール

$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
$ source ~/.bash_profile
$ rbenv -v
  • ruby-buildのインストール

$ git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
$ cd ~/.rbenv/plugins/ruby-build
$ sudo ./install.sh
$ rbenv install -l
  • Rubyのインストール

$ rbenv install 2.7.2
$ rbenv global 2.7.2

7.node.jsのインストールを行う(EC2)


$ curl -sL https://rpm.nodesource.com/setup_14.x | sudo bash -
$ sudo yum install -y nodejs
$ sudo npm install -g n
$ sudo n stable
$ sudo ln -snf /usr/local/bin/node /usr/bin/node

8.yarnのインストールを行う(EC2)


$ curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
$ sudo yum install yarn -y

9.Railsのインストールを行う(EC2)


$ cd ~
$ mkdir rails
$ cd rails
$ bundle init
$ vim Gemfile 
# 「gem "rails", "〇〇"」部分を、"自分の環境のバージョン"に書き換え、コメントアウト解除

$ bundle install
$ bundle exec rails -v
# インストールされたことを確認

$ cd ..
$ rm -rf rails

10.データベースの設定を行う(ローカル)


$ EDITOR="vim" bin/rails credentials:edit

下記を追記する。

credentials.yml.enc

db:
  username: (作成したDBのusername)
  password: (作成したDBのpassword)
  host: (作成したDBのdatabase endpoint)

続いて、config/database.ymlを編集。

config/database.yml

production:
  <<: *default
  database: sample_app # 自分のアプリ名
  username: <%= Rails.application.credentials.db[:username] %>
  password: <%= Rails.application.credentials.db[:password] %>
  host:     <%= Rails.application.credentials.db[:host] %>
  port:     3306 # MySQLの場合

前編終了!

お疲れ様です。ここまでで、デプロイ作業の半分が完了しました。
次編からは、とうとうデプロイを行っていくので頑張りましょう!!!
後編に続く...

0
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
0
0