CouchDB on Amazon EC2 CentOS server with Sprinkle

Read the Getting Started part of Till Klampäckel’s CouchDB on Ubuntu on AWS blog post for some general information. I see no reason to repeat those things here.

Till stresses the need for a security group opening port 80, but you should also enable ssh at port 22, otherwise it will be impossible to isntall anything. The AMI I use is rightscale’s CentOS 5.2 i386 v4.2.4. If you need a 64-bit image, that should work just as well.

Make sure you have Sprinkle installed on you the system you are installing from. Put this in your spinkle file and name it something reasonable. I called it couchdb.rb. If not, gem install sprinkle. Sprinkle is written in Ruby so if you don’t have Ruby, you should start by installing that.

# Sprinkle provisioning and deployment for CouchDB on
# an Amazon EC2 CentOS server

package :spidermonkey do
  source '' do
    custom_dir 'js/src'
    custom_install "make BUILD_OPT=1 -f Makefile.ref && cp *.{h,tbl} /usr/include/ && cd Linux_All_OPT.OBJ && cp *.h /usr/include/ && mkdir -p /usr/{bin,lib}/ && cp js /usr/bin/ && cp /usr/lib/"

  verify do
    has_executable 'js'
    has_file '/usr/include/jsapi.h'
    has_file '/usr/lib/'

package :erlang_dependencies do
  yum %w( ncurses-devel openssl-devel)

package :erlang do
  description 'Erlang, the programming language'
  source ''

  verify do
    has_executable '/usr/local/bin/erl'

  requires :erlang_dependencies

package :couchdb_dependencies do
  yum %w( curl curl-devel icu libicu-devel )

# - CouchDB 0.9.1
package :couchdb, :provides => :database do
  description 'CouchDB'
  version '0.9.1'
  source '' do
    post :install, 'adduser -r -d /usr/local/var/lib/couchdb -M -s /bin/bash -c "CouchDB Administrator" couchdb'
    post :install, 'touch /usr/local/var/log/couchdb/couch.log'
    post :install, 'chown couchdb /usr/local/var/log/couchdb/couch.log'
    post :install, 'mkdir -p /usr/local/var/lib/couchdb'
    post :install, 'chown couchdb /usr/local/var/lib/couchdb'
    post :install, '/usr/local/etc/rc.d/couchdb start'
    post :install, 'ln -s /usr/local/etc/rc.d/couchdb /etc/init.d/couchdb'
    post :install, 'chkconfig --add couchdb'

  verify do
    has_executable '/usr/local/bin/couchdb'

  requires :couchdb_dependencies
  requires :erlang
  requires :spidermonkey

package :rubygems do
  description 'Ruby Gems Package Management System'
  yum 'rubygems'

package :couchrest do
  description 'Rest API for CouchDB'
  version '0.33'
  gem 'couchrest'

policy :db, :roles => :db do
  requires :database
  requires :couchrest

# Deployment
deployment do
  delivery :capistrano do
    set :user, 'root'
    set :use_sudo, false
    set :run_method, :run

    role :db, ''

  # source based package installer defaults
  source do
    prefix '/usr/local' # where all source packages will be configured to install
    archives '/usr/local/sources' # where all source packages will be downloaded to
    builds '/usr/local/build' # where all source packages will be built

Replace with the public DNS name listed on the Amazon Web Services instance view. You don’t need rubygems and couchrest unless you are going to use Ruby, but I decided to leave them since CouchRest is a nice libarary to use when talking to CouchDB from Ruby.

Run it in a shell with sprinkle -s couchdb.rb. Might be interesting to check the powder cloud like this first: sprinkle -cts couchdb.rb. The expected cloud looks liek this:

--> Cloud hierarchy for policy db

Policy db requires package database
Selecting couchdb for virtual package database
  Package couchdb requires couchdb_dependencies
  Package couchdb requires erlang
    Package erlang requires erlang_dependencies
  Package couchdb requires spidermonkey

Policy db requires package couchrest
  Package couchrest requires rubygems

Set up an SSH tunnel to get the remote futonI tend to use 5994 locally to avoid conflicts with the local CouchDB. ssh -L 5994:localhost:5984 where once again, should be replaced with the public DNS name listed on the Amazon Web Services instance view. Point your browser to http://localhost:5994/_utils/ for that familiar futon view.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.