bing
Flat 10% & upto 50% off + Free additional Courses. Hurry up!

Install MongoDB

 

MongoDB runs on most platforms and supports 64-bit architecture for production use and both 64-bit and 32-bit architectures for testing.

 

2.1 Install on Linux

Install MongoDB on Red Hat Enterprise or CentOS Linux – 

Overview: Use this tutorial to install MongoDB on Red Hat Enterprise Linux or CentOS Linux versions 5, 6, and 7 using .rpm packages. While some of these distributions include their own MongoDB packages, the official MongoDB packages are generally more up to date.

Platform Support: This installation guide only supports 64-bit systems.

Packages MongoDB provides officially supported packages in their own repository. This repository contains the following packages:

mongodb-org

This package is a metapackage that will automatically install the four component packages listed below.

mongodb-org-server

This package contains the mongod daemon and associated configuration and init scripts.

mongodb-org-mongos

This package contains the mongos daemon.

mongodb-org-shell

This package contains the mongo shell.

mongodb-org-tools

This package contains the following MongoDB tools: mongoimport bsondump, mongodump, mongoexport, mongofiles, mongooplog, mongoperf, mongorestore, mongostat, and mongotop.

 

Control Scripts The mongodb-org package includes various control scripts, including the init script /etc/rc.d/init.d/mongod. These scripts are used to stop, start, and restart daemon processes.

The package configures MongoDB using the /etc/mongod.conf file in conjunction with the control scripts. See the Configuration File reference for documentation of settings available in the configuration file.As of version 3.0.5, there are no control scripts for mongos. The mongos process is used only in sharding.

You can use the mongod init script to derive your own mongos control script for use in such environments. See the mongos reference for configuration details.

 

Considerations This installation guide only supports 64-bit systems.

The default /etc/mongod.conf configuration file supplied by the 3.0 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

 Step 1: Configure the package management system (yum). Create a /etc/yum.repos.d/mongodb-org-3.0.repo file so that you can install MongoDB directly, using yum.

Changed in version 3.0: MongoDB Linux packages for 3.0 are in a new repository.

For the latest stable release of MongoDB Use the following repository file:

[mongodb-org-3.0]

name=MongoDB Repository

baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.0/x86_64/

gpgcheck=0

enabled=1

For versions of MongoDB earlier than 3.0 To install the packages from an earlier release series, such as 2.4 or 2.6, you can specify the release series in the repository configuration. For example, to restrict your system to the 2.6 release series, create a /etc/yum.repos.d/mongodb-org-2.6.repo file to hold the following configuration information for the MongoDB 2.6 repository:

[mongodb-org-2.6]

name=MongoDB 2.6 Repository

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

gpgcheck=0

enabled=1

.repo files for each release can also be found in the repository itself. Remember that odd-numbered minor release versions are development versions and are unsuitable for production use.

Step 2: Install the MongoDB packages and associated tools. When you install the packages, you choose whether to install the current release or a previous one. This step provides the commands for both.

To install the latest stable version of MongoDB, issue the following command:

sudo yum install -y mongodb-org

To install a specific release of MongoDB, specify each component package individually and append the version number to the package name, as in the following example:

sudo yum install -y mongodb-org-3.0.5 mongodb-org-server-3.0.5 mongodb-org-shell-3.0.5 mongodb-org-mongos

You can specify any available version of MongoDB. However yum will upgrade the packages when a newer version becomes available. To prevent unintended upgrades, pin the package. To pin a package, add the following exclude directive to your /etc/yum.conf file:

exclude=mongodb-org,mongodb-org-server,mongodb-org-shell,mongodb-org-mongos,mongodb-org-tools

Versions of the MongoDB packages before 2.6 use a different repo location. Refer to the version of the documentation appropriate for your MongoDB version.

 

Run MongoDB

Configure SELinux

