c a n d l a n d . n e t

AWS EC2 NodeJS, Forever, HAProxy Setup

Dusty Candland | | aws, ec2, forever, haproxy, nodejs, ubuntu

Sign up for EC2

Create an instance, I used one from here, Alestic, paste in the ami-xxxxxx value to find the one you want.

Create an security group with at least SSH and HTTP.

Save your private key and connect like:

ssh -i your_key.pem ubuntu@ec2-instance-location.amazonaws.com

Update and install the needed packages:

sudo apt-get update
sudo apt-get install git-core g++ make curl libssl-dev

Install node, get latest url at NodeJS.org

curl -O http://nodejs.org/dist/node-v0.2.6.tar.gz
tar -xvzf node-v0.2.6.tar.gz
cd node-v0.2.6
./configure
make
sudo make install

Node Package Manager

Install Node Package Manager.

sudo chown -R $USER /usr/local/{share/man,bin,lib/node}
curl http://npmjs.org/install.sh | sh

Forever

This will be used to keep your node process running, forever. Restarting as needed.

keep NodeJS running with Forever

npm install forever

HA Proxy

HA Proxy

HA Proxy Logging

Quickly setup a load balanced high availability cluster

ACL Proxy Config for HAProxy

global

    log 127.0.0.1   local0
    log 127.0.0.1   local1 notice
    #log loghost    local0 info
    maxconn 4096
    #chroot /usr/share/haproxy
    user haproxy
    group haproxy
    daemon
    #debug
    #quiet


defaults

    log global
    mode    http
    option  httplog
    option  dontlognull
    retries 3
    option redispatch
    maxconn 2000
    contimeout  5000
    clitimeout  50000
    srvtimeout  50000


frontend http-in

    bind *:80
    acl is_domain_com hdr_end(host) -i domain.red27.net

    use_backend domain_com if is_domain_com
    default_backend hello


backend domain_com

    option httpchk HEAD /check.txt HTTP/1.0
    option httpclose
    option forwardfor
    dispatch 127.0.0.1:8124


backend hello

    option httpchk HEAD /check.txt HTTP/1.0
    option httpclose
    option forwardfor
    dispatch 127.0.0.1:8123


change /etc/default/haproxy

# Set ENABLED to 1 if you want the init script to start haproxy.
ENABLED=1
# Add extra flags here.
#EXTRAOPTS="-de -m 16"

Running

sudo /etc/init.d/haproxy start

sudo forever start path-to-app.js

Lastly

NOTE: don’t forget to create and EBS AMI Image so your stuff is saved.

resources

NodeJs for server newbs

NodeJS

EC2 Getting Started

Alestic AMI’s

NodeJS on your own AMI

Node as a service

HA Proxy Setup

Webmentions

These are webmentions via the IndieWeb and webmention.io. Mention this post from your site: