Showing posts with label MongoDB. Show all posts
Showing posts with label MongoDB. Show all posts

How to Install Mongodb on Ubuntu

Install Mongodb On Ubuntu

In this Article we will learn how to install mongodb on Ubuntu.If you want to install mongodb on other systems i.e fedora,redhat & centos please refer my last article.So lets start with install mongodb  Ubuntu systems.

What is Mongodb?

MongoDB is the leading NoSQL database, designed for how we build and run applications today.MongoDB empowers organizations to be agile and scalable. It helps them enable new types of applications, improve customer experience, accelerate time to market and reduce total cost of ownership (TCO). MongoDB is named from "huMONGOus" meaning "extremely large".
MongoDB is a general purpose, open-source database. MongoDB features:
  • Document data model with dynamic schemas
  • Full, flexible index support and rich queries
  • Auto-Sharding for horizontal scalability
  • Built-in replication for high availability
  • Text search
  • Advanced security
  • Aggregation Framework and MapReduce
  • Large media storage with GridFS 
After looking what is mongodb.let's gets started with installation of mongodb on Ubuntu..

Install Mongodb Ubuntu System

Ubuntu has its own Mongodb Packages but we will be using the offical Mongodb package available on the mongodb website as they are more up-to-date.

  • First Import the public key used by the package management system i.e. dpkg and apt which can be done with the following command.
     sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10

  • Create the repo file or list file for the mongodb using the following command
     echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee                 /etc/apt/sources.list.d/mongodb.list

  • Now it's time to reload the database of package management which can be done with following command
            sudo apt-get update

  • Now it's Time to Install the Mongodb package which can be done 
             sudo apt-get install -y mongodb-org

   This will install the latest stable release of mongodb on ubuntu    if you want to install a specific release of mongodb on ubuntu,Please use the following command.
    
    sudo apt-get install -y mongodb-org=2.6.1 mongodb-org-server=2.6.1 mongodb-org-shell=2.6.1 mongodb-org-mongos=2.6.1 mongodb-org-tools=2.6.1

The above command will install the mongodb version 2.6.1,you can replace the version number with your requirement.

If you have successfully executed all the above steps.You will be able to install mongodb on ubuntu.


Install MongoDB on Fedora, Red Hat Enterprise and CentOS

In this Tutorial we will learn how to Install MongoDB on different Flavors on Linux i.e fedora, Redhat Enterprise and CentOS.

Considerations

For production deployments, always run MongoDB on 64-bit systems.

