如何设置MongoDB,使其可以作为Windows服务运行?
当前回答
正在mongodb DB: 3.6上工作
(1)安装MongoDB
(2)将bin添加到环境路径变量中
(3)创建c:\data\db
(4)创建c:\data\mongo .log
(5)在bin文件夹上执行以下命令
.\mongo .exe——install——logpath c:\data\mongo .log——logappend ——bind_ip 12 7.0.0.1——dbpath c:\data\db
(6)启动mongodb作为服务
net start MongoDB
(7)最后在命令行中运行mongo,检查mongo shell是否打开。
其他回答
以下是安装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
经过几个小时的努力,我终于做到了。
确保:
您将<MONGODB_PATH>\bin目录添加到系统变量PATH中 以管理员身份运行命令提示符
步骤:
第一步:执行以下命令:
D:\mongodb\bin>mongod --remove
第二步:以管理员身份打开命令提示符后执行该命令:
D:\mongodb\bin>mongod --dbpath=D:\mongodb --logpath=D:\mongodb\log.txt --install
注意:你也可以在上面的命令后面附加——serviceName MongoDB。
这是所有!
After that right there in the command prompt execute:
services.msc
// OR
net start MongoDB
寻找MongoDB service并单击start。
注意:确保以管理员身份运行命令提示符。
如果你不这样做,你的日志文件(在上面的例子中是D:\mongodb\log.txt)将包含这样的行:
2016-11-11T15:24:54.618-0800 I CONTROL [main] Trying to install Windows service 'MongoDB'
2016-11-11T15:24:54.618-0800 I CONTROL [main] Error connecting to the Service Control Manager: Access is denied. (5)
如果你试图从非管理控制台启动服务(即net start MongoDB或start - service MongoDB在PowerShell中),你会得到这样的响应:
System error 5 has occurred.
Access is denied.
或:
Start-Service : Service 'MongoDB (MongoDB)' cannot be started due to the following error: Cannot open MongoDB service
on computer '.'.
At line:1 char:1
+ Start-Service MongoDB
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (System.ServiceProcess.ServiceController:ServiceController) [Start-Service],
ServiceCommandException
+ FullyQualifiedErrorId : CouldNotStartService,Microsoft.PowerShell.Commands.StartServiceComman
最简单的方法是,
创建文件夹C:\data\db 创建文件C:\data\db\log.txt 以“以管理员身份运行”打开命令提示符,确认mogodb bin目录路径正确并写入 C:\Program Files\MongoDB\Server\3.4\ bin> mongod.exe——install mongod——dbpath="c:\data\db"——logpath="c:\data\db\log.txt" 启动mongodb服务: net run MongoDB
我使用的是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时,服务将显示启动,但它将终止。检查日志文件以确认服务已经真正启动。
不仅——安装,
还需要——dbpath和——logpath
重启操作系统后,你需要删除“mongod”。手动锁”
推荐文章
- elasticsearch vs . MongoDB用于过滤应用程序
- MongoDB记录所有查询
- MongoDB:如何找到安装的MongoDB的确切版本
- 如何使用mongoimport导入CSV文件?
- 在mongodb中存储日期/时间的最佳方法
- 如何排序mongodb与pymongo
- 如何在mongodb上导入。bson文件格式
- JSON文件的蒙古导入
- 如何删除mongodb中的数组元素?
- 修改MongoDB数据存储目录
- 在MongoDB中查找重复的记录
- 为什么MongoDB Java驱动在条件中使用随机数生成器?
- 在猫鼬,我如何排序的日期?(node . js)
- 将映像存储在MongoDB数据库中
- 重复Mongo ObjectId的可能性在两个不同的集合中生成?