Important: You must configure SELinux to allow MongoDB to start on Red Hat Linux-based systems (Red Hat Enterprise Linux or CentOS Linux).

To configure SELinux, administrators have three options:

  • Disable SELinux entirely by changing the SELINUX setting to disabled in /etc/selinux/config.
 SELINUX=disabled
  • Set SELinux to permissive mode in /etc/selinux/config by changing the SELINUX setting to permissive .
 SELINUX=permissive
  • Enable access to the relevant ports (e.g. 27017) for SELinux if in enforcing See Default MongoDB Port for more information on MongoDB’s default ports. For default settings, this can be accomplished by running-
semanage port -a -t mongod_port_t -p tcp 27017

You may alternatively choose not to install the SELinux packages when you are installing your Linux operating system, or choose to remove the relevant packages. This option is the most invasive and is not recommended.

 

Data Directories and Permissions –

The MongoDB instance stores its data files in /var/lib/mongo and its log files in /var/log/mongodb by default, and runs using the mongod user account. You can specify alternate log and data file directories in /etc/mongod.conf. See systemLog.path and storage.dbPath for additional information.

If you change the user that runs the MongoDB process, you must modify the access control rights to the /var/lib/mongo and /var/log/mongodb directories to give this user access to these directories.

 

Procedure

Step 1: Start MongoDB. You can start the mongod process by issuing the following command:

sudo service mongod start

Step 2: Verify that MongoDB has started successfully You can verify that the mongod process has started successfully by checking the contents of the log file at /var/log/mongodb/mongod.log for a line reading

[initandlisten] waiting for connections on port <port>

where <port> is the port configured in /etc/mongod.conf, 27017 by default.

You can optionally ensure that MongoDB will start following a system reboot by issuing the following command:

sudo chkconfig mongod on

Step 3: Stop MongoDB. As needed, you can stop the mongod process by issuing the following command:

sudo service mongod stop

Step 4: Restart MongoDB. You can restart the mongod process by issuing the following command:

sudo service mongod restart

You can follow the state of the process for errors or important messages by watching the output in the /var/log/mongodb/mongod.log file.

Step 5: Begin using MongoDB. To help you start using MongoDB, MongoDB provides Getting Started Guides in various driver editions. See getting-started for the available editions.

Later, to stop MongoDB, press Control+C in the terminal where the mongod instance is running.

 

Uninstall MongoDB – To completely remove MongoDB from a system, you must remove the MongoDB applications themselves, the configuration files, and any directories containing data and logs. The following section guides you through the necessary steps.

Step 1: Stop MongoDB. Stop the mongod process by issuing the following command:

sudo service mongod stop

Step 2: Remove Packages. Remove any MongoDB packages that you had previously installed.

sudo yum erase $(rpm -qa | grep mongodb-org)

Step 3: Remove Data Directories. Remove MongoDB databases and log files.

sudo rm -r /var/log/mongodb

sudo rm -r /var/lib/mongo

 

 2.2 Install MongoDB on Windows

Overview: Use this tutorial to install MongoDB on Windows systems.

Platform Support: Starting in version 2.2, MongoDB does not support Windows XP. Please use a more recent version of Windows to use more recent releases of MongoDB.

Requirements: On Windows MongoDB requires Windows Server 2008 R2, Windows Vista, or later. The .msi installer includes all other software dependencies and will automatically upgrade any older version of MongoDB installed using an .msi file.

 

Get MongoDB

Step 1: Determine which MongoDB build you need.

There are three builds of MongoDB for Windows:

  • MongoDB for Windows 64-bit runs only on Windows Server 2008 R2, Windows 7 64-bit, and newer versions of Windows. This build takes advantage of recent enhancements to the Windows Platform and cannot operate on older versions of Windows.
  • MongoDB for Windows 32-bit runs on any 32-bit version of Windows newer than Windows Vista. 32-bit versions of MongoDB are only intended for older systems and for use in testing and development systems. 32-bit versions of MongoDB only support databases smaller than 2GB.
  • MongoDB for Windows 64-bit Legacy runs on Windows Vista, Windows Server 2003, and Windows Server 2008 and does not include recent performance enhancements.

