MongoDB 有什么办法可以让 MongoDB 在 Mac OS X 下开机启动

sihaiyunyou · 2011年11月24日 · 最后由 Guest 回复于 2013年08月23日 · 20315 次阅读

就像在 linux 下在/etc/init.d/下面放置一个脚本文件,设为开机自启动一样,mac 有没有类似的方式呢,据我所知,mac 是没有 win 的 service 这个概念的

用 Homebrew 安装

brew install mongodb
# 安装完成后会有一段提示,执行提示那几个命令就可以了

就是这段信息:

brew info mongodb

MongoDb 用 Homebrew 安装好以后会这么一段

➜  ~  brew install mongodb
mongodb 2.0.0-x86_64
http://www.mongodb.org/
/usr/local/Cellar/mongodb/2.0.0-x86_64 (17 files, 120M)

If this is your first install, automatically load on login with (这段就是用来设置 MongoDB for Mac 的服务的,会开机自启动):
    mkdir -p ~/Library/LaunchAgents
    cp /usr/local/Cellar/mongodb/2.0.0-x86_64/org.mongodb.mongod.plist ~/Library/LaunchAgents/
    launchctl load -w ~/Library/LaunchAgents/org.mongodb.mongod.plist

If this is an upgrade and you already have the org.mongodb.mongod.plist loaded:
    launchctl unload -w ~/Library/LaunchAgents/org.mongodb.mongod.plist
    cp /usr/local/Cellar/mongodb/2.0.0-x86_64/org.mongodb.mongod.plist ~/Library/LaunchAgents/
    launchctl load -w ~/Library/LaunchAgents/org.mongodb.mongod.plist

Or start it manually:
    mongod run --config /usr/local/Cellar/mongodb/2.0.0-x86_64/mongod.conf
MongoDB 1.8+ includes a feature for Write Ahead Logging (Journaling), which has been enabled by default.
To disable journaling, use --nojournal.

http://github.com/mxcl/homebrew/commits/master/Library/Formula/mongodb.rb

O 了,谢谢老大,最好再给来一个 redis-server 开机启动的,扫扫盲,嘿嘿。。

Redis 和 MongoDB 是同样的,Homebrew 这个神器可以搞定!

记住了,Homebrew 是个神器。

是的,建议 mac 用户都用这个东东。太方便了

#2 楼 @lgn21st 这里 brew info mongodb 显示的是最新 mongodb 的信息吗?因为 我去我的/usr/local/Cellar/mongodb 文件夹看,发现版本有两个 2.0.5-x86_64 和 2.0.6-x86_64,但是 brew info mongodb 出来的结果是 2.0.7-x86_64。

#8 楼 @sundevilyang 是最新的 mongodb 信息。 你在/usr/local/Cellar/mongodb里面看到两个老版本的 Mongodb,说明你先后安装了两个 Mongodb,而这两个都不是最新版。你可以用下面几个命令升级并清理掉旧版本。

# 升级brew的版本库
brew update

# 查看outdated的库和应用
brew outdated

# 升级outdated的库和应用
brew upgrade

# 清理调过期的库和应用
brew cleanup

在 MacOSX 下可以用 launchctl 来管理这些服务。

12 楼 已删除
需要 登录 后方可回复, 如果你还没有账号请 注册新账号