使用Homebrew安裝MongoDB
brew install mongodb
配置自動啟動
- 鏈接plist文件
ln -sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents
目錄/usr/local/opt/mongodb/是一個鏈接,指向 /usr/local/Cellar/mongodb/x.y.z x.y.z是版本號,例如:( 2.4.9)
- 通過launchctl來啟動和停止
mongod
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
- 你也可以使用命令
brew來啟動、停止和查看服務(wù)的狀態(tài)。
brew services list | grep mongodb
brew services start mongodb
brew services stop mongodb
請注意:
默認的plist文件指定的MongoDB配置文件是 /usr/local/etc/mongod.conf,
配置中dbpath為/usr/local/var/mongdb。