Install MongoDB on Windows
2015-04-05 17:23
387 查看
Install MongoDB on Windows
Overview
Use this tutorial to install MongoDB on a 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.
IMPORTANT
If you are running any edition of Windows Server 2008 R2 or Windows 7, please install a
hotfix to resolve an issue with memory mapped files on Windows.
Requirements
On Windows MongoDB requires Windows Server 2008 R2, Windows Vista, or later. The .msi installer includes all other software dependencies and will automaticallyupgrade any older version of MongoDB installed using an .msi file.
Get MongoDB
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
2
Download MongoDB for Windows.
Download the latest production release of MongoDB from the MongoDB downloads page. Ensure you download the correct versionof MongoDB for your Windows system. The 64-bit versions of MongoDB does not work with 32-bit Windows.
Install MongoDB
Interactive Installation
1
Install MongoDB for Windows.
In Windows 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. These instructions assume that you have installed MongoDB to C:\mongodb.
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.1
Install MongoDB for Windows.
Open a shell in the directory containing the .msi installation binary of your choice and invoke:msiexec.exe /q /i mongodb-<version>-signed.msi INSTALLLOCATION="<installation directory>"
By default, this method installs the following MongoDB binaries: mongod.exe, mongo.exe,mongodump.exe, mongorestore.exe, mongoimport.exe, mongoexport.exe,mongostat.exe,
and mongotop.exe. You can specify the installation location for the executable by modifying the <installation directory> value.
To install specific subsets of the binaries, you may specify an ADDLOCAL argument:
msiexec.exe /q /i mongodb-<version>-signed.msi INSTALLLOCATION="<installation directory>" ADDLOCAL=<binary set(s)>
The <binary set(s)> value is a comma-separated
list including one or more of the following:
Server - includes mongod.exe
Client - includes mongo.exe
MonitoringTools - includes mongostat.exe and mongotop.exe
ImportExportTools - includes mongodump.exe, mongorestore.exe,mongoexport.exe,
and mongoimport.exe)
MiscellaneousTools - includes bsondump.exe, mongofiles.exe, mongooplog.exe,
and mongoperf.exe
For instance, to install only the entire set of tools to C:\mongodb, invoke:
msiexec.exe /q /i mongodb-<version>-signed.msi INSTALLLOCATION="C:\mongodb" ADDLOCAL=MonitoringTools,ImportExportTools,MiscellaneousTools
You may also specify ADDLOCAL=ALL to install the complete set of binaries, as in the following:
msiexec.exe /q /i mongodb-<version>-signed.msi INSTALLLOCATION="C:\mongodb" ADDLOCAL=ALL
Run MongoDB
WARNINGDo not make mongod.exe visible
on public networks without running in “Secure Mode” with theauth setting. MongoDB is designed to
be run in trusted environments, and the database does not enable “Secure Mode” by default.
1
Set up the MongoDB environment.
MongoDB requires a data directory to store all data. MongoDB’s default data directorypath 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.
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 worknetwork and
click Allow access. For additional information on security and MongoDB, please see the Security
Documentation.
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.
4
Begin using MongoDB.
To begin using MongoDB, see Getting Started with MongoDB. Also consider the ProductionNotesdocument before deploying MongoDB in a production environment.
Later, to stop MongoDB, press Control+C in the terminal where the mongod instance
is running.
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 pathC:\mongodb\.
If you have installed in an alternative directory, you will need to adjust the paths as appropriate.
1
Open an Administrator command prompt.
Windows 7 / Vista / Server 2008 (and R2)
Press Win + R, then type cmd,then press Ctrl + Shift + Enter.
Windows 8
Press Win + X, then press A.Execute the remaining steps from the Administrator command prompt.
2
Create directories.
Create directories for your database and log files:mkdir c:\data\db mkdir c:\data\log
3
Create a configuration file.
Create a configuration file. This file can include any of the configurationoptions for mongod,
butmust include a valid setting for logpath:
The following creates a configuration file, specifying both the logpath and
the dbpath settings in the configuration file:
echo logpath=c:\data\log\mongod.log> "C:\mongodb\mongod.cfg" echo dbpath=c:\data\db>> "C:\mongodb\mongod.cfg"
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\"" DisplayName= "MongoDB" start= "auto"
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
5
Start the MongoDB service.
net start MongoDB
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
Additional Resources
MongoDB for Developers Free CourseMongoDB for .NET Developers Free Online Course
MongoDB Architecture Guide
相关文章推荐
- install mongodb on windows
- Install MongoDB Community Edition on Windows
- install mongodb on windows
- How to Install MongoDB on Windows
- install mongodb on windows 32
- Install MongoDB Community Edition on Windows
- Install MongoDB Community Edition on Windows
- install mongodb on windows 32
- Install MongoDB on Windows
- Install MongoDB Service on Windows 7
- How can I install Log::Log4perl on Microsoft Windows?
- install scrapy on windows
- How to install a windows software on crossover
- install sybase on windows
- How to install MOSS on Windows Server 2008 R2
- How to install Ruby on rails in Windows 2003/xp 如何安装ROR
- SAP MaxDB 7.7 install log on Windows 2003
- NTP server install on windows
- Install boost on Windows for Visual C++
- VMware Tools does not install on a Windows 2008 guest operating system after upgrading to ESX 4