如何设置MongoDB,使其可以作为Windows服务运行?
当前回答
这个答案是为那些已经使用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是否作为服务运行。
其他回答
在我的例子中,我在mongo .exe旁边创建了mongo .cfg,其中包含以下内容。
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: D:\apps\MongoDB\Server\4.0\data
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: D:\apps\MongoDB\Server\4.0\log\mongod.log
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0
#processManagement:
#security:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options:
#auditLog:
#snmp:
然后运行这两个命令中的一个来创建服务。
D:\apps\MongoDB\Server\4.0\bin>mongod --config D:\apps\MongoDB\Server\4.0\bin\mongod.cfg --install
D:\apps\MongoDB\Server\4.0\bin>net stop mongodb
The MongoDB service is stopping.
The MongoDB service was stopped successfully.
D:\apps\MongoDB\Server\4.0\bin>mongod --remove
2019-04-10T09:39:29.305+0800 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2019-04-10T09:39:29.309+0800 I CONTROL [main] Trying to remove Windows service 'MongoDB'
2019-04-10T09:39:29.310+0800 I CONTROL [main] Service 'MongoDB' removed
D:\apps\MongoDB\Server\4.0\bin>
D:\apps\MongoDB\Server\4.0\bin>sc.exe create MongoDB binPath= "\"D:\apps\MongoDB\Server\4.0\bin\mongod.exe\" --service --config=\"D:\apps\MongoDB\Server\4.0\bin\mongod.cfg\""
[SC] CreateService SUCCESS
D:\apps\MongoDB\Server\4.0\bin>net start mongodb
The MongoDB service is starting..
The MongoDB service was started successfully.
D:\apps\MongoDB\Server\4.0\bin>
以下是不正确的,注意转义引号是必需的。
D:\apps\MongoDB\Server\4.0\bin>sc.exe create MongoDB binPath= "D:\apps\MongoDB\Server\4.0\bin\mongod --config D:\apps\MongoDB\Server\4.0\bin\mongod.cfg"
[SC] CreateService SUCCESS
D:\apps\MongoDB\Server\4.0\bin>net start mongodb
The service is not responding to the control function.
More help is available by typing NET HELPMSG 2186.
D:\apps\MongoDB\Server\4.0\bin>
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
现在一切都办好了。享受,
这个答案是为那些已经使用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是否作为服务运行。
不仅——安装,
还需要——dbpath和——logpath
重启操作系统后,你需要删除“mongod”。手动锁”
请尝试Mongo DB: 3.6和Windows 10中的步骤
mongod——删除 mongod——dbpath=C:/data/db——port 27017——logpath C:/data/log/log.txt——service . dbpath=C:/data/ log/log.txt mongod——dbpath=C:/data/db——port 27017——logpath C:/data/log/log.txt——install . sh net start MongoDB
推荐文章
- 无法连接到服务器127.0.0.1:27017
- 如何创建数据库的MongoDB转储?
- 如何将MongoDB作为Windows服务运行?
- 如何监听MongoDB集合的变化?
- 什么时候不使用Cassandra?
- 如何在猫鼬排序?
- BASE术语解释
- .msi和setup.exe文件之间的具体区别是什么?
- 映射一个网络驱动器供服务使用
- js的Mongoose.js字符串到ObjectId函数
- 如何从java应用程序创建一个windows服务
- mongodb中使用ISODate的日期查询似乎无法正常工作
- 如何更新文档数组中的对象(嵌套更新)
- 在猫鼬模式中添加created_at和updated_at字段
- 如何更新mongodb中的多个数组元素