你的位置:首页 > 数据库

[数据库]Mongodb 启动关闭脚本并设置开机自动启动Mongodb

配置文件内容:
[[email protected] etc]# cat mongod.conf
logpath=/export/log/mongodb.log
logappend=true
fork = true
dbpath=/export/data/db
pidfilepath = /export/mongodb/etc/mongodb.pid
rest = true
httpinterface = true
port = 27017


脚本如下:
[[email protected] ~]# cd /etc/init.d/

[[email protected] init.d]# vi mongod

#!/bin/bash


# mongod - Startup script for mongod


# chkconfig: 35 80 15
# description: Mongo is a scalable, document-oriented database.
# processname: mongod
#config: /export/mongodb/etc/mongod.conf
# pidfile: /export/mongodb/etc/mongodb.pid


source /etc/rc.d/init.d/functions


# things from mongod.conf get there by mongod reading it


if [ $(id -u) != "0" ]; then
echo "Permission Denied! Please use root to run again!"
exit 1
fi


test -d /export/mongodb || (mkdir -p /export/mongodb ; chown mongod:mongod /export/mongodb)


# NOTE: if you change any OPTIONS here, you get what you pay for:
# this script assumes all options are in the config file.
CONFIGFILE="/export/mongodb/etc/mongod.conf"
SYSCONFIG="/etc/sysconfig/mongod"


export PATH=$PATH:/export/mongodb/bin/


DBPATH=`awk -F= '/^dbpath/{print $2}' "$CONFIGFILE"`
OPTIONS=" --config $CONFIGFILE"
mongod=${MONGOD-/export/mongodb/bin/mongod}
echo "db path is: "$DBPATH
echo $mongod
MONGO_USER=mongodb
MONGO_GROUP=mongodb


[ -f "$SYSCONFIG" ] && source "$SYSCONFIG"


super() {
su - $MONGO_USER -c "PATH=$PATH:/export/mongodb/bin/; $*"
}


start()
{
echo -n $"Starting mongod: "
# echo -n "$MONGO_USER" "numactl --interleave=all"
# daemon --user "$MONGO_USER" "numactl --interleave=all" $mongod $OPTIONS
# daemon --user "$MONGO_USER" $mongod $OPTIONS
#
# su - $MONGO_USER -c "$mongod $OPTIONS" -m -p
# su - $MONGO_USER
# $mongod $OPTIONS
daemon --user "$MONGO_USER" "numactl --interleave=all" $mongod $OPTIONS
# super $mongod $OPTIONS
echo $mongod$OPTIONS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/mongod
}


stop()
{
echo -n $"Stopping mongod: "
killproc -p "$DBPATH"/mongod.lock -d 300 /export/mongodb/bin/mongod
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/mongod
}


restart () {
stop
start
}


ulimit -n 12000
RETVAL=0


case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload|force-reload)
restart
;;
condrestart)
[ -f /var/lock/subsys/mongod ] && restart || :
;;
status)
status $mongod
RETVAL=$?
;;
*)
echo "Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
RETVAL=1
esac


exit $RETVAL

==========================================
[[email protected] ~]# service mongod start

[[email protected] ~]# service mongod stop

===============================================
设置开机自动启动Mongodb
[[email protected] ~]# chkconfig --add mongod

[[email protected] ~]# chkconfig mongod on

[[email protected] ~]# chkconfig mongod --list
mongod 0:off 1:off 2:on 3:on 4:on 5:on 6:off


普吉岛旅游多少钱一人普吉岛游费用普吉岛旅游团购普吉岛蜜月旅游暑假去普吉岛旅游价格大连最具魅力海岛游推荐 雾霾时节 浙江省内洗肺地大盘点(组图) 心花路放电影取景地有哪些? 千古之美 小城正定处处皆国宝 日本旅游美食大收集 日本旅游美食攻略 日本旅游美食大全(图) 泰国曼谷如何去芭提雅绿山动物园? 三亚的海鲜有什么好吃的?三亚吃海鲜去哪里好? 桂林有哪些好吃的? 珠海圆明新园到斗门御温泉自驾游如何走? 在广州坐地铁贵吗?最高价钱是多少? 广州化妆品批发市场有什么地方? 深圳哪里有必胜客? 2015广州圣诞节情侣拍拖去哪好玩?广州圣诞夜约会哪里好? 2015广州圣诞节平安夜哪里有活动?广州圣诞节圣诞夜场去哪好玩? 三亚槟榔谷班车时间?槟榔谷班车几点发车? 2015圣诞节深圳动漫灯会活动在哪里?深圳欢乐海岸海洋馆圣诞好玩活动? AT84AS001TP-EB Datasheet AT84AS001TP-EB Datasheet AT84AS001VTPY Datasheet AT84AS001VTPY Datasheet AT84AS003CTP Datasheet AT84AS003CTP Datasheet 广州到潮州道韵楼旅游 广州到潮州道韵楼旅游 广州到潮州道韵楼旅游 广州到潮州东山湖温泉度假村旅游 广州到潮州东山湖温泉度假村旅游 广州到潮州东山湖温泉度假村旅游 广州到潮州鳄渡秋风旅游 广州到潮州鳄渡秋风旅游 广州到潮州鳄渡秋风旅游