OPTIONS
翻译或纠错本页面

Install MongoDB Enterprise on Windows

2.6 新版功能.

概述

Use this tutorial to install MongoDB Enterprise on Windows systems. MongoDB Enterprise is available on select platforms and contains support for several features related to security and monitoring.

Prerequisites

MongoDB Enterprise Server for Windows requires Windows Server 2008 R2 or later. The MSI installer includes all other software dependencies.

Install MongoDB Enterprise

1

Download MongoDB Enterprise for Windows.

Download the latest production release of MongoDB Enterprise

2

Install MongoDB Enterprise for Windows.

Run the downloaded MSI installer. Make configuration choices as prompted.

MongoDB is self-contained and does not have any other system dependencies. You can install MongoDB into any folder (e.g. D:\test\mongodb) and run it from there. The installation wizard includes an option to select an installation directory.

Run MongoDB Enterprise

警告

Do not make mongod.exe visible on public networks without running in “Secure Mode” with the auth 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 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"
2

Start MongoDB.

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

C:\Program Files\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:\Program Files\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, please see the Security Documentation.

3

Connect to MongoDB.

To connect to MongoDB through the mongo.exe shell, open another Command Prompt. When connecting, specify the data directory if necessary. This step provides several example connection commands.

If your MongoDB installation uses the default data directory, connect without specifying the data directory:

C:\mongodb\bin\mongo.exe

If you installation uses a different data directory, specify the directory when connecting, as in this 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"

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 MongoDB 快速入门. Also consider the 生产环境指南 document before deploying MongoDB in a production environment.

Configure a Windows Service for MongoDB Enterprise

You can set up the MongoDB server as a Windows Service that starts automatically at boot time.

1

Configure directories and files.

Create a configuration file and a directory path for MongoDB log output (logpath):

Create a specific directory for MongoDB log files:

md "C:\Program Files\MongoDB\log"

In the Command Prompt, create a configuration file for the logpath option for MongoDB:

echo logpath="C:\Program Files\MongoDB\log\mongo.log" > "C:\Program Files\MongoDB\mongod.cfg"
2

Run the MongoDB service.

Run all of the following commands in Command Prompt with “Administrative Privileges:”

Install the MongoDB service. For --install to succeed, you must specify the logpath run-time option.

"C:\Program Files\MongoDB\bin\mongod.exe" --config "C:\Program Files\MongoDB\mongod.cfg" --install

Modify the path to the mongod.cfg file as needed.

To use an alternate dbpath, specify the path in the configuration file (e.g. C:\Program Files\MongoDB\mongod.cfg) or on the command line with the --dbpath option.

If the dbpath directory does not exist, mongod.exe will not start. The default value for dbpath is \data\db.

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.

3

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:\Program Files\MongoDB\bin\mongod.exe" --remove

Configure a Windows Service for MongoDB Enterprise

注解

There is a known issue for MongoDB 2.6.0, SERVER-13515, which prevents the use of the instructions in this section. For MongoDB 2.6.0, use Manually Create a Windows Service for MongoDB Enterprise to create a Windows Service for MongoDB.

You can set up the MongoDB server as a Windows Service that starts automatically at boot time.

1

Configure directories and files.

Create a configuration file and a directory path for MongoDB log output (logpath):

Create a specific directory for MongoDB log files:

md "C:\Program Files\MongoDB\log"

In the Command Prompt, create a configuration file for the logpath option for MongoDB:

echo logpath="C:\Program Files\MongoDB\log\mongo.log" > "C:\Program Files\MongoDB\mongod.cfg"
2

Run the MongoDB service.

Run all of the following commands in Command Prompt with “Administrative Privileges:”

Install the MongoDB service. For --install to succeed, you must specify the logpath run-time option.

"C:\Program Files\MongoDB\bin\mongod.exe" --config "C:\Program Files\MongoDB\mongod.cfg" --install

Modify the path to the mongod.cfg file as needed.

To use an alternate dbpath, specify the path in the configuration file (e.g. C:\Program Files\MongoDB\mongod.cfg) or on the command line with the --dbpath option.

If the dbpath directory does not exist, mongod.exe will not start. The default value for dbpath is \data\db.

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.

3

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:\Program Files\MongoDB\bin\mongod.exe" --remove

Manually Create a Windows Service for MongoDB Enterprise

The following procedure assumes you have installed MongoDB using the MSI installer, with the default path C:\Program Files\MongoDB 2.6 Enterprise.

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

1

Open an Administrator command prompt.

Press Win + R, then type cmd, then press Ctrl + Shift + Enter.

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 configuration options for mongod, but must 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:\Program Files\MongoDB 2.6 Standard\mongod.cfg"
echo dbpath=c:\data\db>> "C:\Program Files\MongoDB 2.6 Standard\mongod.cfg"
4

Create the MongoDB service.

Create the MongoDB service.

sc.exe create MongoDB binPath= "\"C:\Program Files\MongoDB 2.6 Enterprise\bin\mongod.exe\" --service --config=\"C:\Program Files\MongoDB 2.6 Standard\mongod.cfg\"" DisplayName= "MongoDB 2.6 Standard" 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