下载所需软件(下载到/usr/local/src目录)
1#wget http://downloads.mongodb.org/src/mongodb-src-r1.8.1.tar.gz 2#wget http://ftp.mozilla.org/pub/mozilla.org/js/js-1.7.0.tar.gz 3#wget http://sourceforge.net/projects/pcre/files/pcre/8.12/pcre-8.12.tar.bz2
安装 python :
1#yum install -y python-devel 2安装scons: 下载scons(http://www.scons.org/download.php) 3tar zxf scons-2.0.1.tar.gz 4cd scons-2.0.1 5python setup.py install
安装spidermonkey库,下载支持c的js api库 js-1.7.0.tar.gz(http://ftp.mozilla.org/pub/mozilla.org/js/)
1yum install -y boost boost-devel 2 3tar zxvf js-1.7.0.tar.gz 4cd js/src/ 5export CFLAGS="-DJS_C_STRINGS_ARE_UTF8" 6make -f Makefile.ref 7JS_DIST=/usr gmake -f Makefile.ref export 8cd ../..
安装pcre
1tar zxf pcre-8.12.tar.gz 2cd pcre-8.12 3./configure --enable-utf8 --enable-unicode-properties 4make && make install 5cd ..
安装MongoDB
1tar zxf mongodb-src-r1.8.1.tar.gz 2 cd mongodb-src-r1.8.1 3scons all // scons可能出现找不到pcre库的现象(修改/etc/ld.so.conf也无用,是scons自身的问题),这时需要打开mongodb-src-r1.8.0下的SConstruct,查找【 linux2"== os.sys.platform:】,在LIBPATH后面添加上pcrecpp库的安装路径,在LIBS后添加上pcrecpp库名,再重新scons all即可(操作:vim SConstruct;原来:env.Append( LIBPATH=["/usr/lib64" , "/lib64" ] ) ;修改后env.Append( LIBPATH=["/usr/lib64" , "/lib64" ,"/usr/local/pcre/lib"]); 接下来在env.Append( LIBS=["pthread"] )后面添加 env.Append( LIBS=["libpcrecpp"] ) ) 4scons --prefix=/usr/local/mongo install 5如果需要安装lib和head,使用如下方式安装 6scons --prefix=/usr/local/mongo --full install
创建配置文件
1mkdir -p /usr/local/mongo/etc /usr/local/mongo/data /usr/local/mongo/log/ /usr/local/mongo/repair 2vim /usr/local/mongo/etc/mongo.conf 3在mongo.conf中添加下面的内容 4dbpath = /usr/local/mongo/data 5logpath = /usr/local/mongo/mongodb.log 6repairpath = /usr/local/mongo/repair 7pidfilepath = /usr/local/mongo/mongodb.pid 8directoryperdb = true 9logappend = true 10noauth = true 11port = 27017 12maxConns = 1024 13fork = true 14rest = true 15quota = true 16quotaFiles = 1024 17nssize = 16
启动mongodb
1ln -s /usr/local/mongo/bin/mongod /usr/bin/mongod 2mongod -f /usr/local/mongo/etc/mongo.conf
看看是不是启动起来了,但是使用这种方式管理mongodb服务器很不明智,我们完善一下:
1mkdir -p /usr/local/mongo/srv 2vim /usr/local/mongo/srv/mongodb-start
添加下面的内容
1#!/bin/sh 2mongod -f /usr/local/mongo/etc/mongo.conf 3 4vim /usr/local/mongo/srv/mongodb-stop
添加下面的内容
1#!/bin/bash 2pid=`ps -o pid,command ax | grep mongod | awk '!/awk/ && !/grep/ {print $1}'`; 3if [ "${pid}" != "" ]; then 4 kill -2 ${pid}; 5fi
添加执行权限
1chmod a+x /usr/local/mongo/srv/mongodb-start 2chmod a+x /usr/local/mongo/srv/mongodb-stop 3vim /etc/rc.d/init.d/mongodb
添加下面的内容
1#! /bin/sh 2# 3# mongodb – this script starts and stops the mongodb daemon 4# 5# chkconfig: - 85 15 6# description: MongoDB is a non-relational database storage system. 7# processname: mongodb 8# config: /usr/local/mongo/etc/mongo.conf 9# pidfile: /usr/local/mongo/mongodb.pid 10PATH=/usr/local/mongo/bin:/sbin:/bin:/usr/sbin:/usr/bin 11NAME=mongodb 12test -x $DAEMON || exit 0 13set -e 14case "$1" in 15 start) 16 echo -n "Starting MongoDB... " 17 /usr/local/mongo/srv/mongodb-start 18 ;; 19 stop) 20 echo -n "Stopping MongoDB... " 21 /usr/local/mongo/srv/mongodb-stop 22 ;; 23 *) 24 N=/etc/init.d/$NAME 25 echo "Usage: $N {start|stop}" >&2 26 exit 1 27 ;; 28 esac 29 exit 0
添加服务
1chmod a+x /etc/rc.d/init.d/mongodb 2chkconfig --add mongodb 3chkconfig --level 345 mongodb on 4/etc/rc.d/init.d/mongodb start