16
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Amazon Linux 2 で Rails アプリケーションのサーバーを構成してみる

Last updated at Posted at 2018-01-24

Amazon Linux 2 の特徴

  • AWS INTEGRATION
    • AWS tools (e.g. AWS CLI) と cloud-init が入った
  • LONG TERM SUPPORT
  • EXTRAS REPOSITORY FOR SOFTWARE PACKAGES
    • amazon-linux-extras で nginx などのパッケージを管理できる
  • ON-PREMISES USE
    • オンプレ利用用途に VM Image などが用意されている
  • SYSTEMD SUPPORT
  • TUNED LTS KERNEL AND NEW TOOLCHAIN
  • SECURITY CONFIGURATIONS
  • SECURITY UPDATES

インスタンスの作成

AMI 選択画面で Amazon Linux 2 LTS Candidate AMI 2017.12.0 (HVM), SSD Volume Type (ami-c2680fa4) を選択してインスタンスを立てる.

公開鍵の追加

vi ~/.ssh/authorized_keys

ユーザーの追加

sudo adduser deploy

ライブラリのインストール

sudo yum -y install \
git make gcc-c++ patch \
openssl-devel \
libyaml-devel libffi-devel libicu-devel \
libxml2 libxslt libxml2-devel libxslt-devel \
zlib-devel readline-devel \
mysql mysql-server mysql-devel \
ImageMagick ImageMagick-devel \
epel-release protobuf-devel

デプロイ先フォルダの用意

sudo mkdir /var/www
sudo chown deploy /var/www/
sudo mkdir /var/www/deploy
sudo chown deploy /var/www/deploy/

nginx のインストール

Amazon Linux 2 では amazon-linux-extras で入れる.

# 確認する
amazon-linux-extras
# install する
sudo amazon-linux-extras install nginx1.12
# ついでに emacs も入れる
sudo amazon-linux-extras install emacs

nginx の起動

# 起動
sudo systemctl start nginx.service
# ステータスの確認
sudo systemctl status nginx.service
# systemd を有効化
sudo systemctl enable nginx.service
# 有効になっているか確認
systemctl is-enabled nginx.service

nginx の設定

# nginx の設定ファイル
sudo vi /etc/nginx/nginx.conf
# 設定再読込
sudo nginx -s reload

ffmpeg

sudo rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm
mkdir ~/tmp
cd ~/tmp
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum -y localinstall epel-release-latest-7.noarch.rpm
sudo yum -y install ffmpeg ffmpeg-devel

wkhtmltoimage

https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
tar -xvf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
sudo mv wkhtmltox/bin/wkhtmltoimage /usr/bin/wkhtmltoimage

NodeJS

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
source ~/.bashrc
nvm install v8.9.4
nvm use v8.9.4
nvm alias default v8.9.4

Ruby

sudo git clone https://github.com/sstephenson/rbenv.git /usr/local/rbenv
sudo git clone https://github.com/sstephenson/ruby-build.git /usr/local/rbenv/plugin/ruby-build
sudo /usr/local/rbenv/plugin/ruby-build/install.sh
sudo vi /etc/profile.d/rbenv.sh
sudo su -
source /etc/profile.d/rbenv.sh
rbenv install 2.4.3
rbenv global 2.4.3
gem install bundler --no-ri --no-rdoc

タイムゾーン, host の修正

timedatectl, hostnamectl を利用する.

sudo timedatectl set-timezone Asia/Tokyo
sudo hostnamectl set-hostname deploy.dot.com
sudo reboot

New Relic Infrastructure の追加

https://rpm.newrelic.com/accounts/813076 でライセンスキー確認

echo "license_key: YOUR_LICENSE_KEY" | sudo tee -a /etc/newrelic-infra.yml
sudo curl -o /etc/yum.repos.d/newrelic-infra.repo https://download.newrelic.com/infrastructure_agent/linux/yum/el/7/x86_64/newrelic-infra.repo
sudo yum -q makecache -y --disablerepo='*' --enablerepo='newrelic-infra'
sudo yum install newrelic-infra -y

公開鍵

sudo su - deploy
mkdir ~/.ssh
chmod 700 ~/.ssh
touch ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
# デプロイするサービスの公開鍵を追加
vi ~/.ssh/authorized_keys

refs

16
15
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
16
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?