如何设置MongoDB,使其可以作为Windows服务运行?
发布于 2010-03-13 22:58:00
我认为如果你用--install
命令行开关运行它,它会把它作为一个Windows Service来安装。
mongod --install
不过,首先阅读this thread可能是值得的。在写入相关注册表项时,相对/绝对路径似乎存在一些问题。
发布于 2016-03-19 20:21:26
我尝试了所有的答案,然后按照https://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/#configure-a-windows-service-for-mongodb-community-edition描述的方式做了。
使用配置文件...
"C:\mongodb\bin\mongod.exe" --config "C:\mongodb\mongod.cfg" --install
发布于 2013-04-24 20:19:32
此PowerShell脚本将MongoDB作为Windows Service下载并安装:
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
https://stackoverflow.com/questions/2438055
复制相似问题