设为首页 收藏本站
查看: 910|回复: 0

[经验分享] Mongodb简介及部署

[复制链接]

尚未签到

发表于 2018-10-25 10:14:17 | 显示全部楼层 |阅读模式
#!/bin/sh  
#
  
# mongodb      init file for starting up the MongoDB server
  
#
  
# chkconfig:   - 90 10
  
# description: Starts and stops the MongDB daemon that handles all \
  
#              database requests.
  

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

  
exec="/usr/local/mongodb/bin/mongod"
  
prog="mongod"
  
logfile="/var/log/mongodb/mongodb.log"
  

  
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
  
pidfile=${PIDFILE-/var/run/mongodb/mongodb.pid}
  
options="$MONGODB_OPTIONS $OPTIONS"
  
lockfile="/var/lock/subsys/mongod"
  
#要修改的就是相应的环境路径
  
# Nicer version of killproc that does not kill mongodb when it takes
  
# a long time to shut down and does not hang for a long time when mongo
  
# shuts down quickly
  
killproc_nice() {
  
        local RC base pid pid_file= delay i
  

  
        RC=0; delay=3
  
        # Test syntax.
  
        if [ "$#" -eq 0 ]; then
  
                echo $"Usage: killproc [-p pidfile] [ -d delay] {program} [-signal]"
  
                return 1
  
        fi
  
        if [ "$1" = "-p" ]; then
  
                pid_file=$2
  
                shift 2
  
        fi
  
        if [ "$1" = "-d" ]; then
  
                delay=$2
  
                shift 2
  
        fi
  

  
        # Save basename.
  
        base=${1##*/}
  

  
        # Find pid.
  
        __pids_var_run "$1" "$pid_file"
  
        RC=$?
  
        if [ -z "$pid" ]; then
  
                if [ -z "$pid_file" ]; then
  
                        pid="$(__pids_pidof "$1")"
  
                else
  
                        [ "$RC" = "4" ] && { failure $"$base shutdown" ; return $RC ;}
  
                fi
  
        fi
  

  
        # Kill it.
  
        if [ -n "$pid" ] ; then
  
                [ "$BOOTUP" = "verbose" -a -z "${LSB:-}" ] && echo -n "$base "
  
                if checkpid $pid 2>&1; then
  
                        # TERM first, then KILL if not dead
  
                        kill -TERM $pid >/dev/null 2>&1
  
                        usleep 100000
  

  
                        # Check every one second if the program is stopped.
  
                        # Do so for a maximum of $delay seconds
  
                        for ((i = 0 ; i < $delay; i++))
  
                        do
  
                                if checkpid $pid; then
  
                                        sleep 1
  
                                else
  
                                        break
  
                                fi
  
                        done
  

  
                        # If the program is not stopped, kill it
  
                        if checkpid $pid ; then
  
                                kill -KILL $pid >/dev/null 2>&1
  
                                usleep 100000
  
                        fi
  
                fi
  
                checkpid $pid
  
                RC=$?
  
                [ &quot;$RC&quot; -eq 0 ] && failure $&quot;$base shutdown&quot; || success $&quot;$base shutdown&quot;
  
                RC=$((! $RC))
  
        else
  
                failure $&quot;$base shutdown&quot;
  
                RC=0
  
        fi
  

  
        # Remove pid file if any.
  
        rm -f &quot;${pid_file:-/var/run/$base.pid}&quot;
  
        return $RC
  
}
  

  
start() {
  
    [ -x $exec ] || exit 5
  
    echo -n $&quot;Starting $prog: &quot;
  
    daemon --pidfile=${pidfile} --user mongodb &quot;$exec $options run >> $logfile 2>&1&quot;
  
    retval=$?
  
    echo
  
    [ $retval -eq 0 ] && touch $lockfile
  
    return $retval
  
}
  

  
stop() {
  
    echo -n $&quot;Stopping $prog: &quot;
  
    killproc_nice -p ${pidfile} -d 300 $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 -p ${pidfile} $prog
  
}
  

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

  

  
case &quot;$1&quot; 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 $&quot;Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}&quot;
  
        exit 2
  
esac
  
exit $?



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-626228-1-1.html 上篇帖子: MongoDB 复制相关介绍 下篇帖子: mongodb3.4--2分片配置实验 wiredTiger -账户管理
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表