软件开发MongoDB

为MongoDB创建Windows服务后无法启动:The service is not responding to the control function?

在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:  ...显示全部

在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.

请教,可能是哪里的配置问题?

收起
参与2

返回waitfeiyn的回答

waitfeiynwaitfeiyn系统工程师某公司

大概知道问题出在哪里了。

仔细阅读了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=后面添加一个空格。

回头继续做测试!

软件开发 · 2020-01-21
浏览2720

回答者

waitfeiyn
系统工程师某公司
擅长领域: 云计算容器云Kubernetes

waitfeiyn 最近回答过的问题

回答状态

  • 发布时间:2020-01-21
  • 关注会员:1 人
  • 回答浏览:2720
  • X社区推广