Derby.js deploy on Amazon EC2

The intensive development of cloud services leaves no one indifferent. Our focus is on the Amazon service - Elasctic Cloud Compute. There was a task to deploy the node.js project using Derby . Amazon Elastic Beanstalk also supports node.js, however we will limit ourselves only to Amazon EC2. Also out of the box, Amazon Elastic Beanstalk offers Amazon Linux with preinstalled node.js + nginx. In our case, Amazon Linux is not suitable, the version of node.js and the bunch of node.js + nginx as well. ,

Create instance and connect to EC2 server

It is assumed that you are registered with AWS and have access to the AWS Managment Console .
Launch EC2 Instance:
  1. Go to the AWS Managment Console
  2. Select a region (in our case, US East (N. Virginia))
  3. Go to Services -> Compute & Nerworking -> EC2
  4. Launch Instance: We select Ubuntu Server 13.04 x64 , we configure keys, and other necessary parameters, including Instance Type (in our case t1.micro)
  5. After creating the list of instances, we observe how our server gets state running
  6. We connect to the server via ssh: for this, right-click on the desired one in the list of instances, select Connect -> Connect with a standalone SSH Client
    There will be something like:
    $ ssh -i yourkey.pem
  7. Connect to the server according to the parameters obtained in paragraph 6.

We will use this bundle: node.js + derby + redis + mongodb
We will install the necessary packages one by one.

Install Node.js.

For Derby.js we will use the version of node.js 0.10.17
  1. Download source:
    $ wget
  2. Unpack:
    $ tar -xvf node-v0.10.17.tar.gz
    $ cd  node-v0.10.17
  3. Install:
    	$ sudo apt-get -y install checkinstall
    	$ checkinstall -D --install=no --nodoc --pkgversion=0.10.17 --pkgname="Node.js 0.10.17"
    	$ sudo dpkg -i node*.deb
  4. Install DerbyJS :
    $ sudo npm install -g derby

Install Redis 2.6.16

  1. Download:
    $ wget
  2. Unpack:
    $ tar -xvf redis-2.6.16.tar.gz
    $ cd redis-2.6.16
  3. Install:
    $ sudo checkinstall -D --install=no --nodoc --pkgversion=2.6.16 --pkgname="Redis 2.6.16"
    $ sudo dpkg -i redis*.deb
  4. Customize
    $ sudo mkdir /etc/redis
    $ sudo mkdir /var/redis
    $ sudo cp utils/redis_init_script /etc/init.d/redis
    $ sudo cp redis.conf /etc/redis/6379.conf
    $ sudo vi /etc/redis/6379.conf
    specify the parameters
    daemonize yes
    logfile /var/log/redis.log
    dir /var/redis/
    save file
  5. We start the service:
    $ sudo service redis start
  6. Add to startup:
    $ sudo update-rc.d redis defaults
  7. We check:
    $ redis-cli
    redis> ping
    redis> exit

Install MongoDB

  1. Installation:
    sudo apt-get -y install mongodb
  2. Check the status:
    $ service mongodb status
    Answer example:
    mongodb start/running, process 24815

Create Derby App

  1. Creature
    $ mkdir ~/www
    $ cd ~/www
    $ derby new myapp
    $ cd myapp
  2. Check the launch:
    $ nmp start

Run as a daemon

Perhaps one of the easiest ways:
$ cd ~/www/myapp
$ nohup node server.js &
You can also use supervisord or another tool.

References / Sources