MongoDB安装与配置启动

1、下载安装包。mongodb-linux-x86_64-rhel62-3.6.3.tgz

2、解压。修改名字。

3、修改配置文件:

# mongodb.conf

#where to log
logpath=/eyuroot/mongodb/log/mongodb.log              

# fork and run in background
fork = true

#port = 27017

dbpath=/eyuroot/mongodb/data   

pidfilepath=/eyuroot/mongodb/mongodb.pid

4、启动脚本:

#!/bin/sh
#
# mongodb init file for starting up the MongoDB server
#
# chkconfig: - 20 80
# description: Starts and stops the MongDB daemon that handles all \
# database requests.

# Source function library.
. /etc/rc.d/init.d/functions

exec="/usr/bin/mongod"
prog="mongod"
logfile="/eyuroot/mongodb/log/mongodb.log"
options=" -f /etc/mongod.conf"

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

lockfile="/var/lock/subsys/mongod"

start() {
[ -x $exec ] || exit 5
echo -n $"Starting $prog: "
#daemon --user mongod "$exec --quiet $options run >> $logfile 2>&1 &"

daemon --user mongod "$exec --quiet $options run > /dev/null"
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}

stop() {
echo -n $"Stopping $prog: "
killproc $prog
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}

restart() {
stop
start
}

reload() {
restart
}

force_reload() {
restart
}

rh_status() {
# run checks to determine if the service is running or use generic status
status $prog
}

rh_status_q() {
rh_status >/dev/null 2>&1
}

case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
exit 2
esac
exit $?

5、如果有报错,请检查目录权限。

6、加入到开机启动中:

chkconfig --add mongod

chkconfig mongod on

posted @ 2018-03-20 16:57  叶落千尘  阅读(157)  评论(0编辑  收藏  举报