Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have successfully deployed a heavy Rails application to Linode or Digital Ocean, using these technologies:</p> <ul> <li><strong>rbenv</strong> for Ruby installation</li> <li><strong>nginx + Passenger</strong> for the application server</li> <li><strong>PostgreSQL</strong> for the database server</li> <li><strong>Capistrano</strong> to automate deploys (configure this first on your dev machine with your server IP and settings, I will not cover it here)</li> </ul> <p>These are the steps that work for me:</p> <h1>Setting up the virtual machine</h1> <p><strong>Create a new virtual machine</strong></p> <p>Follow the setup instructions of your hosting, being Linode or Digital Ocean, to create the node and set it up.</p> <p><strong>Set up date</strong></p> <ul> <li>dpkg-reconfigure tzdata</li> </ul> <p><strong>Update packages</strong></p> <ul> <li>apt-get update</li> <li>apt-get upgrade</li> </ul> <h1>Security</h1> <p><strong>Create user</strong></p> <ul> <li>adduser deploy</li> <li>usermod -a -G sudo deploy</li> <li>logout</li> </ul> <p><strong>Set up SSH key-authentication</strong></p> <p>On local:</p> <ul> <li>ssh-keygen</li> <li>copy the public key: <ul> <li>scp ~/.ssh/id_rsa.pub deploy@example.com:~</li> </ul></li> </ul> <p>On the server:</p> <ul> <li>ssh deploy@example.com</li> <li>enable the alias to list files: <ul> <li>vim ~/.bashrc</li> <li>uncomment all aliases</li> </ul></li> <li>mkdir .ssh</li> <li>mv id_rsa.pub .ssh/authorized_keys</li> <li>chown -R deploy:deploy .ssh</li> <li>chmod 700 .ssh</li> <li>chmod 600 .ssh/authorized_keys</li> <li>logout (test the new authentication)</li> </ul> <p><strong>Set up SSH</strong></p> <ul> <li>sudo vim /etc/ssh/sshd_config</li> <li>Switch PermitRootLogin to no</li> <li>sudo service ssh restart</li> </ul> <p><strong>Set up firewall</strong></p> <ul> <li>sudo iptables -L (it should show a void table)</li> <li>sudo vim /etc/iptables.firewall.rules</li> <li>Paste this: <a href="https://gist.github.com/davidmles/89fc88e48e17cf8252bfca374e46355f#file-iptables-firewall-rules" rel="nofollow noreferrer">https://gist.github.com/davidmles/89fc88e48e17cf8252bfca374e46355f#file-iptables-firewall-rules</a></li> <li>sudo iptables-restore &lt; /etc/iptables.firewall.rules</li> <li>sudo iptables -L (now it should show the configured rules)</li> <li>sudo vim /etc/network/if-pre-up.d/firewall</li> <li>Paste this: <a href="https://gist.github.com/davidmles/89fc88e48e17cf8252bfca374e46355f#file-firewall" rel="nofollow noreferrer">https://gist.github.com/davidmles/89fc88e48e17cf8252bfca374e46355f#file-firewall</a></li> <li>sudo chmod +x /etc/network/if-pre-up.d/firewall</li> </ul> <p><strong>Set up fail2ban</strong></p> <p>Set up if you have enough free memory, as it tends to eat it.</p> <ul> <li>sudo apt-get install -y fail2ban</li> </ul> <h1>Setup Ruby</h1> <p><strong>Install Git</strong></p> <ul> <li>sudo apt-get install -y git</li> </ul> <p><strong>Install rbenv</strong></p> <ul> <li>git clone <a href="https://github.com/sstephenson/rbenv.git" rel="nofollow noreferrer">https://github.com/sstephenson/rbenv.git</a> ~/.rbenv</li> <li>echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc</li> <li>echo 'eval "$(rbenv init -)"' >> ~/.bashrc</li> <li>source ~/.bashrc</li> <li>git clone <a href="https://github.com/sstephenson/ruby-build.git" rel="nofollow noreferrer">https://github.com/sstephenson/ruby-build.git</a> ~/.rbenv/plugins/ruby-build</li> </ul> <p><strong>Install Ruby</strong></p> <ul> <li>sudo apt-get install -y curl gnupg build-essential</li> <li>rbenv install -l (look for the latest version)</li> <li>rbenv install 2.3.3 (or the latest available version at this moment)</li> <li>rbenv global 2.3.3</li> <li>rbenv rehash</li> <li>vim .gemrc <ul> <li>Paste this: gem: --no-document</li> </ul></li> </ul> <h1>Setup servers</h1> <p><strong>Install nginx + Passenger</strong></p> <ul> <li>Install following the documentation: <ul> <li><a href="https://www.phusionpassenger.com/library/install/nginx/install/oss/jessie/" rel="nofollow noreferrer">https://www.phusionpassenger.com/library/install/nginx/install/oss/jessie/</a></li> </ul></li> </ul> <p><strong>Install PostgreSQL</strong></p> <ul> <li>Install following the documentation: <ul> <li><a href="https://wiki.postgresql.org/wiki/Apt#PostgreSQL_packages_for_Debian_and_Ubuntu" rel="nofollow noreferrer">https://wiki.postgresql.org/wiki/Apt#PostgreSQL_packages_for_Debian_and_Ubuntu</a></li> </ul></li> </ul> <h1>Setup libraries</h1> <p><strong>Install node.js</strong></p> <p>Needed to pre-compile assets.</p> <ul> <li>sudo apt-get install -y nodejs</li> </ul> <p><strong>Install bundler</strong></p> <ul> <li>get install bundler</li> <li>rbenv rehash</li> </ul> <h1>Setup the application</h1> <p><strong>Create the user in PostgreSQL</strong></p> <ul> <li>createuser username --pwprompt</li> <li>createdb -Ousername -Eutf8 db_name</li> <li>Test it: <ul> <li>psql db_name --user username --password</li> </ul></li> </ul> <p><strong>Deploy the code</strong> * On the server: * sudo mkdir -p /srv/yoursite.com * sudo chown deploy:deploy /srv/yoursite.com * On your dev machine: * bundle exec cap production deploy:check (it will throw an error because it doesn't find the database) * On the server: * cd /srv/yoursite.com/shared/config * vim database.yml (paste your database config) * vim secrets.yml (paste your secrets config) * On your dev machine: * bundle exec cap production deploy * bundle exec cap production whenever:update_crontab</p> <p><strong>Configure logrotate</strong></p> <ul> <li>Follow this guide: * <a href="https://gorails.com/guides/rotating-rails-production-logs-with-logrotate" rel="nofollow noreferrer">https://gorails.com/guides/rotating-rails-production-logs-with-logrotate</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload