Skip to content

Mongodb Couchdb

victorkane edited this page Jun 24, 2011 · 10 revisions

Important: On a 32 bit system, MongoDB limits you to 2 Giga of data. So that's what we're doing on this sample app on a dev linode VPS.

getconf LONG_BIT will show you the number of bits in a LONG, which typically matches the architecture type of the OS (i.e. 32 bits for a 32 bit OS and 64 bits for a 64 bit OS):

# getconf LONG_BIT
32

Another indication of which Linux Kernel you have installed (above and beyond what's happening with the processor) is to be found in uname -a, where you will see an explicit x_64 or similar:

You will see something like this on 32-bit systems:

Linux li209-15 2.6.38.3-linode32 #1 SMP Thu Apr 21 20:08:53 UTC 2011 i686 GNU/Linux

and something like this on 64-bit operating systems:

Darwin Victor-Kanes-MacBook-Pro.local 10.7.4 Darwin Kernel Version 10.7.4: Mon Apr 18 21:24:17 PDT 2011; root:xnu-1504.14.12~3/RELEASE_X86_64 x86_64

Installation of CouchDB

Mac

$ brew install couchdb
If this is your first install, automatically load on login with:
    mkdir -p ~/Library/LaunchAgents
    cp /usr/local/Cellar/couchdb/1.0.2/Library/LaunchDaemons/org.apache.couchdb.plist ~/Library/LaunchAgents/
    launchctl load -w ~/Library/LaunchAgents/org.apache.couchdb.plist

If this is an upgrade and you already have the org.apache.couchdb.plist loaded:
    launchctl unload -w ~/Library/LaunchAgents/org.apache.couchdb.plist
    cp /usr/local/Cellar/couchdb/1.0.2/Library/LaunchDaemons/org.apache.couchdb.plist ~/Library/LaunchAgents/
    launchctl load -w ~/Library/LaunchAgents/org.apache.couchdb.plist

Or start manually with:
    couchdb
==> Summary
/usr/local/Cellar/couchdb/1.0.2: 282 files, 2.5M, built in 23 seconds

$ couchdb
Apache CouchDB 1.0.2 (LogLevel=info) is starting.
Apache CouchDB has started. Time to relax.
[info] [<0.31.0>] Apache CouchDB has started on http://127.0.0.1:5984/
[info] [<0.103.0>] 127.0.0.1 - - 'GET' /_utils 301

Ubuntu

See my blog post on the subject: Setting up Cloud App Server with CouchDB, Node.js and Express on Ubuntu 10.04 LTS Part I.

Installation of MongoDB

One simple solution, especially for production sites, would be to install the existing packages for Ubuntu/Debian or Fedora/CentOS, for example see http://www.mongodb.org/display/DOCS/Ubuntu+and+Debian+packages

However, here we just want to install a quick Linux binary to test things out.

Go to the MongoDB Downloads page and obtain the latest release for your system. In our case, on a linode Ubuntu 10.4 LTS, with release 1.8.2, we did the following:

# cd /usr/local/download
# wget http://fastdl.mongodb.org/linux/mongodb-linux-i686-1.8.2.tgz
# cd /usr/local
# tar xvzf downloads/mongodb-linux-i686-1.8.2.tgz
# ln -s mongodb-linux-i686-1.8.2/ mongodb

Now we could just follow directions on the Mongo Quickstart Unix page, but let's organize ourselves a little bit. We want to put the data into a given directory of our choosing, and also set up the log file location.

So we make provision for the database and log file location, and create a config file in /usr/local/etc and specify our own configuration:

# mkdir /var/log/mongodb
# cd /usr/local/mongodb
# mkdir -p data/db
# mkdir etc
# vim /usr/local/etc/mongodb.conf
# cat /usr/local/etc/mongodb.conf 
dbpath = /usr/local/mongodb/data/db
logpath = /var/log/mongodb/output.log
bind_ip = 127.0.0.1

Just to see if it's working, we can start it up like this, specifying our own configuration file

# /usr/local/mongodb/bin/mongod --config /usr/local/mongodb/etc/mongodb.conf
all output going to: /var/log/mongodb/output.log

You can tuck this inside a command like /usr/local/bin/startmongo but it will have to be run via sudo if the user is not root.

In another terminal, we do:

# /usr/local/mongodb/bin/mongo
MongoDB shell version: 1.8.1
connecting to: test
> db.foo.save( { a : 1 } )
> db.foo.find()
{ "_id" : ObjectId("4dc0af75bca176fd02601f8a"), "a" : 1 }
> exit
bye

It's working! MongoDB is up and running.

Check out log contents:

# cat /var/log/mongodb/output.log

There you can confirm that the default listening port is 27017:

http://www.mongodb.org/display/DOCS/Starting+and+Stopping+Mongo

As the quickstart guide says, "Once you have MongoDB installed and running, head over to the Tutorial"

Also see http://www.mongodb.org/display/DOCS/Starting+and+Stopping+Mongo