centos安装mongodb 3.2.9

centos 6.5 x64

1、下载地址:用迅雷下载,直接下载下不动

https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.2.9.tgz

 

2。解压:
tar -zxvf mongodb-linux-x86_64-rhel62-3.0.1.tgz
  
 
3。指定安装目录:
 
mv mongodb-linux-i686-2.0.3.tgz /usr/local/mongodb  
 
 
4。新建mongodb数据文件存放目录:
 
mkdir -p /app/mongodb/db  
  
 
5。新建log文件存放目录:
 
mkdir -p /app/mongodb/logs  
 
 
6。
 
cd /usr/local/mongodb/bin  
 
 
7。新建配置文件,mongodb支持把参数写进配置文件,执行:
 
vi mongodb.conf  
 
加入内容如下: 
dbpath = /app/mongodb/db #数据文件存放目录  
  
logpath = /app/mongodb/logs/mongodb.log #日志文件存放目录  
  
port = 27017  #端口  
  
fork = true  #以守护程序的方式启用,即在后台运行  
  
nohttpinterface = true  
 
 
 
8。启动Mongo程序,使用配置文件mongodb.conf定义的参数启动 
/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/bin/mongodb.conf
 
 
9。测试,OK,安装成功! 
 
 
配置开机自动启动mongodb 
vi /etc/rc.d/rc.local  
 
在文件中加入: 
/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/bin/mongodb.conf  
 
注意:默认mongodb的数据目录对应的是/data/db下面。日志目录对于到/data/logs/mongodb.log,如果是目录结构有调整需要重新指定配置的路径
 
 
 
 
 

MongoDB安装了以后,应当设置开机自启动。

假设启动命令如下:

sudo /db/mongodb/265/bin/mongod --config /db/conf/mongodb/mongodb.conf

方法有二:

1、把这句话写到把 /etc/rc.local,即可开机启动。

第二种:

2、将一个脚本放到/etc/init.d/

比如,命名为/etc/init.d/mongodb,则执行以下步骤即可:

1)要给它们赋予执行权限:
chmod +x /etc/init.d/mongodb

2)接着试一下是否可以启动、停止:
service mongodb start
service mongodb stop

3)最后设为开机启动:
chkconfig mongodb on

#!/bin/bash

# mongod - Startup script for mongod

# chkconfig: 35 80 15
# description: Mongo is a scalable, document-oriented database.
# processname: mongod
#config: /db/conf/mongodb/mongod.conf
# pidfile: /var/run/mongo/mongo.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 /var/run/mongodb || (mkdir -p /var/run/mongodb ; chown mongod:mongod /var/run/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="/db/conf/mongodb/mongodb.conf"
SYSCONFIG="/etc/sysconfig/mongod"

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

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

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

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

start()
{
  echo -n $"Starting mongod: "
#  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
#  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 /db/mongodb/265/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

  

你可能感兴趣的:(centos安装mongodb 3.2.9)