- 安装MongoDB >
- Install MongoDB Enterprise >
- 在 Windows 下安装 MongoDB Enterprise
在 Windows 下安装 MongoDB Enterprise¶
On this page
2.6 新版功能.
概述¶
使用本教程在 Windows 下安装 MongoDB Enterprise . MongoDB Enterprise 在当前平台可用,并且包含对安全和监控有关的几个功能的支持。
前提条件¶
MongoDB Enterprise Server for Windows requires Windows Server 2008 R2 or later. The .msi installer includes all other software dependencies and will automatically upgrade any older version of MongoDB installed using an .msi file.
获取 MongoDB Enterprise¶
注解
To install a version of MongoDB prior to 3.2, please refer to that version’s documentation. For example, see version 3.0.
Download MongoDB Enterprise for Windows.¶
Download the latest production release of MongoDB Enterprise.
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
安装 MongoDB Enterprise¶
通过向导安装¶
Install MongoDB Enterprise 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:\Program Files\MongoDB\Server\3.2\.
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).
无人值守安装¶
You may install MongoDB unattended on Windows from the command line using msiexec.exe.
Install MongoDB Enterprise 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.4.0-signed.msi ^
INSTALLLOCATION="C:\Program Files\MongoDB\Server\3.4.0\" ^
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 | Binaries |
Server | mongod.exe |
Router | mongos.exe |
Client | mongo.exe |
MonitoringTools | mongostat.exe, mongotop.exe |
ImportExportTools | mongodump.exe, mongorestore.exe, mongoexport.exe, mongoimport.exe |
MiscellaneousTools | bsondump.exe, mongofiles.exe, mongooplog.exe, mongoperf.exe |
For instance, to install only the MongoDB utilities, invoke:
msiexec.exe /q /i mongodb-win32-x86_64-2008plus-ssl-3.4.0-signed.msi ^
INSTALLLOCATION="C:\Program Files\MongoDB\Server\3.4.0\" ^
ADDLOCAL="MonitoringTools,ImportExportTools,MiscellaneousTools"
支行 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.
Set up the MongoDB environment.¶
MongoDB requires a data directory to store all data. MongoDB’s default data directory path is the absolute path \data\db on the drive from which you start MongoDB. Create this folder by running the following command in 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:\Program Files\MongoDB\Server\3.2\bin\mongod.exe" --dbpath d:\test\mongodb\data
If your path includes spaces, enclose the entire path in double quotes, for example:
"C:\Program Files\MongoDB\Server\3.2\bin\mongod.exe" --dbpath "d:\test\mongo db data"
You may also specify the dbpath in a configuration file.
Start MongoDB.¶
To start MongoDB, run mongod.exe. For example, from the Command Prompt:
"C:\Program Files\MongoDB\Server\3.2\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\Server\3.2\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.
Connect to MongoDB.¶
To connect to MongoDB through the mongo.exe shell, open another Command Prompt.
"C:\Program Files\MongoDB\Server\3.2\bin\mongo.exe
If you want to develop applications using .NET, see the documentation of C# and MongoDB for more information.
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.
Before deploying MongoDB in a production environment, consider the 生产环境指南 document.
Later, to stop MongoDB, press Control+C in the terminal where the mongod instance is running.
设置 MongoDB Enterprise 的 Windows 服务的配置¶
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.
Create directories.¶
Create directories for your database and log files:
mkdir c:\data\db
mkdir c:\data\log
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:\Program Files\MongoDB\Server\3.2\mongod.cfg that specifies both systemLog.path and storage.dbPath:
systemLog:
destination: file
path: c:\data\log\mongod.log
storage:
dbPath: c:\data\db
Install the MongoDB service.¶
重要
Run all of the following commands in Command Prompt with “Administrative Privileges”.
Install the MongoDB service by starting mongod.exe with the --install option and the -config option to specify the previously created configuration file.
"C:\Program Files\MongoDB\Server\3.2\bin\mongod.exe" --config "C:\Program Files\MongoDB\Server\3.2\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.
Start the MongoDB service.¶
net start MongoDB
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\Server\3.2\bin\mongod.exe" --remove
为 MongoDB Enterprise 手动创建 Windows 服务¶
你可以将 MongoDB 服务设置成 Windows Service ,这样就可以在开机时自动启动。
The following procedure assumes you have installed MongoDB using the .msi installer with the path C:\Program Files\MongoDB\Server\3.2\.
If you have installed in an alternative directory, you will need to adjust the paths as appropriate.
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.
Create directories.¶
Create directories for your database and log files:
mkdir c:\data\db
mkdir c:\data\log
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:\Program Files\MongoDB\Server\3.2\mongod.cfg that specifies both systemLog.path and storage.dbPath:
systemLog:
destination: file
path: c:\data\log\mongod.log
storage:
dbPath: c:\data\db
Create the MongoDB service.¶
Create the MongoDB service.
sc.exe create MongoDB binPath= "\"C:\Program Files\MongoDB\Server\3.2\bin\mongod.exe\" --service --config=\"C:\Program Files\MongoDB\Server\3.2\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
Start the MongoDB service.¶
net start MongoDB
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