[英]MongoDB: Setting up Windows Service
I have just installed MongoDB 2.6 and I am trying to run it as a Windows Service on Windows 8, by following the instructions at http://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/ . 我刚安装了MongoDB 2.6,并尝试按照http://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/上的说明在Windows 8上将其作为Windows服务运行。
Here's my directory structure within the C drive: 这是我在C盘中的目录结构:
MongoDB
(MongoDB installation) MongoDB
(MongoDB安装)
bin
Project
DB
Log
mongo.conf
mongod.cfg
The contents of mongo.conf
is: mongo.conf
的内容是:
storage:
dbPath: "C:\Project\DB"
And the contents of mongod.cfg
is: 而
mongod.cfg
的内容是:
logpath="C:\Project\Log\mongo.log"
As directed to in the tutorial, from the command line (in administrator mode) I then type: 按照教程中的指示,从命令行(在管理员模式下),然后键入:
"C:\\MongoDB\\bin\\mongod.exe" --config "C:\\Project\\mongod.cfg" --install
However, I get an error message: 但是,我收到一条错误消息:
SEVERE: Failed global initialization: FileNotOpen Failed to open ""C:\\MongoDB\\bin\\Project\\Log\\mongo.log""
Please can somebody explain what I'm doing wrong? 请问有人可以解释我做错了什么吗? I've followed the instructions as dictated in the tutorial (except changed some of the directory names).
我按照教程中的说明进行了操作(除了更改了一些目录名称)。
I'm also very confused as to the difference between mongo.conf
and mongod.cfg
... 我也很困惑
mongo.conf
和mongod.cfg
之间的区别......
Thanks! 谢谢!
I was having a similar problem with Mongo 2.6.3. 我和Mongo 2.6.3有类似的问题。 I was trying to set the log path to
C:\\Users\\Public\\Public Databases\\Mongo\\log\\mongo.log
and the service installer kept responding with Failed to open ""C:\\Program Files\\MongoDB 2.6 Standard\\bin\\Users\\Public\\Public Databases\\Mongo\\log\\mongo.log""
. 我试图将日志路径设置为
C:\\Users\\Public\\Public Databases\\Mongo\\log\\mongo.log
,服务安装程序保持响应, Failed to open ""C:\\Program Files\\MongoDB 2.6 Standard\\bin\\Users\\Public\\Public Databases\\Mongo\\log\\mongo.log""
。
It started working for me when I stopped quoting the log path in the config file. 当我停止引用配置文件中的日志路径时,它开始为我工作。 (ie I changed
logpath="C:\\Users\\Public\\Public Databases\\Mongo\\log\\mongo.log"
to logpath=C:\\Users\\Public\\Public Databases\\Mongo\\log\\mongo.log
). (即我将
logpath="C:\\Users\\Public\\Public Databases\\Mongo\\log\\mongo.log"
更改为logpath=C:\\Users\\Public\\Public Databases\\Mongo\\log\\mongo.log
)。
There is a known issue installing MongoDB 2.6.0 as a Windows service using the --install
command - see SERVER-13515 . 使用
--install
命令将MongoDB 2.6.0安装为Windows服务存在一个已知问题 - 请参阅SERVER-13515 。 A fix has been committed for the MongoDB 2.6.1 release. 已经为MongoDB 2.6.1版本提交了修复程序。
As a workaround, I've provided instructions on how to install the service manually on that SERVER issue. 作为解决方法,我已经提供了有关如何在该SERVER问题上手动安装服务的说明。
The short version is: 简短版本是:
create the service definition, similar to: 创建服务定义,类似于:
sc create MongoDB binPath= "\\"C:\\Program Files\\MongoDB 2.6 Standard\\bin\\mongod.exe\\" --service --config=\\"C:\\Program Files\\MongoDB 2.6 Standard\\mongod.cfg\\"" DisplayName= "MongoDB 2.6 Standard" start= "auto"
start the MongoDB service 启动MongoDB服务
net start MongoDB
For full instructions please refer to SERVER-13515 . 有关完整说明,请参阅SERVER-13515 。
I'm also very confused as to the difference between mongo.conf and mongod.cfg
我也很困惑mongo.conf和mongod.cfg之间的区别
The MongoDB server doesn't care about the name/extension of the file you specify with --config
(as long as the file can be read). MongoDB服务器不关心使用
--config
指定的文件的名称/扩展名(只要可以读取该文件)。 Your confusion on the format is because the mongo.conf
example uses the new YAML config file format supported by MongoDB 2.6+, while mongod.cfg
uses the older format supported by 2.6 as well as earlier versions. 您对格式的困惑是因为
mongo.conf
示例使用MongoDB 2.6+支持的新YAML配置文件格式 ,而mongod.cfg
使用2.6以及早期版本支持的旧格式。
I used the older mongod.cfg
format in my workaround example, as technically someone could adapt these instructions to manually create a service definition for MongoDB 2.4 as well. 我在我的解决方法示例中使用了较旧的
mongod.cfg
格式,因为技术上有人可以调整这些指令来手动为MongoDB 2.4创建服务定义。
I got the same problem not only when installing as a Windows service but also when running "mongodb.exe" file. 我不仅在安装Windows服务时,而且在运行“mongodb.exe”文件时遇到了同样的问题。 I tried to remove double quote (") characters but the error was still there:
我试图删除双引号(“)字符,但错误仍然存在:
2014-08-16T14:14:49.166Z SEVERE: Failed global initialization: FileNotOpen Failed to open "D:\\MongoDB\\log\\mongo.log" 2014-08-16T14:14:49.166Z严重:全局初始化失败:FileNotOpen无法打开“D:\\ MongoDB \\ log \\ mongo.log”
Please note that I was using config file in new YAML format. 请注意,我使用的是新的YAML格式的配置文件。 I had no problem when using the old format.
使用旧格式时我没有问题。 I tried several ways on the new YAML configuration file and finally I found that it doesn't accept the absolute path.
我在新的YAML配置文件上尝试了几种方法,最后我发现它不接受绝对路径。 Just change to relative path and it works like a charm!
只需改变相对路径,它就像一个魅力!
My folder structure is:
MongoDB\
bin\
data\
log\
Here is my YAML configuration file that works on the build MongoDB 2.6.4 - Windows 64 bit version, installed on my Windows 7 - Professional x64: 这是我的YAML配置文件,适用于我的Windows 7 - Professional x64上安装的构建MongoDB 2.6.4 - Windows 64位版本:
systemLog:
timeStampFormat: iso8601-utc
destination: file
path: ..\log\mongo.log
quiet: false
logAppend: true
net:
bindIp: 127.0.0.1
port: 27017
storage:
dbPath: ..\data
directoryPerDB: true
journal:
enabled: true
I tried a lot of things, in the end I had to remove config file and pass dbpath and logpath settings directly. 我尝试了很多东西,最后我不得不删除配置文件并直接传递dbpath和logpath设置。 Following command worked for me:-
以下命令对我有用: -
C:>mongod --dbpath d:\\mongodb\\data --logpath d:\\mongodb\\logs\\mongo.log --instal l --serviceName MongoDB --serviceDisplayName MongoDB C:> mongod --dbpath d:\\ mongodb \\ data --logpath d:\\ mongodb \\ logs \\ mongo.log --instal l --serviceName MongoDB --serviceDisplayName MongoDB
There is a JIRA on that topic for the last version of MongoDB and a workaround too. 对于MongoDB的最新版本,该主题有一个JIRA,也是一种解决方法。 A solution is to install a previous version then install the service ans re-use the last version of the driver.
解决方案是安装以前的版本然后安装服务并重新使用最新版本的驱动程序。 Hope this helps !
希望这可以帮助 !
@Stennie 's answer, as well as the manual service installation instructions on the mongoDB site were adequate for me. @Stennie的回答以及mongoDB网站上的手动服务安装说明对我来说已经足够了。 One thing to note though, is that the quoted items in the instructions need double backslashes (\\\\) in order to work correctly.
但需要注意的一点是,指令中的引用项需要双反斜杠(\\\\)才能正常工作。 Probably obvious to most developers, but I had it slip my mind, and the error response was simply that the service fails to start up.
对于大多数开发人员来说可能是显而易见的,但是让我感到不安,而错误响应只是服务无法启动。 Also, be wary of the spaces after the equals signs.
另外,要注意等号后面的空格。
sc.exe create MongoDB binPath= "\"C:\\Program Files\\MongoDB 2.6 Standard\\bin\\mongod.exe\" --service --config=\"C:\\Program Files\\MongoDB 2.6 Standard\\mongod.cfg\"" DisplayName= "MongoDB 2.6 Standard" start= "auto"
观察你的错误日志,它传递两个而不是一个。省略一个(编辑你的配置文件内容并删除“s”)你应该很好。
有时,当您遇到以下错误时:“全局初始化失败:FileNotOpen无法打开... / mongodb.log”,如果您有日志文件,则可以将其删除并重试。
Stop MongoDB from Windows Services
and then try again. 从
Windows Services
停止MongoDB,然后重试。 It worked for me! 它对我有用!
My previous logpath=c:\\programfiles\\......
the alternative is logpath="c:\\program files\\......"
it works 我之前的
logpath=c:\\programfiles\\......
替代方案是logpath="c:\\program files\\......"
它的工作原理
I think the reason is that the system must visit the log file through c:\\program files\\......
, but there comes error when I write logpath=c:\\program files\\......
because there is a space between program and files. 我认为原因是系统必须通过
c:\\program files\\......
访问日志文件,但是当我写logpath=c:\\program files\\......
时出现错误,因为那里是程序和文件之间的空间。 Then I add ""
, and it works. 然后我添加
""
,它的工作原理。 I hope it helps. 我希望它有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.