第一步:
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86\_64-debian81-3.2.10.tgz
第二步:
tar -zxvf mongodb-linux-x86_64-debian81-3.2.10.tgz -C /data/server && mv /data/server/mongodb-linux-x86_64-debian81-3.2.10 /data/server/mongodb
第三步:
mkdir -p /data/mongodb
第四步:
vim /etc/mongodb.conf
dbpath=/data/mongodb
master=true
logpath=/data/mongodb/mongodb.log
logappend=true
第五步:
cd /data/server/mongodb/bin
./mongod -f /etc/mongodb.conf &
ps -def | grep mongod
第六步:
自启动
vim /etc/init.d/mongodb
#!/bin/sh
### BEGIN INIT INFO
# Provides: mongod
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/stop
### END INIT INFO
# Source function library.
. /lib/lsb/init-functions
retval=0
pidfile=`ps -ef | grep 'mongod' | grep -v grep | awk '{print $2}'`
CONFIG="/etc/mongodb.conf"
PROGRAM="/data/server/mongodb/bin/mongod"
MONGOPID=`ps -ef | grep 'mongod' | grep -v grep | awk '{print $2}'`
test -x $PROGRAM || exit 0
case "$1" in
start)
ulimit -n 3000
log_begin_msg "Starting MongoDB server"
$PROGRAM -f $CONFIG &
log_end_msg 0
;;
stop)
log_begin_msg "Stopping MongoDB server"
if [ ! -z "$MONGOPID" ]; then
kill -15 $MONGOPID
fi
log_end_msg 0
;;
status)
;;
*)
log_success_msg "Usage: /etc/init.d/mongodb {start|stop|status}"
exit 1
esac
exit 0
保存文件并修改权限
chmod +x /etc/init.d/mongodb
注册开机脚本
update-rc.d mongodb defaults
参考: