Skip to main content

For Application Data Storage on Fedora 14, Use MongoDB

Introduction

MongoDB is a database engine that gives users access to key-value databases that are not related to each other in any way. It is a component of the expanding NoSQL movement, which is geared at the creation of a replacement for conventional relational database management systems (RDBMS). In addition to having a design that is schema-free and an architecture that is scalable, MongoDB also offers an output format that is based on JSON and specialised language specific bindings. These features make it especially appealing for use in the building of bespoke software applications. Despite the fact that MongoDB is still a relatively young project and is not yet packaged by the majority of the main operating system distributions, the software has already been utilised in a number of large scale production installations such as "GitHub," "SourceForge," and "DISQUS."

Install MongoDB

Prerequisites

Use the following command to make sure that all of the software you have installed is up-to-date:

#yum update

You should get the most recent binaries from the upstream source, which at the time of this writing is version 1.6.5. Make sure that the version of MongoDB that you download was built for the architecture of your computer system. This will guarantee that the software runs properly on your computer. The 32-bit version is used in this text; however, the 64-bit edition may be used with these procedures by making a few adjustments. It has been brought to our attention that the database size restriction for the 32-bit version of MongoDB is 2 GB. If you anticipate storing more than 2 terabytes of data, you should make sure that you are using the 64-bit version of MongoDB and that you have deployed a system that is capable of running 64 bits.

#cd /opt/
#wget http://fastdl.mongodb.org/linux/mongodb-linux-i686-1.6.5.tgz
#tar zxvf mongodb-linux-i686-1.6.5.tgz
#mv mongodb-linux-i686-1.6.5 /opt/mongodb

*The binaries for MongoDB are now in the /opt/mongodb/bin/ folder. MongoDB is now set up in the /opt/mongodb/ folder. In this example, it is assumed that all database files will be stored in the /srv/db/mongodb folder and log files will be stored in the /srv/db/mongodb.log file. To make this file and directory, type the following commands:

#mkdir -p /srv/db/mongodb
#touch /srv/db/mongodb.log

*Develop Some Simple Control Scripts

In most configurations, the MongoDB server process is managed by passing command line parameters to the mongod binary, which may be found in the /opt/mongodb/bin directory. The creation of control scripts in the /opt/bin/ directory with the names mongodb-start and mongodb-stop may help to ease the execution of these tasks. Execute the following commands in order to generate the necessary directories:

#mkdir /opt/bin/
#mkdir /opt/config/

The scripts may be downloaded and their permissions adjusted by using the following series of commands:

#cd /opt/bin/
#wget -O mongodb-start http://www.linode.com/docs/assets/621-mongodb-start.sh
#wget -O mongodb-stop http://www.linode.com/docs/assets/622-mongodb-stop.sh
#chmod +x *

*Examine the contents of the mongodb-start and mongodb-stop files, and if your deployment calls for a different startup method, make the necessary modifications to these files. The MongoDB process may be started or stopped by executing the /opt/bin/mongodb-start or /opt/bin/mongodb-stop commands, respectively, from this point forward. The variables that are specified in the /opt/config/mongodb file are responsible for controlling the behaviour of the mongod process.

Utilizing a Straightforward Init Script

As a wrapper around the mongodb-start and mongo-stop scripts discussed above, we have also written a very simple "init script." You must still edit and administer the settings of your MongoDB server in the files listed above. This script merely ensures that MongoDB starts at boot time. Issue the following instructions:

#wget -O init-rpm.sh http://www.linode.com/docs/assets/623-mongodb-init-rpm.sh
#mv init-rpm.sh /etc/rc.d/init.d/mongodb
#chmod +x /etc/rc.d/init.d/mongodb /etc/init.d/mongodb
#chkconfig --add mongodb
#chkconfig mongodb on

In addition to this, you will have to set up a user and group for the mongodb database by issuing the following command:

#useradd -M -r --home-dir /opt/mongodb mongodb

Now, use the following command to make sure that the MongoDB user you just established will have access to all of the necessary files located in the /srv/db/ directory structure.

#chown mongodb:mongodb -R /srv/db/

Using the init script, you may start and stop MongoDB using the following commands:

#/etc/init.d/mongodb start
#/etc/init.d/mongodb stop

The MongoDB system that you installed is now fully operational and ready for use.

Thank You