MongoDB is NoSQL database which is used to store large amount of data with as document storage with schema schema.
It done’t have tabular format of database like relational database or SQL database like MySQL, PostgresSQL, Oracle etc. It used world wide because of its features like replication, high availability, indexing and auto-sharing.

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.”

Recently MongoDB released new version 4.2 which could be install on CentOS/RHEL/OEL 6/7/8

  • RHEL / CentOS / Oracle 8 (Starting in MongoDB Community 4.2.1)
  • RHEL / CentOS / Oracle 7
  • RHEL / CentOS / Oracle 6

In this we will see how we can install MongoDB 4.2 Community Edition Database in CentOS6. In this series we will see other installation on Which are almost same as this one.

SetUP

Using CentOS6.

[root@srv13 ~]# cat /etc/redhat-release 
CentOS release 6.10 (Final)
[root@srv13 ~]# uname -r
2.6.32-754.29.2.el6.x86_64

Installation

For installation of MongaDB Database server we need to download its RPM packages from Mongodb repositories, which could resolve all dependencies required for these packages. So yum configuration we need to create Yum repo file like below.

We would be creating /etc/yum.repos.d/mongodb.repo file that would contain path of repositories

[root@srv16 ~]# cat  /etc/yum.repos.d/mongodb.repo
[mongodb] 
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1

Once file has been save in mentioned location, we could start Installing MongoDB packages through yum command like below.

# yum install  mongodb-org

Installing:
 mongodb-org                                         x86_64    
Installing for dependencies:
 mongodb-org-mongos                                  x86_64    
 mongodb-org-server                                  x86_64    
 mongodb-org-shell                                   x86_64    
 mongodb-org-tools                                   x86_64    

Transaction Summary
===============================================================
Install       5 Package(s)

Total download size: 119 M
Installed size: 283 M
Is this ok [y/N]: 

In above command, we are installing all mongaDB packages, we can install them individually, in case requirement is different then just installing from scratch.

Now our mongoDB is installed and we can start MongoDB service.

[root@srv13 ~]# /etc/init.d/mongod start
Starting mongod: [  OK  ]

Now we should try connecting Mongo console. We have some warning on console. Let’s try to understand all warning and try to clear them one by one.

Below are warning comes on Mongo console.

Server has startup warnings: 

WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
         See http://dochub.mongodb.org/core/prodnotes-filesystem

WARNING: Access control is not enabled for the database.
         Read and write access to data and configuration is unrestricted.

WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
       We suggest setting it to 'never'

WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
       We suggest setting it to 'never'

WARNING: soft rlimits too low. rlimits set to 1024 processes, 64000 files. 
	Number of processes should be at least 32000 : 0.5 times number of files.

I removed unnecessary time-stamp from logs, so that it would be clear for understanding. Let’s deal all of them one by one.

XFS filesystem for DataDir

MongoDB recommended to use xfs file-system for this new MongoDB version 4.2. Which cause below Warning message.

WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
         See http://dochub.mongodb.org/core/prodnotes-filesystem

So we should use xfs file-system, which would make it happy for Data Directory point of view.
For same i attach another disk, which is format with XFS file-system like below

[root@srv13 ~]# df -hTP /var/lib/mongo/
Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/vdb       xfs    10G  333M  9.7G   4% /var/lib/mongo

Access control enabled

WARNING: Access control is not enabled for the database.
         Read and write access to data and configuration is unrestricted.

When we connected to MongoDB, it also come with Warning for “Access control is not for the database”.
We can also work on this with very simple addition in mongo configuration file.

Add below code in /etc/mongod.conf configuration file

security:
    authorization: "enabled"

After addition of Above code in /etc/mongod.conf configuration file we need to restart mongo service to get ride of above Warning message

Hugepages Warning

WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
        We suggest setting it to 'never'

WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
        We suggest setting it to 'never'

This code be easily get ride with two simple methods, one we can could temporary change in /proc temp file-system.Which change but persistent over reboot.

# echo never > /sys/kernel/mm/redhat_transparent_hugepage/enabled
# echo never > /sys/kernel/mm/redhat_transparent_hugepage/defrag

Restart MongoDB service to get in effect.

To make it persistent over reboot, we have to make it permanent in /etc/grub.conf file in corresponding to you default kernel, like below.

 transparent_hugepage=never

It will automatically get in effect with next reboot as well.

Process and File Limits


** WARNING: soft rlimits too low. rlimits set to 1024 processes, 64000 files.
        Number of processes should be at least 32000 : 0.5 times number of files.

In above Warning Mongo ask for limit, which we can see through proc file-system.

[root@srv13 ~]# cat  /proc/2677/limits | egrep "processes|open files"
Max processes             1024                 64000                processes 
Max open files            64000                64000                files     

We can make it change through /etc/security/limits.d/90-nproc.conf, need to add below line.

mongod      soft    nproc     64000

After addition of this,we need restart MongoDB, will make it effect like below.

[root@srv13 ~]# cat  /proc/2585/limits | egrep "processes|open files"
Max processes             64000                64000                processes 
Max open files            64000                64000                files     

Once all these parameters changed and restart MongoDB process. Now when we connect mongo console, there will be no Warning on console.

[root@srv13 ~]# mongo
MongoDB shell version v4.2.7
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("94b59590-0b0f-4278-9852-c21e499ffa42") }
MongoDB server version: 4.2.7
>