在上一篇的文章《linux中的官网mongo的安装》已经完全可以启动mongo了。但是每一次都需要手动启动,或者手动关闭。为了将更好的方便管理,我们将mongo的添加到系统的服务中,作为服务。
(1)要作为一项服务,必须在linux的/etc/init.d/下建立一个mongod的初始化启动文件
$ touch mongod
$ chmod 777 mongod
$ vi mongod
里面的内容可以很简单:
#!/bin/bash
#chkconfig: 2345 80 90
#description: mongodb
start() {
/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/mongo
d.conf
}
stop() {
/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/
mongod.conf --shutdown
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo
$"Usage: $0 {start|stop|restart}"
exit 1
esac
保存退出。
(2)添加服务
$ chkconfig --add mongod
$ chkconfig mongod on
$ service mongod start
这样子就启动了。停止用命令service mongod st