BIG DATA GURUKUL

Open the world of Knowledge

MONGODB INSTALLATION ON AWS CLUSTER

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
       baseurl=https://repo.mongodb.org/yum/amazon/2013.03/mongodb-org/3.2/x86_64/
       gpgcheck=1
       enabled=1
       gpgkey=https://www.mongodb.org/static/pgp/server-3.2.asc" |
       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:

          >mongo

 

   # 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.

              >rs.initiate({_id:”bdg-mongodb”,version:1,members:[{_id:0,host:”bdg-hdp-admin:27017”]}});

 

        To check status:

              >rs.status();

  

      #Then add other members as below:

              >rs.add(‘bdg-hdp-master:27017’);


              


              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.

                  >rs.addArb(‘bdg-hdp-datanode2:27017’);

 

         Again check status rs.status()


           


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