[root@hqw server]# vi /etc/init.d/mongodb
[root@hqw server]# chmod +x /etc/init.d/mongodb
[root@hqw server]# ./bin/mongo
MongoDB shell version: 1.8.2
connecting to: test
Sat Dec 13 10:56:32 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:79
exception: connect failed
[root@hqw server]# service mongodb start
Starting mongod: all output going to: /usr/local/mongodb/server/logs
[ OK ]
[root@hqw server]# ./bin/mongo
MongoDB shell version: 1.8.2
connecting to: test
> show dbs;
admin (empty)
local (empty)
> exit
bye
[root@hqw server]# service mongodb stop
Stopping mongod: [ OK ]
[root@hqw server]# /etc/init.d/mongodb start
Starting mongod: all output going to: /usr/local/mongodb/server/logs
[ OK ]
[root@hqw server]# ./bin/mongo
MongoDB shell version: 1.8.2
connecting to: test
> show dbs;
admin (empty)
local (empty)
> exit
bye
[root@hqw server]# cd bin
[root@hqw bin]# ls
bsondump mongo mongod mongodump mongoexport mongofiles mongoimport mongorestore mongos mongosniff mongostat
[root@hqw bin]# pwd
/usr/local/mongodb/server/bin
[root@hqw server]# chmod +x /etc/init.d/mongodb
[root@hqw server]# ./bin/mongo
MongoDB shell version: 1.8.2
connecting to: test
Sat Dec 13 10:56:32 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:79
exception: connect failed
[root@hqw server]# service mongodb start
Starting mongod: all output going to: /usr/local/mongodb/server/logs
[ OK ]
[root@hqw server]# ./bin/mongo
MongoDB shell version: 1.8.2
connecting to: test
> show dbs;
admin (empty)
local (empty)
> exit
bye
[root@hqw server]# service mongodb stop
Stopping mongod: [ OK ]
[root@hqw server]# /etc/init.d/mongodb start
Starting mongod: all output going to: /usr/local/mongodb/server/logs
[ OK ]
[root@hqw server]# ./bin/mongo
MongoDB shell version: 1.8.2
connecting to: test
> show dbs;
admin (empty)
local (empty)
> exit
bye
[root@hqw server]# cd bin
[root@hqw bin]# ls
bsondump mongo mongod mongodump mongoexport mongofiles mongoimport mongorestore mongos mongosniff mongostat
[root@hqw bin]# pwd
/usr/local/mongodb/server/bin
[root@hqw bin]#
启动脚本
#!/bin/sh
#
#mongod - Startup script for mongod
#
# chkconfig: - 85 15
# description: Mongodb database.
# processname: mongod
# Source function library
. /etc/rc.d/init.d/functions
# things from mongod.conf get there by mongod reading it
# OPTIONS
OPTIONS=" --dbpath=/usr/local/mongodb/server/data --logpath=/usr/local/mongodb/server/logs --logappend &"
#mongod
mongod="/usr/local/mongodb/server/bin/mongod"
lockfile=/var/lock/subsys/mongod
start()
{
echo -n $"Starting mongod: "
daemon $mongod $OPTIONS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch $lockfile
}
stop()
{
echo -n $"Stopping mongod: "
killproc $mongod -QUIT
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $lockfile
}
restart () {
stop
start
}
ulimit -n 12000
RETVAL=0
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload|force-reload)
restart
;;
condrestart)
[ -f $lockfile ] && restart || :
;;
status)
status $mongod
RETVAL=$?
;;
*)
echo "Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
RETVAL=1
esac
exit $RETVAL