如何安装Mongodb3.0.6单实例-创新互联

这篇文章将为大家详细讲解有关如何安装Mongodb3.0.6单实例,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

成都创新互联服务项目包括八公山网站建设、八公山网站制作、八公山网页制作以及八公山网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,八公山网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到八公山省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!

[root@b28-17-51 ~]#mkdir -p /export/data

[root@b28-17-51 ~]#mkdir -p /export/log

[root@b28-17-51 export]#tar -xvf mongodb-linux-x86_64-3.0.6.tgz

[root@b28-17-51 export]#mv mongodb-linux-x86_64-3.0.6 mongodb

[root@b28-17-51 log]#touch mongodb.log

[root@b28-17-51 mongodb]#mkdir etc

[root@b28-17-51 etc]#touch mongodb.pid

[root@b28-17-51 etc]# vi 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

[root@b28-17-51 export]#numactl --interleave=all /export/mongodb/bin/mongod --config /export/mongodb/etc/mongod.conf

设置Mongodb启动命令:
[root@b28-17-51 export]#groupadd mongodb

[root@b28-17-51 export]#useradd -m mongodb -g mongodb

脚本如下:
[root@yoon ~]# cd  /etc/init.d/

[root@yoon 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

==========================================
[root@yoon ~]# service mongod start

[root@yoon ~]# service mongod stop

===============================================
设置开机自动启动Mongodb
[root@yoon ~]# chkconfig --add mongod

[root@yoon ~]# chkconfig  mongod  on

[root@yoon ~]# chkconfig mongod --list
mongod         0:off 1:off 2:on 3:on 4:on 5:on 6:off

关于“如何安装Mongodb3.0.6单实例”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。


本文标题:如何安装Mongodb3.0.6单实例-创新互联
标题来源:http://myzitong.com/article/ceejid.html