如何设置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是否打开。
其他回答
对于2.4.3版本(发布日期的当前版本),创建一个配置文件,然后执行以下命令:
C:\MongoDB\bin\mongo .exe——config C:\MongoDB\mongo .cfg——service
经过几个小时的努力,我终于做到了。
确保:
您将<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
以管理员身份运行“cmd.exe”,然后运行“sc.exe”,添加一个新的Windows服务。
例如:
sc.exe create MongoDB binPath= "c:\program files\mongodb\server\3.2\bin\mongod.exe"
这个答案是为那些已经使用MSI安装mongo DB的人准备的。
假设您的默认安装位置是“C:\Program Files\MongoDB\Server\3.2\bin”
运行mongo作为窗口服务的步骤
以管理员身份打开命令提示符 输入cd C:\Program Files\MongoDB\Server\3.2\bin(请正确检查路径,因为您可能安装了不同的版本,而不是3.2)。 按回车键 Type net start MongoDB 按回车键 按Windows + R,输入services。检查Mongo是否作为服务运行。
MongoDB 3.4 [Windows]
Create dir C:/mongodb/data Create a file in C:/mongodb/mongodb.config using this configuration: storage: engine: wiredTiger dbPath: "C:/mongodb/data" directoryPerDB: true journal: enabled: true systemLog: destination: file path: "C:/mongodb/data/mongod.log" logAppend: true timeStampFormat: iso8601-utc net: bindIp: 127.0.0.1 port: 27017 wireObjectCheck : false To install MongoDb as a service, run this command in powershell with admin power mongod --config="C:\mongodb\mongodb.config" --install --service Open Services.msc and look for MongoDb, then start it
推荐文章
- elasticsearch vs . MongoDB用于过滤应用程序
- MongoDB记录所有查询
- MongoDB:如何找到安装的MongoDB的确切版本
- 如何使用mongoimport导入CSV文件?
- 在mongodb中存储日期/时间的最佳方法
- 如何排序mongodb与pymongo
- 如何在mongodb上导入。bson文件格式
- JSON文件的蒙古导入
- 如何删除mongodb中的数组元素?
- 修改MongoDB数据存储目录
- 在MongoDB中查找重复的记录
- 为什么MongoDB Java驱动在条件中使用随机数生成器?
- 在猫鼬,我如何排序的日期?(node . js)
- 将映像存储在MongoDB数据库中
- 重复Mongo ObjectId的可能性在两个不同的集合中生成?