Install MongoDB on SUSE Linux

10gen provides compiled versions of MongoDB for use on Linux that provides a simple option for users who cannot use packages. This tutorial outlines the basic installation of MongoDB using these compiled versions and an initial usage guide.

Download MongoDB

  • 1.Download MongoDB as various available source:
  1. http://www.mongodb.org/downloads
  2. In a terminal session, begin by downloading the latest release. In most cases you will want to download the 64-bit version of MongoDB.

curl http://downloads.mongodb.org/linux/mongodb-linux-x86_64-x.y.z.tgz > mongo.tgz

If you need to run the 32-bit version, use the following command

curl http://downloads.mongodb.org/linux/mongodb-linux-i686-x.y.z.tgz > mongo.tgz
Note: Replace x.y.z with the current stable version (i.e. 2.0.6).

  • Once you’ve downloaded the release, issue the following command to extract the files from the archive:

tar -zxvf mongo.tgz

  • You can find the mongod binary, and the binaries all of the associated MongoDB utilities, in the bin/directory within the extracted directory.
  • Now, You should place the MongoDB binaries in a central location on the file system that is easy to access and control. Consider /opt or /usr/local/bin.
  • Before you start mongod for the first time, you will need to create the data directory. By default, mongod writes data to the /data/db directory. To create this directory, use the following command:

mkdir -p /data/db

  • Ensure that the system account that will run the mongod process has read and write permissions to this directory. If mongod runs under the mongod user account, issue the following command to change the owner of this folder:

chown mongod /data/db

If you use an alternate location for your data directory, ensure that this user can write to your chosen data path.
You can specify, and create, an alternate path using the –dbpath option to mongod and the above command.

  • The 10gen builds of MongoDB contain no control scripts or method to control the mongod process. You may wish to create control scripts, modify your path, and/or create symbolic links to the MongoDB programs in your /usr/local/bin or /usr/bin directory for easier use.
  • Create a default configuration file located at /etc/mongod.conf

It is used for all configuration parameter for mongod process.

  • For testing purposes, you can start a mongod directly in the terminal without creating a control script:

mongod –config /etc/mongod.conf

Note: The above command assumes that the mongod binary is accessible via your system’s search path, and that you have created a default configuration file located at /etc/mongod.conf.

  • Among the tools included with this MongoDB distribution, is the mongo shell. You can use this shell to connect to your MongoDB instance by issuing the following command at the system prompt(open a new command prompt for mongo process):

./bin/mongo

  • The ./bin/mongo command assumes that the mongo binary is in the bin/ sub-directory of the current directory. This is the directory into which you extracted .tgz file.
  • This will connect to the database running on the localhost interface by default. At the mongo prompt, issue the following two commands to insert a record in the “test” collection of the (default) “test” database and then retrieve that record:

> db.test.save( { a: 1 } )
> db.test.find()

  • A configuration file (/etc/mongod.conf) file contain various configuration parameter like:

logpath= /var/log/mongo/mongod.log
logappend= true
pidfilepath= /var/log/mongo/mongodpid.log
Logpath contain location of log file on your system.

Author: SPEC INDIA


Subscribe Now For Fresh Content

Guest Contribution

We are looking for industry experts to contribute to our blog section through fresh and innovative content.

Write For Us

Our Portfolio

Proven Solutions Across Industries
Technology for Real-Life

Visit Our Portfolio

Scroll Up