mongoDB installation, startup and how to set it as a windows service for windows system (summary)

One: Download

      Go to the MongoDB official website  , download the appropriate version for your computer system, and install it in a suitable location. What I downloaded here is:

After installation, I put it on "D drive", and changed the folder name to "mongodb" (the three folders of data, etc, logs are created by myself later, which will be explained later).

 

Two: turn on and off the service

    Create the database directory D:\mongodb\data, then open the cmd command line window, switch to the D:\mongodb\bin directory, and execute the following command (where --dbpath is the specified database storage directory, there are two "-" ):

mongod --dbpath D:\MongoDB\data

At this time, the command line window will print some startup information. When the last line displays the following information, it means that the startup is successful.

2014-04-23T10:38:48.391+0800 [initandlisten] waiting for connections on port 27017

At this time, enter http://localhost:27017/ in the browser and you can see that the display information is:

If you don't know much about cmd commands, you can go to Baidu, as long as you can simply enter the folder (cd..) and exit the folder (cd..), the cmd execution steps are posted below:

At present, the mongodb service has been started. Closing this cmd window will automatically close the service.

Next time you can use the same steps to restart the service. (Not recommended)

In fact, it is painful to start Mongo through the command line every time, so we need to create a permanent service, which requires us to add Mongo to the Windows local service. Continue to return to cmd and execute (a folder and log file will be created to store the log, and the path of the data folder is the path of the local data):

mongod.exe --logpath D:\mongodb\logs\mongodb.log --logappend --dbpath D:\mongodb\data --directoryperdb --serviceName MongoDB --install

After the service is created, it is stopped by default. We need to manually open the service and use the command, net start MongoDB, to start the service. (If it does not take effect, you can also open the task manager yourself, find the relevant service, and open it manually. The figure shows that the mongodb service has been started)

 If you see that the display is running, then it has been done for a long time~ You can start mongodb through this service in the future~

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324668634&siteId=291194637