Database Linux Tutorials

How To Install MongoDB on CentOS 7 / RHEL 7

main_image_mongo

MongoDB is a cross-platform, document oriented database that provides, high performance, high availability, and easy scalability. MongoDB works on concept of collection and document.

Add MongoDB to Yum repo

vi /etc/yum.repos.d/mongodb.repo

guess_linux_mongodb1

[mongodb]
name=MongoDB repo
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1

guess_linux_mongodb2

Save and close the file.

Before we move on, we should verify that the MongoDB repository exists within the yum utility. The repolist command displays a list of enabled repositories:

yum repolist

guess_linux_mongodb3

Installing MongoDB
We can install the mongodb-org package from the third-party repository using the yum utility.

yum install mongodb-org

guess_linux_mongodb4

guess_linux_mongodb5

Next, start  the MongoDB service with the systemctl utility:

systemctl start mongod

guess_linux_mongodb6

The systemctl utility did not provide a result after executing the start command, but we can check that the service started by viewing the end of the mongod.log file with the cat command:

cat /var/log/mongodb/mongod.log

guess_linux_mongodb7

MongoDB is a threaded application. It can launch additional processes to handle its workload. The warning states that for MongoDB to be most effective the number of processes that it is authorized to spin up should be half that of the number of files that it can have open at any given time. To resolve the warning, alter the processes soft rlimit value for mongod by editing the 20-nproc.conf file:

vi /etc/security/limits.d/20-nproc.conf

guess_linux_mongodb8

Add the following line to the end of file:

mongod soft nproc 32000

guess_linux_mongodb9

restart mongodb

systemctl restart mongod

guess_linux_mongodb10

Testing

type mongo on terminal

mongo

guess_linux_mongodb11

and then type following to show all databases;

show dbs;

guess_linux_mongodb12

guess_linux_mongodb13

Thank You

Leave a Comment