在上一篇的文章《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 stop。
(3)添加环境变量。
为了方便进入到mongo的shell命令行环境,可以添加环境变量。
单独查看PATH环境变量,可用:
[root@localhost u-boot-sh4]#echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
添加PATH环境变量,可用:
[root@localhost u-boot-sh4]#exportPATH=/opt/STM/STLinux-2.3/devkit/sh4/bin:$PATH
再次查看:
[root@localhost u-boot-sh4]# echo $PATH
/opt/STM/STLinux-2.3/devkit/sh4/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
说明添加PATH成功。
不报错则成功。
建议用第二种方法。至此,直接输入mongo就可以进入到mongo的shell环境。