The default /etc/mongodb.conf configuration file supplied by the 2.6 series packages has bind_ip`set to 127.0.0.1 by default. Modify this setting as needed for your environment before initializing a replica set.
Changed in version 2.6: The package structure and names have changed as of version 2.6. For instructions on installation of an older release, please refer to the documentation for the appropriate version.


Install Mongodb 


Lets begin with the installation of Mongodb with YUM.

 Step 1: Add the Mongodb repo in package management system (YUM) in fedora.
 Create a /etc/yum.repos.d/mongodb.repo file which should have the following  configuration information for the MongoDB repository:

 [mongodb]

 name=MongoDB Repository

 baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/

 gpgcheck=0

 enabled=1

  

The Above configuration will work with 64-bit system,if You are running a 32-bit configuration please use the given below Confiugration:





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



Step 2: Once you have successfully done the changes in the package management system (YUM),It's time to install the Mongodb on the system i.e  fedora, Red Hat Enterprise and CentOS :



To install the latest stable version of MongoDB, simply issue the following command:
  sudo yum install -y mongodb-org

if you want to use a specific version of mongodb,You have  to specify each component package individually and append the version number to the package name,An example is shown below:
   sudo yum install -y mongodb-org-2.6.1 mongodb-org-server-2.6.1 mongodb-org-shell-2.6.1 mongodb-org-mongos-2.6.1 mongodb-org-tools-2.6.1


If you have completed the above two steps successfully,You have installed  mongodb in fedora or Redhat Enterprise .Thanks!!

Upgrade MongoDB Replica Set to 2.4

MongoDB is the leading NoSQL database, designed for how we build and run applications today. MongoDB empowers organizations to be agile and scalable. It helps them enable new types of applications, improve customer experience, accelerate time to market and reduce total cost of ownership (TCO). MongoDB is named from "huMONGOus" meaning "extremely large".
MongoDB is a general purpose, open-source database. MongoDB features:
  • Document data model with dynamic schemas
  • Full, flexible index support and rich queries
  • Auto-Sharding for horizontal scalability
  • Built-in replication for high availability
  • Text search
  • Advanced security
  • Aggregation Framework and MapReduce
  • Large media storage with GridFS 
 After having a overview of what Mongodb is,Lets have look on how to upgrade Mongodb to its latest version on Ubuntu.In the general case, the upgrade from MongoDB 2.2 to 2.4 is a binary-compatible “drop-in” upgrade: shut down the mongod instances and replace them with mongod instances running 2.4. However, before you attempt any upgrade please familiarize yourself with the Recommendations and Checklist

When upgrading, consider the following:
  • For all deployments using authentication, upgrade the drivers (i.e. client libraries), before upgrading the mongod instance or instances.
  • To upgrade to 2.4 sharded clusters must upgrade following the meta-data upgrade procedure.
  • If you’re using 2.2.0 and running with auth enabled, you will need to upgrade first to 2.2.1 and then upgrade to 2.4. See Rolling Upgrade Limitation for 2.2.0 Deployments Running with auth Enabled.
  •  If you have system.users documents (i.e. for auth) that you created before 2.4 you must ensure that there are no duplicate values for the user field in the system.users collection in any database. If you do have documents with duplicate user fields, you must remove them before upgrading.
 You can upgrade to 2.4 by performing a “rolling” upgrade of the set by upgrading the members individually while the other members are available to minimize downtime. Use the following procedure:
  •  Upgrade the secondary members of the set one at a time by shutting down the mongod and replacing the 2.2 binary with the 2.4 binary. After upgrading a mongod instance, wait for the member to recover to SECONDARY state before upgrading the next instance. To check the member’s state, issue rs.status() in the mongo shell.
    • Login to one of the secondary in replica set and shutdown the instances. 
                   Akhil@akhil-3450:~# mongo
                         MongoDB shell version: 2.2.3
                         connecting to: test
                         > use admin;                        
                        > db.shutdownServer()
    •  Now Install the Lastest package of Mongod
      •  Issue the following command to import the 10gen public GPG Key:
                              sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
      • Create a /etc/apt/sources.list.d/10gen.list file and include the following line for the 10gen repository. 
                             deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen
      •  Now issue the following command to reload your repository:
                             sudo apt-get update
      • To install a specific release, append the version number to the package name:
                             sudo apt-get install mongodb-10gen=2.X.X
      •  To install the latest stable version of MongoDB:
                             sudo apt-get install mongodb-10gen
Once you are done with all the above steps successfully,restart the mongodb and wait for this instances to became secondary and in-sync with the master. 
Now continue upgrading the remaining secondary members by repeating the above steps.After you are done with upgrading secondaries to the latest version It's time to upgrade the master to latest version as well.
  • To upgrade master first we need to switch the master,So that one of the Secondary becomes master and the existing master becomes secondary.  
                         Akhil@akhil-3450:~# mongo
                         MongoDB shell version: 2.2.3 
                         connecting to: test
                          > use admin;
                          > rs.StepDown()
  •  Once the primary has stepped down and another member has assumed PRIMARY state, as observed in the output of rs.status(),Follow the above mentioned steps for upgrading Secondaries in the replica set.

After all the members of replica set are upgraded to required version,you can switch back the primary and you are done with upgrade of mongodb.

Recent Posts

Powered by Blogger.

 

© 2013 Akhil's Blog. All rights resevered. Designed by Templateism

Back To Top