在/etc/init.d/下建立一个mongod的初始化启动文件
$ touch mongod
$ chmod 777 mongod
$ vim mongod
#!/bin/sh
#chkconfig: 2345 80 90
#description: mongodb
start() {
/home/mongodb/bin/mongod --config /home/mongodb/mongodb.conf &
}
stop() {
/home/mongodb/bin/mongod --config /home/mongodb/mongodb.conf --shutdown
}
case "$1" in
start)
start
echo "mongod start"
;;
stop)
stop
echo "mongod stop"
;;
restart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
添加服务
$ chkconfig --add mongod
$ chkconfig mongod on
$ service mongod start