Skip to main content

MONGODB ON CENTOS 7



                MongoDB is a NoSQL database which provides high performance, high availability, and automatic scaling. NoSQL database means that, unlike MySQL or PostgreSQL, it does not support SQL in order to retrieve or manipulate the stored data.

1.INSTALLING MONGODB                                                                                                                                                                    
First Create a mongodb repository file                                                          
#Vim /etc/yum.repos.d/mongodb-org-3.2.repo
[mongodb-org-3.2]
name=MongoDB 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

Now update and reload the repo
#yum update
#yum repolist

Now install mongodb
#yum -y install mongodb-org

After that start the  service
#systemctl start mongodb


2.FIXING MONGODB ERROR 
                                                     
MongoDB is installed. Now we can access the mongodb shell by using the command below:

#mongo

We will mostly see this error regarding ulimit configuration


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


To solve this problem we need to increase the ulimit configuration of the user mongod.


# vi /etc/security/limits.d/90-nproc.conf


Output:
# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.
*          soft    nproc     4096
root       soft    nproc     unlimited


We needed to change the 4096 to 32000




*          soft    nproc     32000


Then restart the MongoDB service and try again to access the mongo shell, the error is gone now.

#Systemctl restart mongod





3.CREATION OF A ADMINISTRATOR USER

In this step, we will create a new user "admin" for MongoDB with the role 'UserAdminAnyDatabase' from the mongo shell.

# mongo

I will create new user administrator named 'admin' with password 'admin123'. Please use a secure password on your server. Then we will configure the role of the user to be 'UserAdminAnyDatabase'.

#use admin

Type in the MongoDB query below to create the new administrator user:

db.createUser(
  {
    user: "admin",
    pwd: "admin123",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
  }
)

Now make sure that the user has been created with the MongoDB query below.
show users


Now our mongodb is ready to use.