如何设置MongoDB,使其可以作为Windows服务运行?
当前回答
不像其他答案。
在系统重启/重新启动时自动启动服务
MongoDB安装
窗户
(1)安装MongoDB
(2)添加bin到路径
(3)创建c:\data\db
(4)创建c:\data\log
(5)创建c:\data\mongo .cfg
systemLog:
destination: file
path: c:\data\log\mongod.log
storage:
dbPath: c:\data\db
(6)创建在重启时自动启动的服务。以管理员身份运行..
sc.exe create MongoDB binPath= "\"C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe\" --service --config=\"C:\data\mongod.cfg\"" DisplayName= "MongoDB" start= "auto"
(7)启动服务。以管理员身份运行..
net start MongoDB
重要:即使显示“MongoDB服务已成功启动”,它也可能失败
要再次检查打开的控制面板>服务,确保MongoDB服务的状态为“Running”
如果不是,检查C:\data\log\mongo .log中的日志文件,找出失败的原因并修复它
(不要通过控制面板>服务启动MongoDB,使用..net start MongoDB
(8)最后,重新启动你的机器,运行MongoDB,重新启动时它仍将运行
如果你想杀死它…
net stop MongoDB
sc.exe delete MongoDB
其他回答
下载并安装MongoDB作为Windows服务:
Set-ExecutionPolicy RemoteSigned
$mongoDbPath = "C:\MongoDB"
$mongoDbConfigPath = "$mongoDbPath\mongod.cfg"
$url = "http://downloads.mongodb.org/win32/mongodb-win32-x86_64-2008plus-2.4.9.zip"
$zipFile = "$mongoDbPath\mongo.zip"
$unzippedFolderContent ="$mongoDbPath\mongodb-win32-x86_64-2008plus-2.4.9"
if ((Test-Path -path $mongoDbPath) -eq $True)
{
write-host "Seems you already installed MongoDB"
exit
}
md $mongoDbPath
md "$mongoDbPath\log"
md "$mongoDbPath\data"
md "$mongoDbPath\data\db"
[System.IO.File]::AppendAllText("$mongoDbConfigPath", "dbpath=C:\MongoDB\data\db`r`n")
[System.IO.File]::AppendAllText("$mongoDbConfigPath", "logpath=C:\MongoDB\log\mongo.log`r`n")
[System.IO.File]::AppendAllText("$mongoDbConfigPath", "smallfiles=true`r`n")
[System.IO.File]::AppendAllText("$mongoDbConfigPath", "noprealloc=true`r`n")
$webClient = New-Object System.Net.WebClient
$webClient.DownloadFile($url,$zipFile)
$shellApp = New-Object -com shell.application
$destination = $shellApp.namespace($mongoDbPath)
$destination.Copyhere($shellApp.namespace($zipFile).items())
Copy-Item "$unzippedFolderContent\*" $mongoDbPath -recurse
Remove-Item $unzippedFolderContent -recurse -force
Remove-Item $zipFile -recurse -force
& $mongoDBPath\bin\mongod.exe --config $mongoDbConfigPath --install
& net start mongodb
如果您使用从管理员命令提示符下载的MSI安装MongoDB 2.6.1或更新版本,则会自动为您创建服务定义。
MongoDB文档也有一个教程,如果需要,可以帮助您手动创建Windows服务定义。
不像其他答案。
在系统重启/重新启动时自动启动服务
MongoDB安装
窗户
(1)安装MongoDB
(2)添加bin到路径
(3)创建c:\data\db
(4)创建c:\data\log
(5)创建c:\data\mongo .cfg
systemLog:
destination: file
path: c:\data\log\mongod.log
storage:
dbPath: c:\data\db
(6)创建在重启时自动启动的服务。以管理员身份运行..
sc.exe create MongoDB binPath= "\"C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe\" --service --config=\"C:\data\mongod.cfg\"" DisplayName= "MongoDB" start= "auto"
(7)启动服务。以管理员身份运行..
net start MongoDB
重要:即使显示“MongoDB服务已成功启动”,它也可能失败
要再次检查打开的控制面板>服务,确保MongoDB服务的状态为“Running”
如果不是,检查C:\data\log\mongo .log中的日志文件,找出失败的原因并修复它
(不要通过控制面板>服务启动MongoDB,使用..net start MongoDB
(8)最后,重新启动你的机器,运行MongoDB,重新启动时它仍将运行
如果你想杀死它…
net stop MongoDB
sc.exe delete MongoDB
正在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
推荐文章
- elasticsearch vs . MongoDB用于过滤应用程序
- MongoDB记录所有查询
- MongoDB:如何找到安装的MongoDB的确切版本
- 如何使用mongoimport导入CSV文件?
- 在mongodb中存储日期/时间的最佳方法
- 如何排序mongodb与pymongo
- 如何在mongodb上导入。bson文件格式
- JSON文件的蒙古导入
- 如何删除mongodb中的数组元素?
- 修改MongoDB数据存储目录
- 在MongoDB中查找重复的记录
- 为什么MongoDB Java驱动在条件中使用随机数生成器?
- 在猫鼬,我如何排序的日期?(node . js)
- 将映像存储在MongoDB数据库中
- 重复Mongo ObjectId的可能性在两个不同的集合中生成?