在Windows Server 2012(或者2016上)安装了MongoDB 3.6,运行mongod.exe没有问题。
MongoDB 3.6的安装路径为D:\MongoDB\Server\3.6,创建了数据目录D:\data\db,日志目录D:\MongoDB\Server\logs,并在D:\MongoDB\Server\3.6下创建了配置文件mongod.cfg,内容如下:
systemLog:
destination: "file"
path:"D:\\MongoDB\\logs\\log.txt"
storage:
dbPath: "D:\\data\\db"
net:
bindIpAll: true
replication:
replSetName: rs0
然后,使用sc命令创建Windows服务:
D:\>sc.exe create MongoDB binPath="\"D:\MongoDB\Server\3.6\bin\mongod.exe\" --service --config=\"D:\MongoDB\Server\3.6\mongod.cfg\"" DisplayName= "MongoDB" start= "auto"
[SC] CreateService SUCCESS
启动服务时报错:
D:\>net start MongoDB
The service is not responding to the control function.
More help is available by typing NET HELPMSG 2186.
请教,可能是哪里的配置问题?
大概知道问题出在哪里了。
仔细阅读了MongoDB的官方文档。文中提到:
sc.exe requires a space between “ = ” and the configuration values (i.e. binPath= `` )
所以,
sc.exe create MongoDB binPath="\"D:MongoDBServer3.6binmongod.exe\" --service --config=\"D:MongoDBServer3.6mongod.cfg\"" DisplayName="MongoDB" start= "auto"
应该写成
sc.exe create MongoDB binPath= "\"D:MongoDBServer3.6binmongod.exe\" --service --config=\"D:MongoDBServer3.6mongod.cfg\"" DisplayName= "MongoDB" start= "auto"
在bindPath=后面以及DisplayName=后面添加一个空格。
回头继续做测试!
收起