CentOS 手工編譯、手動編譯安裝 MongoDB

下載所需軟件(下載到/usr/local/src目錄)php

#wget http://downloads.mongodb.org/src/mongodb-src-r1.8.1.tar.gz
#wget http://ftp.mozilla.org/pub/mozilla.org/js/js-1.7.0.tar.gz
#wget http://sourceforge.net/projects/pcre/files/pcre/8.12/pcre-8.12.tar.bz2

安裝 python :python

#yum install -y python-devel  
安裝scons: 下載scons(http://www.scons.org/download.php)
tar zxf scons-2.0.1.tar.gz
cd scons-2.0.1
python setup.py install

安裝spidermonkey庫,下載支持c的js api庫 js-1.7.0.tar.gz(http://ftp.mozilla.org/pub/mozilla.org/js/)linux

yum install -y boost boost-devel

tar zxvf js-1.7.0.tar.gz
cd js/src/
export CFLAGS="-DJS_C_STRINGS_ARE_UTF8"
make -f Makefile.ref
JS_DIST=/usr gmake -f Makefile.ref export
cd ../..

安裝pcremongodb

tar zxf pcre-8.12.tar.gz
cd pcre-8.12
./configure --enable-utf8 --enable-unicode-properties
make && make install
cd ..

安裝MongoDBvim

tar zxf mongodb-src-r1.8.1.tar.gz
 cd mongodb-src-r1.8.1
scons 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"] )  )
scons --prefix=/usr/local/mongo install
若是須要安裝lib和head,使用以下方式安裝
scons --prefix=/usr/local/mongo --full install

建立配置文件centos

mkdir -p /usr/local/mongo/etc /usr/local/mongo/data /usr/local/mongo/log/ /usr/local/mongo/repair
vim  /usr/local/mongo/etc/mongo.conf
在mongo.conf中添加下面的內容
dbpath = /usr/local/mongo/data
logpath = /usr/local/mongo/mongodb.log
repairpath = /usr/local/mongo/repair
pidfilepath = /usr/local/mongo/mongodb.pid
directoryperdb = true
logappend = true
noauth = true
port = 27017
maxConns = 1024
fork = true
rest = true
quota = true
quotaFiles = 1024
nssize = 16

啓動mongodbapi

ln -s /usr/local/mongo/bin/mongod /usr/bin/mongod
mongod -f /usr/local/mongo/etc/mongo.conf

看看是否是啓動起來了,可是使用這種方式管理mongodb服務器很不明智,咱們完善一下:bash

mkdir -p /usr/local/mongo/srv
vim /usr/local/mongo/srv/mongodb-start

添加下面的內容服務器

#!/bin/sh
mongod -f /usr/local/mongo/etc/mongo.conf

vim /usr/local/mongo/srv/mongodb-stop

添加下面的內容app

#!/bin/bash
pid=`ps -o pid,command ax | grep mongod | awk '!/awk/ && !/grep/ {print $1}'`;
if [ "${pid}" != "" ]; then
    kill -2 ${pid};
fi

添加執行權限

chmod a+x /usr/local/mongo/srv/mongodb-start
chmod a+x /usr/local/mongo/srv/mongodb-stop
vim /etc/rc.d/init.d/mongodb

添加下面的內容

#! /bin/sh
#
# mongodb – this script starts and stops the mongodb daemon
#
# chkconfig: - 85 15
# description: MongoDB is a non-relational database storage system.
# processname: mongodb
# config: /usr/local/mongo/etc/mongo.conf
# pidfile: /usr/local/mongo/mongodb.pid
PATH=/usr/local/mongo/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=mongodb
test -x $DAEMON || exit 0
set -e
case "$1" in
  start)
        echo -n "Starting MongoDB... "
        /usr/local/mongo/srv/mongodb-start
        ;;
  stop)
        echo -n "Stopping MongoDB... "
        /usr/local/mongo/srv/mongodb-stop
        ;;
      *)
            N=/etc/init.d/$NAME
            echo "Usage: $N {start|stop}" >&2
            exit 1
            ;;
    esac
    exit 0

添加服務

chmod a+x /etc/rc.d/init.d/mongodb
chkconfig --add mongodb
chkconfig --level 345 mongodb on
/etc/rc.d/init.d/mongodb start

轉載自:http://www.9958.pw/post/centos_mongodb

相關文章
相關標籤/搜索