Mac设置mongodb开机启动

2020-05-09  本文已影响0人  我是哈斯

1、配置开机启动

确保终端运行 mongod -f mongodb.conf 可正常启动

创建一个plist文件
在/Library/LaunchDaemons目录下

    sudo vi mongodb.plist
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"[http://www.apple.com/DTDs/PropertyList-1.0.dtd](http://www.apple.com/DTDs/PropertyList-1.0.dtd)" >
<plist version='1.0'>
<dict>
<key>Label</key>
<string>mongodb</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/mongodb/bin/mongod</string>
<string>run</string>
<string>--config</string>
<string>/usr/local/mongodb/bin/mongodb.conf</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>WorkingDirectory</key>
<string>/usr/local/mongodb</string>
<key>StandardErrorPath</key>
<string>/usr/local/mongodb/log/error.log</string>
<key>StandardOutPath</key>
<string>/usr/local/mongodb/log/output.log</string>
</dict>
</plist>

放置在/Library/LaunchDaemons目录下,如果不在这个目录,就放到对应正确路径下

执行命令,将mongo服务加入开机启动进程中

启动服务

    sudo launchctl load -w /Library/LaunchDaemons/mongodb.plist

关闭服务

    sudo launchctl unload -w /Library/LaunchDaemons/mongodb.plist
上一篇下一篇

猜你喜欢

热点阅读