-
-
Save sjehutch/4384d569f8121acb2273 to your computer and use it in GitHub Desktop.
Node+cluster on Amazon EC2 Quickstart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 https://help.ubuntu.com/community/EC2StartersGuide | |
#I picked a 64bit 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 install build-essential libssl-dev | |
#Grab that latest node tarball - http://nodejs.org/#download | |
wget http://nodejs.org/dist/node-v0.4.1.tar.gz | |
tar xzf node-v0.4.1.tar.gz | |
cd node-v0.4.1 | |
#install node in the home directory, we should probably have created a non-sudo user for this | |
./configure --prefix=~/local | |
make install | |
#put node in your path | |
export PATH=$PATH:/home/ubuntu/local/bin | |
source ~/.bashrc | |
#Setup npm, this makes life much easier | |
mkdir ~/git | |
cd ~/git | |
git clone https://github.com/isaacs/npm.git | |
cd npm/ | |
make install | |
#setup nvm for easily switching between node versions as things change so quickly | |
npm install nvm | |
#install 'cluster' - https://github.com/LearnBoost/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 }); | |
res.end(body); | |
}); | |
cluster(server) | |
.use(cluster.logger('logs')) | |
.use(cluster.stats()) | |
.use(cluster.pidfiles('pids')) | |
.use(cluster.cli()) | |
.use(cluster.repl(8888)) | |
.listen(3000); | |
#Test it! | |
node cluster.js | |
#Using the domain you ssh'd into earlier, browse to http://<domain>:3000, you should see hello world | |
#From the EC2 instance, login into the cluster admin interface: | |
telnet 0 8888 | |
#type help() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment