无法将 MongoDB 作为服务启动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4661670/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot start MongoDB as a service
提问by Martin Reich
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 have executed to create the service:
我已经为 MongoDB 开发了几个月,并希望将它作为服务安装在我的 Windows 7 Enterprise 机器上。以下是我为创建服务而执行的命令:
"D:\Milvia Systems\Development\MongoDB\mongod.exe" --logpath "D:\Milvia Systems\Development\MongoDB\logs\DBLog.log" --logappend --dbpath "D:\Milvia Systems\Development\MongoDB\db" -vvv --reinstall
However, whenever I use net start "MongoDB" or the Service Control Panel I receive the following error:
但是,每当我使用 net start "MongoDB" 或服务控制面板时,我都会收到以下错误:
Error 1053: The service did not respond to the start or control request in a timely fashion.
错误 1053:服务没有及时响应启动或控制请求。
Environment: Windows 7 Enterprise 64bit MongoDB: 1.6.3 pdfile version 4.5
环境:Windows 7 Enterprise 64bit MongoDB:1.6.3 pdfile version 4.5
回答by Ciaran Archer
Have your checked you logging to see the real problem?
您是否检查过您的日志记录以查看真正的问题?
I suggest extracting the Mongo installation to c:\mongodb
.
我建议将 Mongo 安装解压到c:\mongodb
.
Create the c:\mongodb\logs
and the c:\mongodb\data\db
directories.
创建c:\mongodb\logs
和c:\mongodb\data\db
目录。
Then browse the the c:\mongodb\bin
directory and run the following to remove the service (if you've installed it!):
然后浏览c:\mongodb\bin
目录并运行以下命令以删除该服务(如果您已经安装了它!):
mongod --remove
Then install the service, specifying the log and data directories:
然后安装服务,指定日志和数据目录:
mongod --logpath c:\mongodb\logs\mongo.log --dbpath c:\mongodb\data\db --directoryperdb --install
Then if there is a problem starting the service you should see the reason in the specified log file.
然后,如果启动服务时出现问题,您应该会在指定的日志文件中看到原因。
More info here.
更多信息在这里。
回答by Stanley.Goldman
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.
如果您没有为数据目录或日志目录指定绝对文件路径,您将收到相同的 Windows 错误,但没有日志文件。
I used the information from "Install MongoDB Service on Windows 7", pushed on Webiyoto correct the registered service arguments:
我使用了“在 Windows 7 上安装 MongoDB 服务”中的信息,在 Webiyo上推送来更正注册的服务参数:
- Download MongoDB and extract it to the C:\ drive.
- Add "data" and "logs" subdirectories under the "C:\mongodb165" directory.
- Add a log file name "mongolog.txt" at "C:\mongodb165\logs\mongolog.txt".
- Change the directory to "C:\mongodb165\bin".
Execute the following command:
mongod --install --rest –master –logpath=C:\mongodb165\logs\mongolog.txt
Open the registry editor (regedit.exe), go to HKEY_LOCAL_MACHINE → SYSTEM → CurrentControlSet → Services.
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
Save the changes to the registry and exit the registry editor.
- Open ComponentServices, click on "Services (Local)", and find the MongoDB service. Start it.
- Check at the URL http://localhost:28017/to verify that MongoDB returns stats.
- 下载 MongoDB 并将其解压缩到 C:\ 驱动器。
- 在“C:\mongodb165”目录下添加“data”和“logs”子目录。
- 在“C:\mongodb165\logs\mongolog.txt”处添加日志文件名“mongolog.txt”。
- 将目录更改为“C:\mongodb165\bin”。
执行以下命令:
mongod --install --rest –master –logpath=C:\mongodb165\logs\mongolog.txt
打开注册表编辑器(regedit.exe),进入 HKEY_LOCAL_MACHINE → SYSTEM → CurrentControlSet → Services。
找到 MongoDB 键并将“ImagePath”值设置为:
C:\mongodb165\bin\mongod --service --rest --master --logpath=C:\mongodb165\logs\mongolog.txt --dbpath=C:\mongodb165\data
将更改保存到注册表并退出注册表编辑器。
- 打开ComponentServices,点击“Services (Local)”,找到MongoDB服务。启动它。
- 检查 URL http://localhost:28017/以验证 MongoDB 是否返回统计信息。
回答by Donald Gary
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 Webiyolink 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:
我刚刚在我的 Windows 7 机器上遇到了同样的问题。我按照 MongoDBs Docs 中的说明进行安装,但除非我在“C:\”中,否则它不会让我执行“net start MongoDB”。我不想返回并重新安装 MongoDB 以按照上面引用的 Webiyo链接中包含的说明进行操作。如果您已经根据他们的文档安装了 MongoDB 并且希望能够从您的项目目录所在的位置执行“net start MongoDB”:
Go to HKEY_LOCAL_MACHINE > SYSTEM > CurrentControlSet > services > MongoDB
转到 HKEY_LOCAL_MACHINE > SYSTEM > CurrentControlSet > services > MongoDB
Double click ImagePath under the Name column
双击名称列下的 ImagePath
Paste in the following ImagePath ( edit the folder directory and names to match your needs ):
粘贴以下 ImagePath(编辑文件夹目录和名称以满足您的需要):
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
请注意,如果您直接复制此 ImagePath 值并且您的“data”文件夹位于 mongodb 目录而不是 C:\ 中,请将以下行添加到您的“mongod.cfg”文件中: 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.
执行此操作后,当我运行“net stop MongoDB”时,我收到消息“发生系统错误 109。管道已结束。” 你也可能会看到。此消息已在jira.mongodb.org上进行了彻底讨论。
To save you the time of reading the whole back and forth discussion, Tad Marshalls post sums up this issue:
为了节省您阅读整个来回讨论的时间,Tad Marshalls 的帖子总结了这个问题:
"... it was working fine in 2.1.0; later changes broke it again. But yes, you get this error message in the current code.
“...它在 2.1.0 中运行良好;后来的更改再次破坏了它。但是,您在当前代码中收到此错误消息。
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.
解释是 mongod.exe 正在退出由 Windows 服务控制管理器创建的回调线程,当它由于“net stop mongodb”而调用我们时,这会破坏它用于创建回调线程的 RPC 管道。我们需要重新组织我们的退出逻辑以避免这样做。
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."
错误消息是此问题的唯一实际影响;我们完全按照命令退出,并通知 Windows 服务控制管理器我们已停止,但随后“net”命令显示一条错误消息,因为我们没有按照预期的方式从 RPC 调用返回。”
回答by Chen
To others who may have the same problem on Windows Server 2012:
对于在 Windows Server 2012 上可能遇到相同问题的其他人:
I have just got the same problem with Mongo 3.0.3 on Windows Server 2012. I am not a system admin so I don't know what they have changed for sc.exe. I have to use
我刚刚在 Windows Server 2012 上使用 Mongo 3.0.3 遇到了同样的问题。我不是系统管理员,所以我不知道他们对 sc.exe 做了什么更改。我必须使用
sc.exe create MongoDB binPath= "C:\mongodb\bin\mongod.exe --service --config=C:\mongodb\mongod.cfg" DisplayName= "MongoDB" start= "auto"
This is without the \"\" for both binary and config file paths comparing to the one on their website.
与他们网站上的路径相比,二进制和配置文件路径都没有 \"\" 。
回答by Irshad Khan
I ran this command:
我运行了这个命令:
C:\MongoDB\Server.4\bin>net start MongoDB
And got this message:
并收到此消息:
The service is not responding to the control function. More help is available by typing NET HELPMSG 2186.
服务未响应控制功能。通过键入 NET HELPMSG 2186 可以获得更多帮助。
After some trials and errors, I noticed when following the tutorial it asked me to name my file mongod.confbut the command was trying to refer to mongod.cfg.
经过一些试验和错误后,我注意到在遵循教程时它要求我命名我的文件mongod.conf但该命令试图引用mongod.cfg。
As soon as I corrected that name and re-run the commands,
一旦我更正了该名称并重新运行命令,
C:\MongoDB\Server.4\bin>sc.exe delete MongoDB
[SC] DeleteService SUCCESS
C:\MongoDB\Server.4\bin>sc.exe create MongoDB binPath= "\"C:\MongoDB\Server.4\bin\mongod.exe\" --service --config=\"C:\MongoDB\Server.4\mongod.cfg\"" DisplayName= "MongoDB" start= "auto"
[SC] CreateService SUCCESS
C:\MongoDB\Server.4\bin>net start MongoDB
The MongoDB service is starting....
The MongoDB service was started successfully.
The service started running fine.
该服务开始运行良好。
回答by JL_SO
My mongod.cfg file had the following last two lines:
我的 mongod.cfg 文件有以下最后两行:
#snmp:
mp:
I have no idea why there's an mp: in there. But when I manually executed the image path
我不知道为什么那里有一个 mp: 。但是当我手动执行图像路径时
C:\mongodb\bin\mongod.exe --config "C:\mongodb\bin\mongod.cfg" --service
at
在
Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MongoDB
I got
我有
c:\mongodb\bin>mongod /?C:\mongodb\bin\mongod.exe --config "C:\mongodb\bin\mongod.cfg" --service
Unrecognized option: mp
try 'mongod --help' for more information
So I commented it out and then the service started without any problem.
所以我将其注释掉,然后服务开始没有任何问题。
回答by Sana Jahan
These are the steps I followed to install mongoDB on windows 7
这些是我在 Windows 7 上安装 mongoDB 所遵循的步骤
download the .msi file from the mongodb site--> https://www.mongodb.com/download-center?jmp=nav#communityand run it
Wherever your mondoDb is downloaded (generally in the c drive Program Files folder), go to that folder and wherever is the bin folder in that same folder create your data folderand your log folder
从 mongodb 站点下载 .msi 文件--> https://www.mongodb.com/download-center?jmp=nav#community并运行它
无论您的 mondoDb 下载到何处(通常在 c 驱动器 Program Files 文件夹中),请转到该文件夹,并且同一文件夹中的 bin 文件夹在何处创建您的数据文件夹和日志文件夹
3.Inside your data folder create your db folder
3.Inside你的数据文件夹创建你的db文件夹
The structure would look something like this
Now open command prompt as administrator.
change your file path and enter the bin folder.( in this case it would be c>program files>MongoDB>bin> )
Type in the following command : mongod --directoryperdb --dbpath "C:/Program Files\MongoDB\data" --logpath "C:\Program Files\MongoDB\log\mongo.log" --logappend --rest --install
This would set the logpath and database path. Lastly run net start MongoDB. Hope this helps.
现在以管理员身份打开命令提示符。
更改文件路径并进入 bin 文件夹。(在本例中为 c>program files>MongoDB>bin> )
输入以下命令:mongod --directoryperdb --dbpath "C:/Program Files\MongoDB\data" --logpath "C:\Program Files\MongoDB\log\mongo.log" --logappend --rest --安装
这将设置日志路径和数据库路径。最后运行net start MongoDB。希望这可以帮助。
回答by Sumeet
Following works with MongoDB 3.6.0
以下适用于 MongoDB 3.6.0
Make sure you have these folders:
确保您有以下文件夹:
- C:\mongodb\data
- C:\mongodb\data\db
- C:\mongodb\数据
- C:\mongodb\data\db
Then all you need are these commands:
那么你只需要这些命令:
- mongod --directoryperdb -dbpath C:\mongodb\data\db --logpath C:\mongodb\log\mongo.log --logappend --service --install
- net start MongoDB
- mongo
- mongod --directoryperdb -dbpath C:\mongodb\data\db --logpath C:\mongodb\log\mongo.log --logappend --service --install
- 网络启动MongoDB
- 蒙戈
回答by user2305729
Check if your mongod.cfg file has tabs in it. Removing tabs solved it for me!
检查您的 mongod.cfg 文件中是否有标签。删除标签为我解决了它!
回答by codin
For mongoDB 3.0, You will have to set the following in the config file.
对于mongoDB 3.0,您必须在配置文件中设置以下内容。
logpath=E:\mongoDBdata\log\mongoDB.log
dbpath=E:\mongoDBdata\db
the logpath should end with a file and not a folder.
日志路径应该以文件而不是文件夹结尾。