如何设置MongoDB,使其可以作为Windows服务运行?
当前回答
不仅——安装,
还需要——dbpath和——logpath
重启操作系统后,你需要删除“mongod”。手动锁”
其他回答
以下是安装MongoDB as Windows Service的步骤:
Create a log directory, e.g. C:\MongoDB\log Create a db directory, e.g. C:\MongoDB\db Prepare a configuration file with following lines dbpath=C:\MongoDB\db logpath=C:\MongoDB\log Place the configuration file with name mongod.cfg in folder "C:\MongoDB\" Following command will install the Windows Service on your sc.exe create MongoDB binPath= "\"C:\MongoDB\Server\3.4\bin\mongod.exe\" --service --config=\"C:\MongoDB\mongod.cfg\" DisplayName= "MongoDB 3.4" start= "auto" Once you run this command, you will get the [SC] CreateService SUCCESS Run following command on Command Prompt net start MongoDB
这是唯一对我有用的方法。因为所有东西都必须是绝对路径:
C:\Program Files\MongoDB\Server\3.2\bin>mongod --install --dbpath=c:/data/db --logpath=c:/data/logs/log.txt
我还必须从管理cmd运行它
我使用的是2.4.9版本,并使用配置文件。直到我在配置文件中用空格包围了等号,服务才会启动:
dbpath = D:\Mongo data
logpath = C:\mongodb\logs\mongo.log
logappend = true
原来我有:
logpath=C:\mongodb\logs\mongo.log
我还发现,当安装服务时,你必须使用配置文件的绝对路径,例如:
c:\mongodb\bin\>mongodb.exe C:\mongodb\bin\mongod.conf --install
不要尝试在dbpath周围使用带有空格的倒逗号。当您执行net start MongoDB时,服务将显示启动,但它将终止。检查日志文件以确认服务已经真正启动。
目前(直到2.4.4版本),如果任何路径(dbpath/logpath/config)包含空格,那么服务将不会启动,并显示错误:“服务没有响应控制功能”。
以管理员身份运行“cmd.exe”,然后运行“sc.exe”,添加一个新的Windows服务。
例如:
sc.exe create MongoDB binPath= "c:\program files\mongodb\server\3.2\bin\mongod.exe"
推荐文章
- 如何排序mongodb与pymongo
- 如何在mongodb上导入。bson文件格式
- JSON文件的蒙古导入
- 如何删除mongodb中的数组元素?
- 修改MongoDB数据存储目录
- 在MongoDB中查找重复的记录
- 为什么MongoDB Java驱动在条件中使用随机数生成器?
- 在猫鼬,我如何排序的日期?(node . js)
- 将映像存储在MongoDB数据库中
- 重复Mongo ObjectId的可能性在两个不同的集合中生成?
- Redis比mongoDB快多少?
- 亚马逊SimpleDB vs亚马逊DynamoDB
- 无法连接到服务器127.0.0.1:27017
- 如何创建数据库的MongoDB转储?
- 如何将MongoDB作为Windows服务运行?