如何设置MongoDB,使其可以作为Windows服务运行?
当前回答
对于2.4.3版本(发布日期的当前版本),创建一个配置文件,然后执行以下命令:
C:\MongoDB\bin\mongo .exe——config C:\MongoDB\mongo .cfg——service
其他回答
如果您使用从管理员命令提示符下载的MSI安装MongoDB 2.6.1或更新版本,则会自动为您创建服务定义。
MongoDB文档也有一个教程,如果需要,可以帮助您手动创建Windows服务定义。
以管理员身份运行“cmd.exe”,然后运行“sc.exe”,添加一个新的Windows服务。
例如:
sc.exe create MongoDB binPath= "c:\program files\mongodb\server\3.2\bin\mongod.exe"
check windows services if you have service for mongo remove it by run bellow command mongod --remove create mongo.cfg file with bellow content systemLog: destination: file path: c:\data\log\mongod.log storage: dbPath: c:\data\db path: where you want to store log datas dbPath: your database directory then run bellow command sc.exe create MongoDB binPath= "\"C:\Program Files\MongoDB\Server\3.2\bin\mongod.exe\" --service --config=\"C:\Program Files\MongoDB\Server\3.2\mongod.cfg\"" DisplayName= "MongoDB" start= "auto" binPath : mongodb installation directory config: .cfg file address DisplayName:Your Service Name start service net start MongoDB
现在一切都办好了。享受,
您可以使用下面的命令将mongodb作为windows服务运行
"C:\mongodb\bin\mongod" --bind_ip yourIPadress --logpath "C:\data\dbConf\mongodb.log" --logappend --dbpath "C:\data\db" --port yourPortNumber --serviceName "YourServiceName" --serviceDisplayName "YourServiceName" --install
如果你使用mongodb默认参数,你可以使用这些值:
youripaddress: 127.0.0.1或localhost 你的portnumber: 27017(默认端口)或不放——port serviceDisplayName:仅当你运行多个服务时(从mongodb 1.8开始)
这里有关于这个命令的更多信息
http://www.mongodb.org/display/DOCS/Windows+Service
推荐的mongod——install方法会导致错误:
2015-12-03T18:18:28.896+0100 I CONTROL --install has to be used with a log file for server output
在C:\mongodb中安装mongodb后,您需要简单地添加日志路径:
mongod --install --logpath C:\mongodb\logs\mongo.log
日志文件的路径必须存在,并且必须是Windows的绝对路径。然后你通过输入启动MongoDB服务:
net start MongoDB
推荐文章
- elasticsearch vs . MongoDB用于过滤应用程序
- MongoDB记录所有查询
- MongoDB:如何找到安装的MongoDB的确切版本
- 如何使用mongoimport导入CSV文件?
- 在mongodb中存储日期/时间的最佳方法
- 如何排序mongodb与pymongo
- 如何在mongodb上导入。bson文件格式
- JSON文件的蒙古导入
- 如何删除mongodb中的数组元素?
- 修改MongoDB数据存储目录
- 在MongoDB中查找重复的记录
- 为什么MongoDB Java驱动在条件中使用随机数生成器?
- 在猫鼬,我如何排序的日期?(node . js)
- 将映像存储在MongoDB数据库中
- 重复Mongo ObjectId的可能性在两个不同的集合中生成?