MongoDB不会在Windows 7上作为服务运行

时间:2015-05-06 09:50:51

标签: mongodb

我遇到在Windows 7中运行MongoDB 3.0服务的问题。 我在data/db根目录中创建了data/logMongoDB并配置了mongod.conf文件:

被修改

# mongod.conf

# for documentation of all options, see:
#    http://docs.mongodb.org/manual/reference/configuration-options/

# where to write logging data.
systemLog:
    destination: file
    logAppend: true
    path: C:\Program Files\MongoDB\data\log\mongod.log

# Where and how to store data.
storage:
    dbPath: C:\Program Files\MongoDB\data\db
    journal: 
        enabled: true
#  engine:
#  mmapv1:
#  wiredTiger:

# how the process runs
processManagement:
    fork: true
    pidFilePath: C:\Program Files\MongoDB\mongod.pid

# network interfaces
# net:
#  port: 27017
#  bindIp: 127.0.0.1  # Listen to local interface only, comment to listen on all interfaces.


#security:

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options

#auditLog:

#snmp:

然后我创建了一个Windows服务,它将在启动时运行mongodb:

sc.exe create MongoDB binPath= "C:\MongoDB\bin\mongod.exe
 --service --config=C:\MongoDB\mongod.conf" displayname= "MongoDB 3.0 Standard"
start= "auto"

我也试过了:

sc.exe create MongoDB binPath= "\"C:\MongoDB\bin\mongod.exe\" --service --config=\"C:\MongoDB\mongod.conf\"" DisplayName= "MongoDB" start= "auto"

MongoDB服务属性显示可执行文件的路径:

C:\MongoDB\bin\mongod.exe --service --config=C:\MongoDB\mongod.conf

尝试运行服务(net start MongoDB)向我显示错误消息:

The service is not responding to the control function.
More help is available by typing NET HELPMSG 2186.

我知道这个问题很受欢迎,但大多数解决方案导致错误的路径,文件名/扩展名无法解决我的问题。

更新

建议在指定用户下创建Windows服务也没有帮助(在服务启动期间显示相同的消息):

C:\Users\Administrator>sc.exe create MongoDB binPath= "C:\MongoDB\bin\mongod.exe
 --service --config=C:\MongoDB\mongod.conf" displayname= "MongoDB 3.0 Standard"
start= "auto" obj= ".\Administrator" password= "@gdgsfg1"

此外,我尝试通过services.msc -> MongoDB -> Properties->Log on

指定用户名和密码

Windows事件日志:

Error   6.05.2015 19:54:25  Service Control Manager 7009    None
A timeout was reached (30000 milliseconds) while waiting for the MongoDB service to connect.

Error   6.05.2015 19:54:25  Service Control Manager 7000    None
The MongoDB service failed to start due to the following error: 
The service did not respond to the start or control request in a timely fashion.

1 个答案:

答案 0 :(得分:2)

我找到了为什么MongoDB服务没有成功启动的解决方案。

首先,通过这种方式安装windows mongodb服务,以便在服务安装期间查看YAML配置文件或其他任何类型的错误(sc.exe在mongodb服务期间没有提供足够的ifnormation安装):

mongod.exe --config "C:\Program Files\MongoDB\mongod.cfg" --install

实际上,我的问题是processManagement.fork选项在Windows中不存在,因为它会导致错误Unrecognized processManagement.fork option。所以,我已从配置文件中删除此选项,服务启动正常。

最终的配置文件:

systemLog:  
    destination: file  
    logAppend: true  
    path: C:\Program Files\MongoDB\data\log\mongod.log  
    timeStampFormat: iso8601-utc  

storage:  
    dbPath: C:\Program Files\MongoDB\data\db  
    journal:  
        enabled: true  

processManagement:
    pidFilePath: C:\Program Files\MongoDB\mongod.pid  

net:  
    port: 27017  
    bindIp: 127.0.0.1