LoginSignup
2
0

More than 3 years have passed since last update.

[Chapter-3]EC2のサーバー環境構築

Last updated at Posted at 2021-05-02
タイトル
[Chapter-1]VPCの設定
[Chapter-2]EC2の設定
[Chapter-3]EC2のサーバー環境構築
[Chapter-4]EC2にRailsアプリの配置
[Chapter-5]ロードバランサー(ELB)の作成
[Chapter-6]ACM(AWS Certificate Manager)でSSL証明書を取得
[Chapter-7]Route53の設定
[Chapter-8]https化に向けたロードバランサーの設定
[Chapter-9]https化によるRoute53の設定
[Chapter-10]https化によるNginxの設定

はじめに

今回はEC2のサーバー環境構築をしていきます
自分の手順書としてのメモですので画像はありません。あしからず。

Nginxを設定する

まずサーバーをアップデートします。

サーバー
$ sudo yum update

Nginxをインストール

サーバー
$ sudo amazon-linux-extras install nginx1.12 -y

Nginxの起動

サーバー
$ sudo systemctl start nginx

Nginxサービスを有効化します。(インスタンス起動時自動起動)

サーバー
$ sudo systemctl enable nginx

起動しているか確認(ステータスを表示)

サーバー
$ systemctl status nginx

必要なプラグインをインストール

サーバー
$ sudo yum install git make gcc-c++ patch openssl-devel libyaml-devel libffi-devel libicu-devel libxml2 libxslt libxml2-devel libxslt-devel zlib-devel readline-devel ImageMagick ImageMagick-devel epel-release

PostgreSQLをインストール

サーバー
$ sudo amazon-linux-extras install postgresql11

先ほどの方法でインストールされるのは、PostgreSQLのクライアントだけで、サーバはインストールされない。
postgresql-serverをインストールする

サーバー
$ sudo yum install postgresql-server postgresql-contrib postgresql-devel

サーバーを初期化します。

サーバー
$ sudo postgresql-setup initdb

Node.jsをインストール

サーバー
# ダウンロード
$ curl -sL https://rpm.nodesource.com/setup_12.x | sudo bash -

#インストール
$ sudo yum install -y nodejs

Yarnをインストール

サーバー
$ curl -sL https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
$ sudo yum install -y yarn

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

ruby-buildをインストール

サーバー
$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
$ rbenv rehash

Rubyをインストール

ローカル環境にて制作したアプリをどのバージョンのRubyで制作したか確認してください。
アプリのディレクトリ内でruby -vでバージョン確認です。

ローカル
$ ruby -v
ruby 2.6.6

筆者は2.6.6でインストールします。

サーバー
$ rbenv install -v 2.6.6
$ rbenv global 2.6.6
$ rbenv rehash
$ ruby -v

参考

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