To find which version of Windows you are running, enter the following commands in the Command Prompt or Powershell:

wmic os get caption

wmic os get osarchitecture

 Step 2: Download MongoDB for Windows.

Ensure you download the correct version of MongoDB for yourWindows system. The 64-bit versions of MongoDB do not work with 32-bit Windows.

 

Install MongoDB

Interactive Installation

Step 1: Install MongoDB forWindows. InWindows Explorer, locate the downloaded MongoDB .msi file, which typically is located in the default Downloads folder. Double-click the .msi file. A set of screens will appear to guide you through the installation process.

You may specify an installation directory if you choose the “Custom” installation option.

MongoDB is self-contained and does not have any other system dependencies. You can run MongoDB from any folder you choose. You may install MongoDB in any folder (e.g. D:\test\mongodb).

 

Unattended Installation

You may install MongoDB unattended on Windows from the command line using msiexec.exe.

Step 1: Open an Administrator command prompt. Press the Win key, type cmd.exe, and press Ctrl + Shift + Enter to run the Command Prompt as Administrator.

Execute the remaining steps from the Administrator command prompt.

Step 2: Install MongoDB for Windows. Change to the directory containing the .msi installation binary of your choice and invoke:

msiexec.exe /q /i mongodb-win32-x86_64-2008plus-ssl-3.0.5-signed.msi ^

INSTALLLOCATION="C:\mongodb" ^

ADDLOCAL="all"

You can specify the installation location for the executable by modifying the INSTALLLOCATION value.

By default, this method installs all MongoDB binaries. To install specific MongoDB component sets, you can specify them in the ADDLOCAL argument using a comma-separated list including one or more of the following component sets:

 

component set

 

For instance, to install only the MongoDB utilities, invoke:

msiexec.exe /q /i mongodb-win32-x86_64-2008plus-ssl-3.0.5-signed.msi ^ INSTALLLOCATION="C:\mongodb" ^

ADDLOCAL="MonitoringTools,ImportExportTools,MiscellaneousTools"

 

Run MongoDB –

Step 1: Set up the MongoDB environment.

MongoDB requires a data directory to store all data. MongoDB’s default data directory path is \data\db. Create this folder using the following commands from a Command Prompt:

md \data\db

You can specify an alternate path for data files using the –dbpath option to mongod.exe, for example:

C:\mongodb\bin\mongod.exe --dbpath d:\test\mongodb\data

If your path includes spaces, enclose the entire path in double quotes, for example:

C:\mongodb\bin\mongod.exe --dbpath "d:\test\mongo db data"

You may also specify the dbpath in a configuration file.

Step 2: Start MongoDB.

To start MongoDB, run mongod.exe. For example, from the Command Prompt:

C:\mongodb\bin\mongod.exe

This starts the main MongoDB database process. The waiting for connections message in the console output indicates that the mongod.exe process is running successfully.

Depending on the security level of your system, Windows may pop up a Security Alert dialog box about blocking “some features” of C:\mongodb\bin\mongod.exe from communicating on networks. All users should select Private Networks, such as my home or work network and click Allow access. For additional information on security and MongoDB.

 Step 3: Connect to MongoDB.

To connect to MongoDB through the mongo.exe shell, open another Command Prompt.

C:\mongodb\bin\mongo.exe

If you want to develop applications using .NET, see the documentation of C# and MongoDB for more information.

 Step 4: Begin using MongoDB.

To help you start using MongoDB, MongoDB provides Getting Started Guides in various driver editions. See gettingstarted for the available editions.

Before deploying MongoDB in a production environment, consider the Production Notes document. Later, to stop MongoDB, press Control+C in the terminal where the mongod instance is running.

 

