Note: All steps assume you are running Ubuntu 12.04LTS 64-bit servers. Most of these steps should apply to any distribution of Ubuntu, however.
apt-get update
apt-get upgrade
apt-get install build-essential
apt-get install sqlite3 libsqlite3-ruby libsqlite3-dev
apt-get install libyaml-dev
apt-get install libpq-dev
apt-get install git
curl -L get.rvm.io | bash -s stable
source /etc/profile.d/rvm.sh
rvm reload
rvm install 2.1.0
apt-get install nodejs
gem install bundler rails
gem install unicorn
- Add to ~/.bashrc:
source /etc/profile.d/rvm.sh
rvm reload
cd /var
mkdir www
cd www
application needs to have a pids
directory
cd /var/www
git clone <app_repo>
vi config/unicorn.rb
- Add the following:
working_directory "/var/www/<app_dir_name>"
pid "/var/www/<app_dir_name>/pids/unicorn.pid"
stderr_path "/var/www/<app_dir_name>/log/unicorn.log"
stdout_path "/var/www/<app_dir_name>/log/unicorn.log"
worker_processes 2
timeout 30
rake db:migrate RAILS_ENV=<production/development>
unicorn_rails -c config/unicorn.rb -D -E production/development
ifconfig
and add IP Address to/etc/nginx/nginx.conf
on Load Balancer server
default_run_options[:pty] = true
useradd -s /bin/bash -G sudo -m <username>
passwd <username>
(Enter password when prompted.)
ssh-copy-id -i ~/.ssh/id_rsa.pub <username@remote-host>
ssh <username@remote-host>
sudo nano /etc/ssh/sshd_config
- Change
PermitRootLogin yes
toPermitRootLogin no
sudo restart ssh
apt-get update
apt-get upgrade
apt-get install build-essential
apt-get install git
vi /etc/apt/sources.list.d/pgdg.list
deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main
(Note: replaceprecise
with name of Ubuntu release. Get your current release name by typinglsb_release -c
.)apt-get update
apt-get upgrade
- Potential error handling:
apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 7FCC7D46ACCC4CF8
apt-get install postgresql-9.3 pgadmin3
sudo -u postgres psql postgres
- On psql command line:
\password postgres
and set password.\q
to quit
sudo -u postgres psql
- On psql command line:
CREATE USER <user_name> WITH PASSWORD '[password]';
CREATE DATABASE <database_name> OWNER <user_name>;
\q
to quit
vi /etc/postgresql/9.3/main/postgresql.conf
- Find line:
#listen_addresses = 'localhost'
and change to:listen_addresses = '*'
vi /etc/postgresql/9.3/main/pg_hba.conf
- Find section:
# Put your Actual configuration here
- After comment block:
# TYPE DATABASE USER ADDRESS METHOD
host all all 0.0.0.0/0 md5
service postgresql restart
- Edit
config/database.yml
:
production:
adapter: postgresql
encoding: utf8
database: <database_name>
username: <database_username>
password: <password>
host: <host_ip_address>
port: 5432
pool: 10
- Edit
Gemfile
:
gem 'pg'
bundle
apt-get update
apt-get upgrade
apt-get install build-essential
apt-get install nginx
useradd nginx --no-create-home
vi /etc/nginx/nginx.conf
and replace with:
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
# Load config files from the /etc/nginx/conf.d directory
# The default server is in conf.d/default.conf
# include /etc/nginx/conf.d/*.conf;
upstream unicorn_servers {
server 172.31.32.79:8080 fail_timeout=0;
}
server {
listen 80;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://unicorn_servers;
}
}
}
- Update server list under
upstream unicorn_servers
service nginx start
- If error, add
types_hash_max_size 2048;
inhttp
section and resave. service nginx restart