Install MongoDB On RHEL, CentOS, Fedora, Amazon Linux

MongoDB is a powerful, flexible and scalable general-purpose database. It is an agile database that allows schemas to change quickly as applications evolve. It is a NoSql Database.

Packages

MongoDB provides packages of the officially supported MongoDB builds in its own repository. This repository provides the MongoDB distribution in the following packages:

  • mongodb-org

– This package is a metapackage that will automatically install the four component packages listed below.

  • mongodb-org-server

– This package contains the mongod daemon and associated configuration and init scripts.

  • mongodb-org-mongos

– This package contains the mongos daemon.

  • mongodb-org-shell

– This package contains the mongo shell.

  • mongodb-org-tools

– This package contains the following MongoDB tools:

  • mongoimport bsondump,
  • mongodump,
  • mongoexport,
  • mongofiles,
  • mongooplog,
  • mongoperf,
  • mongorestore,
  • mongostat,
  • and mongotop.

The mongodb-org package includes various control scripts, including the init script /etc/rc.d/init.d/mongod. These scripts are used to stop, start, and restart daemon processes.

The package configures MongoDB using the /etc/mongod.conf file in conjunction with the control scripts. See the Configuration File reference for documentation of settings available in the configuration file.

As of version 2.6.6, there are no control scripts for mongos. The mongos process is used only in sharing. You can use the mongod init script to derive your own mongos control script for use in such environments.

The default /etc/mongodb.conf configuration file supplied by the 2.6 series packages has bind_ip set to 127.0.0.1 by default. Modify this setting as needed for your environment before initializing a replica set.

Install MongoDB:

Configure Package Management System (YUM)

Create a /etc/yum.repos.d/mongodb.repo file to hold the following configuration information for the MongoDB repository:

If you are running a 64-bit system, use the following configuration:

 [mongodb]
 name=MongoDB Repository
 baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
 gpgcheck=0
 enabled=1

Screenshot from 2014-12-13 12:57:02

Screenshot from 2014-12-16 12:30:01

If you are running a 32-bit system, which is not recommended for production deployments, use the following configuration:

 [mongodb]
 name=MongoDB Repository
 baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686/
 gpgcheck=0
 enabled=1

Now, Install Packages using the following command:

[root@reetika ~]#  yum install  mongo-10gen  mongo-10gen-server

The MongoDB instance stores its data files in the /var/log/mongodb and its log files in /var/log/mongodb, and run using the mongod user account. If you change the user that runs the MongoDB process, you must modify the access control rights to the /var/lib/mongo and /var/log/mongo directories.

Screenshot from 2014-12-16 12:38:58

You can check logs from here.

[root@ reetika ~]# tail -f /var/log/mongodb/mongod.log

Sample output:

 2014-12-16T12:56:09.646+0530 [initandlisten] git version: 608e8bc319627693b04cc7da29ecc300a5f45a1f
 2014-12-16T12:56:09.646+0530 [initandlisten] build info: Linux build10.nj1.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
 2014-12-16T12:56:09.646+0530 [initandlisten] allocator: tcmalloc
 2014-12-16T12:56:09.646+0530 [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1" }, processManagement: { fork: true, pidFilePath: "/var/run/mongodb/mongod.pid" }, storage: { dbPath: "/var/lib/mongo" }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
 2014-12-16T12:56:09.738+0530 [initandlisten] journal dir=/var/lib/mongo/journal
 2014-12-16T12:56:09.746+0530 [initandlisten] recover : no journal files present, no recovery needed
 2014-12-16T12:56:09.869+0530 [initandlisten] waiting for connections on port 27017
 2014-12-16T12:57:09.935+0530 [clientcursormon] mem (MB) res:29 virt:457
 2014-12-16T12:57:09.935+0530 [clientcursormon]  mapped (incl journal view):160
 2014-12-16T12:57:09.936+0530 [clientcursormon]  connections:0

You may optionally ensure that MongoDB will start following a system reboot by issuing the following command

[root@reetika ~]#  chkconfig mongod on

Screenshot from 2014-12-16 13:45:26

You can start/stop/restart or check the status of mongodb service using the following commands:

 root@reetika:~# service mongodb start
 start: Job is already running: mongodb
 root@reetika:~# service mongodb status
 mongodb start/running, process 22761
 root@reetika:~# service mongodb stop
 mongodb stop/waiting
 root@reetika:~# service mongodb start
 mongodb start/running, process 22842

That’s it. MongoDB has been installed.

Cheers!