Saturday, February 26, 2011

Ubunt+Node+cluster on Amazon EC2 Quickstart

Just Show Me The Scripts

If you're just looking for a script to setup nodejs under ubuntu quickly, check out this set of scripts.

Walk Through

First you'll need to Signup for AWS/EC2 and generate a key pair. Google it, there should be plenty of tutorials.

Next, create an instance using the AWS Management Console and log into it using your key pair. You can find the AMI's here. I picked a 32bit 10.04 LTS AMI in US-East.

Install node's perquisites (or those that aren't the default ubuntu LTS ami):
  sudo apt-get update
sudo apt-get -y install build-essential libssl-dev

Now let's create a nodejs system user:
  sudo adduser --home /home/nodejs --shell /bin/bash --disabled-password --disabled-login --system nodejs

Now login as that user:
  sudo su nodejs

For the heavy lifting we use the excllent 'nvm' from creationix
  git clone git:// ~/.nvm
. ~/.nvm/

Install nodejs:
  nvm sync
time nvm install latest
nvm use latest

Setup the nodejs user's enviroment to have that latest nodejs in it's path
  echo -e -n "\n. ~/.nvm/\n" >> ~/.bashrc
echo -e -n "\nnvm use latest\n" >> ~/.bashrc

Setup npm, this makes life much easier:
  mkdir ~/git
cd ~/git
git clone
cd npm/
make install

Taking Full Advantage Multiple Cores/CPUs

Assuming you want to take full advantage ec2's multiple cores then install 'cluster' -
  npm install cluster

Setup hello world example:
   mkdir ~/git/sandbox
cd ~/git/sandbox

Edit cluster.js to contain cluster example:
      var cluster = require('cluster')
, http = require('http');

var server = http.createServer(function(req, res){
console.log('%s %s', req.method, req.url);
var body = 'Hello World';
res.writeHead(200, { 'Content-Length': body.length });


Test it!
  node cluster.js

Using the domain you ssh'd into earlier, browse to http://:3000, you should see hello world.

From the EC2 instance, login into the cluster admin interface:
  telnet 0 8888
Type help()


At October 31, 2020 at 7:03 AM , Blogger Subhasree said...

This is the most helpful post that focused on the key points about the subject. This valuable content helps to figure out reliable details. Please visit : Laptop service center in Navalur


Post a Comment

Subscribe to Post Comments [Atom]

<< Home