Sunday, June 19, 2016

Guide to Install MongoDB 3.2 on CentOS 7.x and RHEL 7.x

http://www.linuxtechi.com/install-mongodb-3-2-on-centos-7and-rhel-7

MongoDB is a scalable, Open source, high performance and document oriented NoSQL database. It is developed and supported by 10gen. NoSQL stats that MongoDB doesn’t use Tables and rows.
MongoDB provide better performance as compared to other databases because it saves the data in JASON like documents along with dynamic schema.
In this article we will describe the installation steps of MongoDB 3.2 on CentOS 7.x and RHEL 7.x

Step:1 Configure MongoDB 3.2 yum Repository.

In both Operating system RHEL7.x and CentOS 7.x yum repositories are kept in ‘/etc/yum.repos.d/’ directory.  Create the mongodb repository file with the name “mongodb-org.repo”.
[root@mongodb ~]# cd /etc/yum.repos.d/
[root@mongodb yum.repos.d]# vi mongodb-org.repo
[mongodb-org]
name=MongoDB 3.2 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

Step:2 Install MongoDB package using yum command.

To install MongoDB and its dependent packages use the below yum command.
[root@mongodb ~]# yum install mongodb-org -y
Above command will install the followings MongoDB Packages
Mongodb-org-package-component
Following files and directory will be created once the MongoDB packages are installed.
  • /etc/mongod.conf — Cofiguration file of MongoDB (By default localhost ip  (127.0.0.1) is bind IP and 27017 is the default port ).
  • /var/lib/mongo  — Data directory of MongoDB
  •  /var/log/mongodb/mongod.log  — Log file of MongoDB

Step:3 Start and Enable the Mongodb service.

Run the beneath commands to start and enable the mongodb service across the reboot.
[root@mongodb ~]# systemctl start mongod.service
[root@mongodb ~]# systemctl enable mongod.service
mongod.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig mongod on
[root@mongodb ~]#
In Case OS firewall is enabled and running then open the MongoDB port ‘27017’ using below firewalld-cmd command.
[root@mongodb ~]# firewall-cmd --zone=public --add-port=27017/tcp --permanent
success
[root@mongodb ~]# firewall-cmd --reload
success
[root@mongodb ~]#

Step:4 Connect to MongoDB from the terminal.

Type the command ‘mongo’ from the terminal to connect MongoDB
[root@mongodb ~]# mongo
While connecting to MongoDB we may get below warning message
Warning-Message-while-connecting-mongdb
Use the below commands to resolve ‘transparent huge page error‘ :
[root@mongodb ~]# echo never > /sys/kernel/mm/transparent_hugepage/enabled 
[root@mongodb ~]# echo never > /sys/kernel/mm/transparent_hugepage/defrag
[root@mongodb ~]# systemctl restart mongod
[root@mongodb ~]#
To make above changes permanent, add the above lines in /etc/rc.local file and assign executable rights to /etc/rc.local file.
[root@mongodb ~]# cat /etc/rc.local
echo never > /sys/kernel/mm/transparent_hugepage/enabled;
echo never > /sys/kernel/mm/transparent_hugepage/defrag;
root@mongodb ~]# chmod +x /etc/rc.local
Use below steps to resolve Warning Error related to rlimits, exact error is shown above.
Add the below entry for mongd user in ‘/etc/security/limits.d/20-nproc.conf’ file.
[root@mongodb ~]# vi /etc/security/limits.d/20-nproc.conf
mongodsoft  nproc   64000
Reboot the Server and then try to connect MongoDB using mongo command:
[root@mongodb ~]# mongo
MongoDB shell version: 3.2.7
connecting to: test
>
As you can see that we are able to connect mongodb without any warnings, So our installation is completed now.

Uninstall / Remove MongoDB

Run the beneath commands one after the another from the console to remove MongoDB completely.
[root@mongodb ~]# systemctl stop mongod
[root@mongodb ~]# yum erase $(rpm -qa | grep mongodb-org)
[root@mongodb ~]# rm -rf /var/log/mongodb
[root@mongodb ~]# rm -rf /var/lib/mongo
[root@mongodb ~]#
Reference:  https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/

No comments:

Post a Comment