How to install MongoDB as a Windows Service and precautions

Source: Internet
Author: User
Tags install mongodb mongorestore

Transferred from: http://blog.csdn.net/chaijunkun/article/details/7227967.

MongoDB, as a distributed file storage-based database, has been sought after for nearly two years. Flexible Data Access and efficient processing make it widely used in Internet applications.

I recently started to study MongoDB usage on Windows 32-bit platform. For convenience, I prefer to install it as a Windows system service. In this way, you don't need to open a major program for mongod every time.

However, the commands searched on the Internet sometimes do not allow the Service to be successfully registered, and there are several problems. Next, I will write out the problems I encountered and solutions.

First download the latest release: http://www.mongodb.org/downloads from MongoDB official

I currently use version 2.0.2.

The installation is simple. Extract the package. I put it under drive D. The following is the directory structure:

[Plain]
View plaincopyprint?
  1. C: \ Documents ents and Settings \ chaijunkun> D:
  2. D: \> Cd mongodb-win32-i386-2.0.2
  3. D: \ mongodb-win32-i386-2.0.2> Cd Bin
  4. D: \ mongodb-win32-i386-2.0.2 \ bin> dir
  5. The volume in drive D has no labels.
  6. The serial number of the volume is the F4CA-B47C
  7. D: \ mongodb-win32-i386-2.0.2 \ bin directory
  8. <Dir>.
  9. <Dir> ..
  10. 3,644,928 bsondump.exe
  11. 1,793,536 cmd.exe
  12. 3,952,640 mongod.exe
  13. 3,660,800 running dump.exe
  14. 3,651,072 export export.exe
  15. 3,656,192 bytes files.exe
  16. 3,668,992 uninstall import.exe
  17. 3,654,656 mongorestore.exe
  18. 2,807,808 ipvs.exe
  19. 3,689,472 running stat.exe
  20. 3,657,216 topics top.exe
  21. 37,837,312 bytes for 11 files
  22. 2 directories, 97,404,313,600 available bytes

C: \ Documents ents and Settings \ chaijunkun> D: </P> <p> D: \> Cd mongodb-win32-i386-2.0.2 </P> <p> D: \ mongodb-win32-i386-2.0.2> Cd bin </P> <p> D: \ mongodb-win32-i386-2.0.2 \ bin> dir <br/> the volume in drive D has no labels. <Br/> the serial number of the volume is the F4CA-B47C </P> <p> D: \ mongodb-win32-i386-2.0.2 \ bin directory </P> <p> 2012-02-01 <dir>. <br/> <dir> .. <br/> 2011-12-14 3,644,928 bsondump.exe <br/> 2011-12-14 1,793,536 cmd.exe <br/> 2011-12-14 3,952,640 cmdd.exe <br/> 3,660,800 mongodump.exe <br/> 2011-12-14 3,651,072 export export.exe <br/> 3,656,192 inserting files.exe <br/> 3,668,992 inserting import.exe <br/> 3,654,656 mongorestore.exe <br/> 2,807,808 inserting s.exe <br/> 2011-12-14 3,689,472 inserting stat.exe <br/> inserting stat.exe <br/> 3,657,216 rows top.exe <br/> 11 files, 37,837,312 bytes <br/> 2 directories, 97,404,313,600 available bytes

Next we will install the MongoDB service, but pay attention to the following two points:

1. Keep the current directory of the command line unchanged, that is, stay in D: \ mongodb-win32-i386-2.0.2 \ bin directory. Any changes made to other directories that use absolute positioning will cause service installation failure.

Note: What does it mean? That is to say, keep the current status. Suppose you re-open a CMD and the starting directory becomes

[Plain]
View plaincopyprint?
  1. C: \ Documents ents and Settings \ chaijunkun>

C: \ Documents ents and Settings \ chaijunkun>At this time, even if you use[Plain]
View plaincopyprint?

  1. C: \ Documents ents and Settings \ chaijunkun> D: \ mongodb-win32-i386-2.0.2 \ bin \ mongod.exe .............

C: \ Documents ents and Settings \ chaijunkun> D: \ mongodb-win32-i386-2.0.2 \ bin \ mongod.exe .............

In this way, registration fails.

2. Create a directory to save database files. If you do not create this directory, the Service Registration appears to have been successfully registered. After the service is started, the mongod.exe process will be repeatedly established, destroyed, established, and destroyed. The service status changes to "started", "STOPPED", "started", and "STOPPED". The client cannot connect to the database at all.

Here, I used the mongodbdata directory under drive C as the directory for storing data files, so I created the directory:

[Plain]
View plaincopyprint?
  1. D: \ mongodb-win32-i386-2.0.2 \ bin> mkdir c: \ mongodbdata

D: \ mongodb-win32-i386-2.0.2 \ bin> mkdir c: \ mongodbdata
Now, the preparation is complete. You can install the Service as follows:

[Plain]
View plaincopyprint?
  1. D: \ mongodb-win32-i386-2.0.2 \ bin> mongod -- install -- servicename MongoDB -- servicedisplayname MongoDB -- logpath c: \ MongoDB. log -- dbpath c: \ MongoDB -- directoryperdb

D: \ mongodb-win32-i386-2.0.2 \ bin> mongod -- install -- servicename MongoDB -- servicedisplayname MongoDB -- logpath c: \ MongoDB. log -- dbpath c: \ MongoDB -- directoryperdb

Here we will briefly introduce the parameters used and their meanings:

-- Install: Install the MongoDB service.

-- Servicename: the service name used to install the Windows Service

-- Servicedisplayname: the service name displayed in Windows Service Manager, as shown below:

-- Logpath: name of the MongoDB log output file. Although the literal translation of this parameter is "Log Path", you must specify a specific complete file name. Here I am using the MongoDB. log file under the C root directory. This file does not need to be created in advance and can be specified directly.

-- Dbpath: Specifies the path where MongoDB data is stored. This is the most critical parameter. Not only must this directory exist, but it is best not to end.

-- Directoryperdb: this parameter is easy to understand. Let MongoDB create a directory for each database based on different databases. The so-called "directory per Database"

After executing the preceding command, the service can be successfully registered. If the operating system you use is Windows Vista or Windows 7, pay special attention to its UAC mechanism. You must enable cmd as an administrator and then register the service.

Open the Service Manager, start the MongoDB service, and find that the service can run stably and continuously. Congratulations!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.