Configure a Windows Service for MongoDB

Step 1: Open an Administrator command prompt.

Press the Win key, type cmd.exe, and press Ctrl + Shift + Enter to run the Command Prompt as Administrator. Execute the remaining steps from the Administrator command prompt.

Step 2: Create directories.

Create directories for your database and log files:

mkdir c:\data\db

mkdir c:\data\log

 Step 3: Create a configuration file.

Create a configuration file. The file must set systemLog.path. Include additional configuration options as appropriate. For example, create a file at C:\mongodb\mongod.cfg that specifies both systemLog.path and storage.dbPath:

systemLog:

destination: file

path: c:\data\log\mongod.log

storage:

dbPath: c:\data\db

 Step 4: Install the MongoDB service.

Install the MongoDB service by starting mongod.exe with the –install option and the -config option to specify the previously created configuration file.

"C:\mongodb\bin\mongod.exe" --config "C:\mongodb\mongod.cfg" --install

To use an alternate dbpath, specify the path in the configuration file (e.g. C:\mongodb\mongod.cfg) or on the command line with the –dbpath option. If needed, you can install services for multiple instances of mongod.exe or mongos.exe. Install each service with a unique –serviceName and –serviceDisplayName. Use multiple instances only when sufficient system resources exist and your system design requires it.

Step 5: Start the MongoDB service.

net start MongoDB

Step 6: Stop or remove the MongoDB service as needed.

To stop the MongoDB service use the following command:

net stop MongoDB

To remove the MongoDB service use the following command:

"C:\mongodb\bin\mongod.exe" –remove

 

Manually Create a Windows Service for MongoDB

You can set up the MongoDB server as a Windows Service that starts automatically at boot time. The following procedure assumes you have installed MongoDB using the .msi installer with the path C:\mongodb\.

If you have installed in an alternative directory, you will need to adjust the paths as appropriate.

Step 1: Open an Administrator command prompt.

Press the Win key, type cmd.exe, and press Ctrl + Shift + Enter to run the Command Prompt as Administrator. Execute the remaining steps from the Administrator command prompt.

Step 2: Create directories.

Create directories for your database and log files:

mkdir c:\data\db

mkdir c:\data\log

 Step 3: Create a configuration file.

Create a configuration file. The file must set systemLog.path. Include additional configuration options

as appropriate. For example, create a file at C:\mongodb\mongod.cfg that specifies both systemLog.path and storage.dbPath:

systemLog:

destination: file

path: c:\data\log\mongod.log

storage:

dbPath: c:\data\db

Step 4: Create the MongoDB service.

Create the MongoDB service.

sc.exe create MongoDB binPath= "C:\mongodb\bin\mongod.exe --service –config=\"C:\mongodb\mongod.cfg sc.exe requires a space between “=” and the configuration values (eg “binPath= ”), and a “\” to escape double quotes.

If successfully created, the following log message will display:

[SC] CreateService SUCCESS

Step 5: Start the MongoDB service.

net start MongoDB

 Step 6: Stop or remove the MongoDB service as needed.

To stop the MongoDB service, use the following command:

net stop MongoDB

To remove the MongoDB service, first stop the service and then run the following command:

sc.exe delete MongoDB

Learn more about The Distinctions Between Couchbase And MongoDB in this insightful blog now!

"0 Responses on Install MongoDB"

Training in Cities

Bangalore, Hyderabad, Chennai, Delhi, Kolkata, UK, London, Chicago, San Francisco, Dallas, Washington, New York, Orlando, Boston

100% Secure Payments. All major credit & debit cards accepted Or Pay by Paypal.

top

Sales Offer

  • To avail this offer, enroll before 05th December 2016.
  • This offer cannot be combined with any other offer.
  • This offer is valid on selected courses only.
  • Please use coupon codes mentioned below to avail the offer
offer-june

Sign Up or Login to view the Free Install MongoDB.