I have successfully deployed the heavy Rails application for Linode or Digital Ocean using the following technologies:
- rbenv to install Ruby
- nginx + passenger for application server
- PostgreSQL for the database server
- Capistrano , to automate the deployment (first configure this on your machine with your server IP address and settings, I will not describe it here)
These are the steps that work for me:
Virtual machine setup
Create a new virtual machine
Follow the instructions to install your hosting service, which is Linode or Digital Ocean, to create a node and configure it.
Setting date
- dpkg-reconfigure tzdata li>
Update Packages
- apt-get update
- apt-get upgrade
Security
Create user
- adduser deploy
- usermod -a -G sudo deploy
- Exit
Configure SSH Key Authentication
On local:
- SSH serial
- copy the public key:
- scp ~ / .ssh / id_rsa.pub deploy@example.com : ~
On server:
- ssh deploy@example.com
- include alias for file list:
- vim ~ / .bashrc
- uncomment all aliases
- mkdir.ssh
- mv id_rsa.pub.ssh / authorized_keys
- chown -R deploy: deploy.ssh
- chmod 700.ssh
- chmod 600.ssh / authorized_keys
- logout (check new authentication)
SSH setup
- sudo vim / etc / ssh / sshd_config
- Switch PermitRootLogin to no
- sudo service ssh restart
Firewall setup
Configure fail2ban
Configure if you have enough free memory, as it usually consumes it.
- sudo apt-get install -y fail2ban
Ruby setup
Install git
- sudo apt-get install -y git
Install rbenv
Install Ruby
- sudo apt-get install -y curl gnupg build-essential
- rbenv install -l (find the latest version)
- rbenv install 2.3.3 (or the latest available version at the moment)
- rbenv global 2.3.3
- rbenv rehash
- vim.gemrc
- Paste this: gem: -no-document
Installation servers
Install nginx + passenger
- Install the following documentation:
Install PostgreSQL
- Install the following documentation:
Setting libraries
Install node.js
Asset precompilation required.
- sudo apt-get install -y nodejs
Install picker
- get installation package
- rbenv rehash
Application Setup
Create a user in PostgreSQL
- createuser username --pwprompt
- createdb -Ousername -Eutf8 db_name
- Check this:
- psql db_name - username --password
Deploy the code * On the server: * sudo mkdir -p / srv / yoursite.com * sudo chown deploy: deploy / srv / yoursite.com * On your machine dev: * bundle exec cap production deploy: check (it will throw an error because cannot find the database) * On the server: * cd / srv / yoursite.com / shared / config * vim database.yml (insert the configuration of your database) * vim secrets.yml (insert your secret config) * On your dev machine: * deployment of exec cap package * bundle exec cap production whenever: update_crontab
Configure logrotate
David morales
source share