Open the world of Knowledge


Following are step by step commands which can be used to configure MongoDB on AWS EC2 instance. To configure MongoDB we will require:

  1.            Red Hat Linux Or Windows(as per your choice)
  2.            MongoDB installed via yum
  3.            EBS volume for data and log

# Login to aws console.

Here I have Hadoop- cluster with 4 instances. I have selected Red Hat OS.

To install mongodb on Red hat follow the steps below:

#Select one node on which you want mongodb to be installed.


  #Create /data/db folder:

      >sudo mkdir /data/mongodb

  #Createlog directory:

      >sudo mkdir /log

  #Update installed packages, add the MongoDB yum repo:

       echo "[mongodb-org-3.2]

       name=MongoDB Repository
       gpgkey=" |
       sudo tee -a /etc/yum.repos.d/mongodb-org-3.2.repo

 #Install MongoDB:
        >sudo yum -y update && sudo yum install -y mongodb-org-server \ mongodb-org-shell mongodb-org-tools

 #Now you have to configure mongodb parameter inside /ect/mongod.conf file



  Change permission of mongod.conf file:

           >sudo chmod 777 mongod.conf



  #Edit parameters of mongod.conf file:

            > vi /etc/mongod.conf


      Change following parameters.

        path : /log/mongod.log

       dbPath : /data/db


        Save the file and exit vi editor.


  # Start mongodb service

          > sudo mongod


 It will give you output such as 'waiting for connection on port 27017', which means you have successfully installed mongodb on  aws instance.

Now, connect to the MongoDB database using the mongo shell:



   # Follow the same procedure for all instances.


            → To start replication on instances ←


    Make sure you have stopped all running mongod instances.


       #Edit mongod.conf file

            >vi /etc/mongod.conf

    Enable replication and add replSetName and Remove bindIP under network interfaces.



           Save the file and exit vi editor.

     # Run below command to start instance as replica

              >sudo mongod --config /etc/mongod.conf


       It will give the below output.


  ** Follow the same procedure on all mongodb instance.


    #Open mongo shell and type below command to initiate replication.



        To check status:



      #Then add other members as below:



              Add all other members similarly.


       #To add arbiter


         Arbiters are mongod instances that are part of a replica set but they do not hold data. Arbiters participate in elections in              order to break ties. If a replica set has an even number of members, then add an arbiter.



         Again check status rs.status()


            Your mongoDB cluster is up now. You can start working on your database.