Install MongoDB server on CentOS


Please follow the below steps to install MongoDB database server.

Before going for installation check your selinux is disabled on your server. To check selinux status, execute the below command

[root@server ~]# getenforce

If this enabled then please disable by following command

[root@server ~]# echo 0 > /selinux/enforce

Step 1: Create the mongodb respositories.

[root@server ~]# vi /etc/yum.repos.d/mongodb.repo

== For 64-bit architecture ==

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

== For 32-bit architecture [Not recommended for production environment] ==

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

Step 2: Install MongoDB server

To install the current stable release, enter the below command

[root@server ~]# yum install -y mongodb-org

If you want to install the specific release of MongoDB, enter the below command

[root@server ~]# yum install -y mongodb-org-2.6.1 mongodb-org-server-2.6.1 mongodb-org-shell-2.6.1 mongodb-org-mongos-2.6.1 mongodb-org-tools-2.6.1

Step 3: Start/Stop/Restart the services

[root@server ~]# /etc/init.d/mongod start
[root@server ~]# /etc/init.d/mongod stop
[root@server ~]# /etc/init.d/mongod restart

To start MongoDB after server reboots,

[root@server ~]# chkconfig --level 35 mongod on

Step 4: MongoDB Files

Data files: /var/lib/mongo
Log files: /var/log/mongodb
Configuration files: /etc/mongod.conf

The package includes the mongo console. This tool is a console interface similar to mysql.

[root@server ~]# mongo

[root@server ~]# tail -10 /var/log/mogodb/mongod.log

[initandlisten] waiting for connections on port 27017

Port configuration is defined in /etc/mongod.conf, 27017 by default.

Leave a comment

Leave a comment