As per Wikipedia
“MongoDB is a free and open-source cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with schemas. MongoDB is developed by MongoDB Inc. and is free and open-source, published under a combination of the GNU Affero General Public License and the Apache License.”
MongoDB. In this post, we would see how could we do Installation of MongoDB on RHEL/CentOS7

Setup

We are working on CentOS 7.3 and MongoDB 3.2.15

[root@srv7 ~]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
[root@srv7 ~]# uname  -r
3.10.0-514.26.2.el7.x86_64

db version v3.2.16
git version: 056bf45128114e44c5358c7a8776fb582363e094
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
allocator: tcmalloc
modules: none
build environment:
    distmod: rhel70
    distarch: x86_64
    target_arch: x86_64

Addition of MongoDB repositories

MongoDB packages are not present in default CentOS repositories, SO we have to add MongoDB official repositories. It always good to work with official MongoDB repositories as it contains latest packages.

For same , create file as mentioned below.

[root@srv7 ~]# cat /etc/yum.repos.d/mongodb-org.repo
[mongodb-org-3.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.2.asc

Check it once through “yum repolist”

[root@srv7 ~]# yum repolist "mongodb-org-3.4"
repo id                            repo name                     status
!mongodb-org-3.4/7                 MongoDB Repository            35

Install MongoDB packages

Let’s install MongoDB Packages through yum install command

Dependencies Resolved
=====================================================================================
 Package                        Arch      Version          Repository           Size
=====================================================================================
Installing:
 mongodb-org                    x86_64    3.2.16-1.el7     mongodb-org-3.2     5.8 k
Installing for dependencies:
 mongodb-org-mongos             x86_64    3.2.16-1.el7     mongodb-org-3.2     5.7 M
 mongodb-org-server             x86_64    3.2.16-1.el7     mongodb-org-3.2      13 M
 mongodb-org-shell              x86_64    3.2.16-1.el7     mongodb-org-3.2     6.8 M
 mongodb-org-tools              x86_64    3.2.16-1.el7     mongodb-org-3.2      41 M

Transaction Summary
=====================================================================================
Install  1 Package (+4 Dependent packages)

Total download size: 66 M
Installed size: 202 M
Is this ok [y/d/N]: y

Start of MongoDB Service

As MongoDB packages are installed, let’s start MongoDB service on Machine.

[root@srv7 ~]# systemctl start mongod
[root@srv7 ~]# ps -fC mongod
UID        PID  PPID  C STIME TTY          TIME CMD
mongod    2586     1  0 09:26 ?        00:00:00 /usr/bin/mongod -f /etc/mongod.conf

[root@srv7 ~]# netstat -ntlp| grep mongod
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      2586/mongod

let’s check MongoDB. status or see services running through MongoDB console.

[root@srv7 ~]# mongo
MongoDB shell version: 3.2.16
connecting to: test
Server has startup warnings:
2017-07-28T14:07:58.694+0530 I CONTROL  [initandlisten]
2017-07-28T14:07:58.694+0530 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled                                                                                                           is 'always'.
2017-07-28T14:07:58.694+0530 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-07-28T14:07:58.694+0530 I CONTROL  [initandlisten]
2017-07-28T14:07:58.694+0530 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag                                                                                                           is 'always'.
2017-07-28T14:07:58.694+0530 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-07-28T14:07:58.694+0530 I CONTROL  [initandlisten]
2017-07-28T14:07:58.694+0530 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 4096 p                                                                                                          rocesses, 64000 files. Number of processes should be at least 32000 : 0.5 times number of files.
2017-07-28T14:07:58.694+0530 I CONTROL  [initandlisten]

Now we have three errors in console, we could resolve them first two with tuned profile with below commands.

First we should check active profile

#tuned-adm active
Current active profile: virtual-guest

Now we have to create a directory for new profile.

#mkdir /etc/tuned/virtual-guest-nothp
#cd /etc/tuned/no-thp

Create new profile file for new profile

#cat /etc/tuned/virtual-guest-nothp/tuned.conf 
[main]
include= virtual-guest

[vm]
transparent_hugepages=never

[script]
script=script.sh

create script mentioned in profile file

#cat /etc/tuned/virtual-guest-nothp/script.sh
#!/bin/sh

. /usr/lib/tuned/functions

start() {
    echo never > /sys/kernel/mm/transparent_hugepage/defrag
    return 0
}

stop() {
    return 0
}

process $@

Make these files executable.

cd /etc/tuned/virtual-guest-nothp
chmod +x tuned.conf script.sh

Enable new profile

tuned-adm profile virtual-guest-nothp

Now restart MongoDB service.

#systemctl restart mongod

[root@srv7 no-thp]# mongo
MongoDB shell version: 3.2.16
connecting to: test
Server has startup warnings:
2017-07-28T15:46:45.064+0530 I CONTROL  [initandlisten]
2017-07-28T15:46:45.064+0530 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2017-07-28T15:46:45.064+0530 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-07-28T15:46:45.064+0530 I CONTROL  [initandlisten]
2017-07-28T15:46:45.064+0530 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 4096 processes, 64000 files. Number of processes should be at least 32000 : 0.5 times number of files.
2017-07-28T15:46:45.064+0530 I CONTROL  [initandlisten]

Now we could see there is only one error prompt on the console. For this error, we need to add one entry in limits.conf

#echo "mongod soft nproc 32000" >> /etc/security/limits.d/20-nproc.conf

Now restart MongoDB again and check mongo shell.

#systemctl restart mongod

[root@srv7 ~]# mongo
MongoDB shell version: 3.2.16
connecting to: test
> db.stats()
{
        "db" : "test",
        "collections" : 0,
        "objects" : 0,
        "avgObjSize" : 0,
        "dataSize" : 0,
        "storageSize" : 0,
        "numExtents" : 0,
        "indexes" : 0,
        "indexSize" : 0,
        "fileSize" : 0,
        "ok" : 1
}
>
bye

Now we can all errors on mongo console are resolved and we are ready and running MongoDB server on CentOS7