MongoDB deployment, installation and startup service (simple version)

Based on Windows platform

  1. Download the MongoDB installation package

Baidu Netdisk:

Link:Baidu Cloud Disk Please enter the extraction code

Extraction code: mslw

Or log in to the official website to download:Download MongoDB Community Server | MongoDB

If you choose the msi format for Package, you need to install it. If you choose the zip format, you don't need to install it. You only need to unzip the installation package to use it, so it is recommended to choose the zip format.

Downloaded installation package

  1. Unzip the installation package

The decompressed directory does not have the conf and data folders in the picture below. These two folders will be built later and will be mentioned later.

3. Manually create the conf folder and data folder in the folder above.

4. Create the db folder and logs folder in the data folder. Note: The db folder is empty at this time. After running, it will be in the state shown in the figure below.

5. Create a txt text document in the logs folder and rename it mongodb.log. Note: The log file is empty at this time.

Enter the conf folder, create a txt file under the conf folder and rename it mongod.conf.

6. Open mongod.conf with Notepad and enter the following text manually.

storage:

dbPath: "D:/app/install/mongodb-win32-x86_64-2012plus-4.2.18/data/db"

systemLog:

destination: file

path: "D:/app/install/mongodb-win32-x86_64-2012plus-4.2.18/data/logs/mongodb.log"

logAppend: true

Note: There is a space in the places underlined in red (Note: versions above this version have 4 spaces at the beginning and 1 space after :).

If the spaces are not typed correctly, an error will be reported, such as:

出现:Error parsing YAML config file: yaml-cpp: error at line 3, column 8: illegal map value报错

Reason: The configuration file after mongodb 3.0 adopts YAML format. If there is a value after ":", it needs to be followed by a space. If the key only represents the level, there is no need to add a space after ":" (for example: systemLog: does not need a space after it) ). According to the level, the top level does not require space indentation, the first level has 4 spaces per line, the second level has 8 spaces, and so on.

The path of dbPath can be copied to the location of the folder, and then change \ to /.

The path of path can also be copied into the logs folder, then change \ to /, and then add mongodb.log at the end of the path.

  1. Enter the bin folder, enter cmd and press Enter.

Enter the command prompt and enter the startup command:

mongod -f ..\conf\mongod.conf

or

mongo --config ..\conf\mongod.conf

Then press Enter, and the cursor will flash as shown below.

Then open the mongodb.log log file just created.

If the MongoDB starting message shown below appears, the service is started successfully.

If startup fails, possible reasons are:

  1. The file name is incorrectly typed, for example, mongodb is incorrectly typed into mangodb, mongod is incorrectly typed into mongodb, etc.

  1. The contents of the mongod.conf file are incorrectly typed, such as missing spaces, forgetting to change \ in the path to /, or missing changes, typing the wrong path, and waiting. It is recommended that there be no Chinese characters in the path.

Guess you like

Origin blog.csdn.net/weixin_51451545/article/details/129638125