2
0

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.

Ruby on Rails + Nginx + Unicorn + MySQL環境構築

2
Posted at

■ アップデート
sudo yum update

■ 環境構築に必要なパッケージインストール
sudo yum install git make gcc 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

■ リポジトリ追加
sudo amazon-linux-extras install epel

■ node.jsのインストール
sudo yum install nodejs npm --enablerepo=epel

■ 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
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
rbenv rehash

■ Rubyインストール
rbenv install -v 2.6.2
rbenv global 2.6.2
rbenv rehash
ruby -v

■ githubからソースデプロイ

■ Unicornインストール
sudo yum install mysql-devel
gem install bundler
bundle install
vim config/unicorn.conf.rb

■ config/unicorn.conf.rb生成
vim config/unicorn.conf.rb

==
$worker = 2
$timeout = 30
$app_dir = "/var/www/rails/mumu" #自分のアプリケーション名
$listen = File.expand_path 'tmp/sockets/.unicorn.sock', $app_dir
$pid = File.expand_path 'tmp/pids/unicorn.pid', $app_dir
$std_log = File.expand_path 'log/unicorn.log', $app_dir

worker_processes $worker
working_directory $app_dir
stderr_path $std_log
stdout_path $std_log
timeout $timeout
listen $listen
pid $pid
preload_app true

before_fork do |server, worker|
defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!
old_pid = "#{server.config[:pid]}.oldbin"
if old_pid != server.pid
begin
Process.kill "QUIT", File.read(old_pid).to_i
rescue Errno::ENOENT, Errno::ESRCH
end
end
end

after_fork do |server, worker|
defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
end

■ Nginxインストール
sudo yum install nginx
sudo vim /etc/nginx/conf.d/smallmaker.conf
sudo chmod -R 775 /var/lib/nginx

■ MySQLインストール
sudo yum localinstall https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm -y
sudo yum-config-manager --disable mysql80-community
sudo yum-config-manager --enable mysql57-community
sudo yum install mysql-community-server -y

SET GLOBAL validate_password_length=4;
SET GLOBAL validate_password_policy=LOW;
set password for root@localhost=password('root');

■ MySQLユーザー作成
create user smallmaker@'localhost' identified with mysql_native_password by 'smallmaker';
grant all on . to smallmaker@'localhost';

■ データベース作成
CREATE DATABASE smallmaker DEFAULT CHARSET 'utf8';

■ unicorn 起動
#unicorn_rails -c /var/project/smallmaker/application/config/unicorn.conf.rb -D -E production
unicorn -c /var/project/smallmaker/application/config/unicorn.conf.rb -D -E production

■ unicorn 停止
sudo kill -QUIT cat tmp/pids/unicorn.pid

■ nginx スタート
sudo service nginx start

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?