Installing MongoDB on Debian 7.5

The development server caters for the hosting of schema-free document-oriented databases during the development of web-based applications.

Installing MongoDB

The official packages are generally more up to date than the packages distributed with Debian. To enable the installation of the official packages, we need to import the public GPG key of the MongoDB package store. To import the public GPG key to the system key ring, we execute the following command in a “root” shell.

apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10

Once the key is imported, we need to create an APT source list file for MongoDB. To create the file, we execute the following command in a “root” shell.

echo 'deb http://downloads-distro.mongodb.org/repo/debian-sysvinit dist 10gen' > /etc/apt/sources.list.d/mongodb.list

Once the source list file is created, we need to reload the local package database. To reload the local package database, we execute the following command in a “root” shell.

apt-get update

Once the package database is updated, we can install the latest stable version of MongoDB. To install the MongoDB package, we execute the following command in a “root” shell.

apt-get install mongodb-org

Configuring MongoDB

The configuration of MongoDB is defined in the /etc/mongod.conf file. It is recommended to stop the daemon before making any configuration changes.

To stop the daemon, we stop the mongod service by executing the following command in a “root” shell.

service mongod stop

dbpath

dbpath = /var/lib/mongodb

By default, MongoDB stores its databases under /var/lib/mongodb. To store the databases under /home/mongodb, we would move the current databases by executing the following command in a “root” shell.

mv /var/lib/mongodb /home

To update the location, we set the value of dbpath to /home/mongodb in the /etc/mongodb.conf file.

dbpath = /home/mongodb

port

port = 27017

By default, MongoDB listens on port 27017 for connections. By setting the value of port, MongoDB can listen on a different port for connections. The default ports used by MongoDB, is listed in the reference documentation.

bind_ip

bind_ip = 127.0.0.1

By default, MongoDB binds to the localhost IP address. By specifying an IP address for bind_ip, MongoDB will bind to that specific address.

bind_ip = 192.168.100.14

From the example above, MongoDB will only bind to the IP address specified, namely 192.168.100.14.

To start the daemon, we start the mongod service by executing the following command in a “root” shell.

service mongod start
Advertisements

One thought on “Installing MongoDB on Debian 7.5

Comments are closed.