Deploying an Node.js stack on Ubuntu
This doc will walk you through deploying an Ubuntu 14.04 server on Digital Ocean through Mist.io and provision an Ansible playbook that will install a Node.js/nginx/mongodb stack. The Ansible playbook will take care of any requirements and will act as a base to build upon and tune configuration to fulfill your needs. After the newly created virtual machine is provisioned, Mist.io will enable monitoring and set up some rules to alert you in case of high system load.
Step 1: Adding an SSH key to Mist.io
You will need to add an SSH to Mist.io if you haven't already done so. The key will be deployed on the newly created machine so that Mist.io can access it. From the main page enter the Keys section, press Add and insert the name of the key. Press generate to have an SSH RSA key produced by Mist.io, or upload an existing private SSH key file.
Step 2: Creating an Ansible playbook
This Ansible playbook will install nginx and set some default configuration plus a 'Hello world' page. It will also install Node.js 0.12 through https://deb.nodesource.com and mongodb through mongodb.org. It is a simple playbook designed to be used for testing and act as a base for preparing more advanced ones to suit your needs.
On this example playbook there are 5 roles,
- an init role that installs essential packages (git, vim, etc),
- a mongodb role that installs mongodb and sets the configuration file to bind it on localhost
- a Node.js role that installs Node.js 0.12
- a python tooling role that will install all necessary python utilities
- an nginx role that installs nginx, sets a basic conf for nginx and a hello world page
The way the playbook is organized (with roles, tasks, templates, defaults and handlers) makes it easy to extend and add additional parts, like more template files for the Node.js, or set some github repository to clone, set nginx's configuration to proxypass the Node.js app etc.
From the main page, enter the Scripts section, press Add script, specify a name, then select Ansible Playbook as Type, Github as Source, specify https://github.com/mgogoulos/ansible-provisioner as the Github Repo and playbook.yml as the Entry point. The entry point is the playbook that will be run.
Step 3: Deploying the server
In the Machines section select Create server and specify the following: name, Provider, image, size, location and key, specify the script as the one you have just created, and make sure 'Enable monitoring' is selected. For example, for a small (512MB) Ubuntu 14.04 server on Digital Ocean, in San Fransisco 1 region, the wizard should look like this:
You can deploy servers through mist command line client, suitable when you need to deploy multiple servers. Checkout the doc at http://docs.mist.io/article/84-usage#create_machine
Click Launch and after a few minutes (depending on your provider) the machine will be up and running
Once the machine is deployed with your ssh key, the Ansible playbook will be run. When everything is done, we will see a 'Hello world' page when visiting the IP of the newly created server
Step 4: Adding some monitoring rules
With monitoring enabled on the machine, we can set some rules. For example, if we want to get an email if the load exceeds 5 for more than 5 minutes, our rule should look like:
Step 5: Checking out the playbook's output
We can see the output of the playbook by visiting the playbook we've run on the Scripts section. The stdout part can prove valuable in case something went wrong.
The Ansible playbook remains stored in Mist.io so running it on an existing server is a matter of selecting it and opening the Run script dialog. As soon as it gets finished you will be able to see the output.