Cannot start MongoDB as a service

后端 未结 24 1487
情话喂你
情话喂你 2020-12-07 10:07

I have been developing for MongoDB for some months now and would like to install it as a service on my Windows 7 Enterprise machine. The following is the command that I hav

相关标签:
24条回答
  • 2020-12-07 10:28

    After spend half an hour on debug ... I finally found that there is single dash before the "rest" attribute.

    0 讨论(0)
  • 2020-12-07 10:29

    I just encountered the same issue on my windows 7 machine. I followed the directions in MongoDBs Docs for the install, but it wouldn't let me execute "net start MongoDB" unless I was in "C:\". I didn't want to go back and reinstall MongoDB to follow the instructions included in the Webiyo link referenced above though. If you already installed MongoDB according to their docs and want to be able to execute "net start MongoDB" from where ever your project directory is:

    Go to HKEY_LOCAL_MACHINE > SYSTEM > CurrentControlSet > services > MongoDB

    Double click ImagePath under the Name column

    Paste in the following ImagePath ( edit the folder directory and names to match your needs ):

    C:\mongodb\bin\mongod.exe --service  --rest  --master  --logpath=C:\mongodb\log\mongolog.txt  --dbpath=C:\mongodb\data\db --config C:\mongodb\mongod.cfg
    

    Note that if you direct copy this ImagePath value and your "data" folder is in the mongodb directory instead of C:\ add the following line to your "mongod.cfg" file: dbpath=C:\mongodb\data\db

    After I did this, when I run "net stop MongoDB" I get the message "System error 109 has occurred. The pipe has been ended." You may see it as well. This message has been discussed thoroughly at jira.mongodb.org.

    To save you the time of reading the whole back and forth discussion, Tad Marshalls post sums up this issue:

    "... it was working fine in 2.1.0; later changes broke it again. But yes, you get this error message in the current code.

    The explanation is that mongod.exe is exiting from a callback thread created by the Windows Service Control Manager when it calls us due to "net stop mongodb" and this breaks the RPC pipe it used to create the callback thread. We need to reorganize our exit logic to avoid doing this.

    The error message is the only real effect of this issue; we exit on command, cleanly, and inform the Windows Service Control Manager that we are stopped, but then the "net" command displays an error message because we didn't return from the RPC call the way it expected us to."

    0 讨论(0)
  • 2020-12-07 10:30

    Check if a process instance of mongod is already running. If yes, this service will not start because C:\data\db\mongod.lock will be used by it.

    And to start MongoDB as a service, this file shall be not used by any process.

    0 讨论(0)
  • 2020-12-07 10:30

    Well, in my case, I was running low disk space on my drive where I have my MongoDB data files. I checked MongoDB logs file which stated the following

    2015-11-11T21:53:54.717+0500 E JOURNAL [initandlisten] Insufficient free space for journal files 2015-11-11T21:53:54.717+0500 I JOURNAL [initandlisten] Please make at least 3379MB available in C:\wamp\bin\mongodb\data\db\journal or use --smallfiles

    All I had to do is clean up some space and fire up the service again.. Worked for me. So All you have to is check your logs file and deal with the problem accordingly.

    0 讨论(0)
  • 2020-12-07 10:31

    If you did not specify absolute file paths for the data directory, or the log directory, you will get the same Windows error, but no log file.

    I used the information from "Install MongoDB Service on Windows 7", pushed on Webiyo to correct the registered service arguments:

    1. Download MongoDB and extract it to the C:\ drive.
    2. Add "data" and "logs" subdirectories under the "C:\mongodb165" directory.
    3. Add a log file name "mongolog.txt" at "C:\mongodb165\logs\mongolog.txt".
    4. Change the directory to "C:\mongodb165\bin".
    5. Execute the following command:

      mongod --install --rest –master –logpath=C:\mongodb165\logs\mongolog.txt
      
    6. Open the registry editor (regedit.exe), go to HKEY_LOCAL_MACHINE → SYSTEM → CurrentControlSet → Services.

    7. Find the MongoDB key and set the "ImagePath" value to:

      C:\mongodb165\bin\mongod --service  --rest  --master  --logpath=C:\mongodb165\logs\mongolog.txt  --dbpath=C:\mongodb165\data
      
    8. Save the changes to the registry and exit the registry editor.

    9. Open ComponentServices, click on "Services (Local)", and find the MongoDB service. Start it.
    10. Check at the URL http://localhost:28017/ to verify that MongoDB returns stats.
    0 讨论(0)
  • 2020-12-07 10:31

    Check if your mongod.cfg file has tabs in it. Removing tabs solved it for me!

    0 讨论(0)
提交回复
热议问题