Installing MongoDB on Ubuntu 10.04 LTS

The storage engine for Discovery is MongoDB. The process outlined below installs the official 10gen MongoDB packages.

This document assumes we're beginning the process from a vanilla installation of Ubuntu 10.04 LTS, i.e. no programming languages, databases, or webservers installed. We also assume you have terminal access to the system.

At the terminal execute the following commands:

echo "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen" | sudo tee -a /etc/apt/sources.list

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
sudo apt-get update 
sudo apt-get -y upgrade
sudo apt-get -y install mongodb-10gen

You can test your MongoDB server by connecting with the 'mongo shell':

mongo              # should say connecting to 'test'
                   # CTRL+d exit the shell

You're now ready to install or launch Discovery.

Read on, If you have separate data disk from your operating system disk. The next section covers that configuration.

Configuring Non-Trivial Storage for MongoDB

A common configuration is to split the operating system and data disks on a MongoDB server. For example you might have a 20Gb OS volume and a 500Gb data volume.

To make use of a separate data volume to hold your MongoDB database we need to mount that volume into the OS and move some files around.

Let's assume your OS volume is already mounted from /dev/sda1 and that your data volume will be mounted from /dev/sdb1.

Partitioning the Data Volume

Complete the following section if you haven't paritioned and formatted your data volume.

First, lets create a data volume partition on /dev/sdb, which is going to be called /dev/sdb1.

sudo fdisk /dev/sdb Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1
First cylinder (1-1305, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305):
Using default value 1305
Command (m for help): w The partition table has been altered!
Command (m for help): q

Format the new data volume partition:

sudo mkfs.ext4 /dev/sdb1

You now have a fully prepared data volume. However it hasn't been mounted into the OS and the existing MongoDB files haven't been moved on to it.

Activating the Data Volume

Stop the MongoDB service, move the existing data files out of harms way, and create a mount point for the data volume:

sudo service mongodb stop
sudo mv /var/lib/mongodb /var/lib/mongodb.bak
sudo mkdir /var/lib/mongodb
sudo chown mongodb.mongodb /var/lib/mongodb

Mount the data-volume and move the data files on it:

sudo mount /dev/sdb1 /var/lib/mongodb -o noatime
 sudo mv /var/lib/mongodb.bak/* /var/lib/mongodb
sudo rmdir /var/lib/mongodb.bak

Restart MongoDB and try connecting to the 'mongo shell':

sudo service mongodb start
mongo                        # type 'show dbs'
                             # CTRL+d to exit

Auto-mount the Data Volume on reboot

Ensure your data-volume automatically mounts when the system reboots:

echo "/dev/sdb1  /var/lib/mongodb  ext4 noatime 0 0" | sudo tee -a /etc/fstab
sudo mount -a