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 CentOS7. In this series we will see other installation on Which are almost same as this one.

SetUP

Using CentOS7.

[root@srv17 ~]# uname -r
3.10.0-1127.10.1.el7.x86_64
[root@srv17 ~]# cat /etc/redhat-release 
CentOS Linux release 7.8.2003 (Core)

MongoDb 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@srv17 ~]# cat /etc/yum.repos.d/mongodb-org-4.2.repo 
[mongodb-org-4.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc

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

# yum install  mongodb-org

Dependencies Resolved

==================================================
 Package                                          
==================================================
Installing:
 mongodb-org                                      
Installing for dependencies:
 mongodb-org-mongos                               
 mongodb-org-server                               
 mongodb-org-shell                                
 mongodb-org-tools                                

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

Total download size: 119 M
Installed size: 283 M
Is this ok [y/d/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@srv17 ~]# service  mongod start
Redirecting to /bin/systemctl start mongod.service

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.

 ** 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'

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

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.

[root@srv17 ~]# cat  /sys/kernel/mm/transparent_hugepage/enabled 
[always] madvise never

[root@srv17 ~]#  echo never >  /sys/kernel/mm/transparent_hugepage/enabled 
[root@srv17 ~]# cat  /sys/kernel/mm/transparent_hugepage/enabled 
always madvise [never]

Restart MongoDB service to get in effect.

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

Append “transparent_hugepage=never” kernel parameter in /etc/default/grub on options GRUB_CMDLINE_LINUX, like below

GRUB_CMDLINE_LINUX="rd.lvm.lv=centos/swap crashkernel=auto ... console=ttyS0,115200  transparent_hugepage=never"

Rebuild /boot/grub2/grub.cfg file by running grub2-mkconfig like below.

[root@srv17 ~]#  grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-1127.10.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1127.10.1.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-1127.8.2.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1127.8.2.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-1127.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1127.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-1062.18.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1062.18.1.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-957.27.2.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-957.27.2.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-8fa8434cdfc0ec4697aa09c612dd0fe7
Found initrd image: /boot/initramfs-0-rescue-8fa8434cdfc0ec4697aa09c612dd0fe7.img
[   49.661275] xor: automatically using best checksumming function:
[   49.671098]    avx       : 36696.000 MB/sec
[   49.693101] raid6: sse2x1   gen() 16628 MB/s
[   49.710098] raid6: sse2x2   gen() 21257 MB/s
[   49.727098] raid6: sse2x4   gen() 24320 MB/s
[   49.744100] raid6: avx2x1   gen() 33660 MB/s
[   49.761098] raid6: avx2x2   gen() 37765 MB/s
[   49.778096] raid6: avx2x4   gen() 42851 MB/s
[   49.778454] raid6: using algorithm avx2x4 gen() (42851 MB/s)
[   49.778902] raid6: using avx2x2 recovery algorithm
[   49.815334] Btrfs loaded, crc32c=crc32c-intel
[   49.822487] fuse init (API version 7.23)
done

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

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

[root@srv17 ~]# mongo
MongoDB shell version v4.2.7
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("9ed71c34-2f92-468d-823d-51e31fd697f5") }
MongoDB server version: 4.2.7
>