Install MongoDB 4.2 on CentOS8
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 CentOS8.
[root@srv16 ~]# uname -r 4.18.0-147.8.1.el8_1.x86_64 [root@srv16 ~]# cat /etc/redhat-release CentOS Linux release 8.1.1911 (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.
[root@srv16 ~]# yum install mongodb-org Last metadata expiration check: 0:00:17 ago on Sun 07 Jun 2020 03:25:38 AM BST. Dependencies resolved. =============================================================================== Package Architecture =============================================================================== Installing: mongodb-org x86_64 Installing dependencies: python2 x86_64 python2-libs x86_64 python2-pip-wheel noarch python2-setuptools-wheel noarch mongodb-org-mongos x86_64 mongodb-org-server x86_64 mongodb-org-shell x86_64 mongodb-org-tools x86_64 Installing weak dependencies: python2-pip noarch python2-setuptools noarch Enabling module streams: python27 Transaction Summary =============================================================================== Install 11 Packages Total download size: 129 M Installed size: 322 M Is this ok [y/N]: y
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@srv16 ~]# systemctl start mongod
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'
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'
This warning 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@srv16 ~]# cat /sys/kernel/mm/transparent_hugepage/enabled [always] madvise never [root@srv16 ~]# echo never > /sys/kernel/mm/transparent_hugepage/enabled [root@srv16 ~]# 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
[root@srv16 ~]# grep -i cmdline /etc/default/grub GRUB_CMDLINE_LINUX="crashkernel=auto resume=/dev/mapper/cl-swap rd.lvm.lv=cl/root rd.lvm.lv=cl/swap console=ttyS0 transparent_hugepage=never"
Rebuild /boot/grub2/grub.cfg file by running grub2-mkconfig like below.
[root@srv16 ~]# grub2-mkconfig -o /boot/grub2/grub.cfg Generating grub configuration file ... [ 2880.382127] fuse init (API version 7.27) 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@srv16 ~]# mongo MongoDB shell version v4.2.7 connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb Implicit session: session { "id" : UUID("9362166c-5ed9-4862-acdc-17cb5e6f4d00") } MongoDB server version: 4.2.7 >
Leave a Reply