basic download and exact and mkdir
cd /usr/local/src
download mongodb-linux-x86_64-3.0.6.tgz
tar xzvf mongodb-linux-x86_64-3.0.6.tgz
mv ./mongodb-linux-x86_64-3.0.6 ../
ln -s /usr/local/mongodb-linux-x86_64-3.0.6 /usr/local/mongodb
mkdir -p /data/mongodb/log
mkdir -p /data/mongodb/db
init file
#!/bin/bash
#
# Startup script for the mongodb server.
#
# chkconfig: 345 85 15
# description: mongodb
# processname: mongodb
# config: None
# Source function library.
. /etc/rc.d/init.d/functions
# for para
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo 'never' > /sys/kernel/mm/transparent_hugepage/enabled
echo 'never' > /sys/kernel/mm/transparent_hugepage/defrag
ulimit -n 600000
ulimit -u 300000
DESC="mongodb"
NAME="mongodb"
export PATH=/usr/local/mongodb/bin:/usr/local/java/bin:/usr/local/java/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin
DAEMON="/usr/local/mongodb/bin/mongod"
# 配置文件路径
#CONFIGFILE=/etc/php-fpm.conf
PIDFILE="/var/run/$NAME.pid"
LOGPATH="/data/mongodb/log/mongodb.log"
DBPATH="/data/mongodb/db/"
#CLUSTERNAME="mongodbGraphServer"
#[ ${#CLUSTERNAME} -gt 1 ] || { echo "CLUSTERNAME is NULL"; exit 1; }
PORT=27017
#--pidfilepath
SCRIPTNAME=/etc/init.d/$NAME
# Gracefully exit if the package has been removed.
`$DAEMON -h 1>/dev/null` || exit 0
rh_start() {
#numactl --interleave=all $DAEMON --fork --quiet --port $PORT --journal --rest --httpinterface --pidfilepath $PIDFILE --dbpath $DBPATH --logpath $LOGPATH --replSet $CLUSTERNAME && return 0 || return 1
numactl --interleave=all $DAEMON --fork --quiet --port $PORT --journal --rest --httpinterface --pidfilepath $PIDFILE --dbpath $DBPATH --logpath $LOGPATH && return 0 || return 1
}
rh_stop() {
$DAEMON --dbpath $DBPATH --shutdown 2>/dev/null && return 0 || return 1
}
rh_reload() {
kill -HUP `cat $PIDFILE` 2>/dev/null && return 0 || return 1
}
rh_check() {
[ -f $PIDFILE ] && processID=`cat $PIDFILE` || processID=00000000000
number=`ps aux | awk '{print $2}' | grep $processID | wc -l`
# 0 for running; 1 for not running.
[[ $number -eq 1 ]] && return 0 || return 1
}
rh_clean() {
cd $DBPATH && rm -rvf * && cd $LOGPATH && rm -rvf * && return 0 || return 1
}
case "$1" in
start)
echo -n "Starting $DESC"
rh_check && [[ $? -eq 0 ]] && echo -n ".......[AlreadyRunning]" || { rh_start && echo -n ".......[Started]" || echo -n "Error"; }
echo
;;
stop)
echo -n "Stopping $DESC"
rh_check && [[ $? -eq 0 ]] && { rh_stop && echo -n ".......[Stopped]" || echo -n ".......[Error]"; } || echo -n ".......[AlreadyStopped]"
echo
;;
reload)
echo -n "Reloading $DESC"
rh_check && [[ $? -eq 0 ]] && { rh_reload && echo -n ".......[Reloaded]" || echo -n ".......[ReloadError]"; } || echo -n ".......[Stopped]"
echo
;;
restart)
$0 stop
sleep 1
$0 start
;;
status)
echo -n "Checking $DESC: $NAME"
rh_check && [[ $? -eq 0 ]] && echo -n .......[Running] || echo -n .......[Stopped]
echo
;;
clean)
echo -n "Begin Clean mongodb:"
$0 stop
rh_clean ;[[ $? -eq 0 ]] && echo -n ".......[Cleaned]" || echo -n ".......[CleanedError]"
$0 start
echo
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|reload|sttus}" >&2
exit 3
;;
esac
exit 0