MongoDB的源代碼依賴了一些基礎組件,如js引擎Spider Monkey,正則表達式引擎PCRE,安裝構建工具Scons,以及C++的boost庫等
1、準備
wget http://downloads.mongodb.org/src/mongodb-src-r1.8.2.tar.gz
wget http://sourceforge.net/projects/scons/files/scons/2.1.0.alpha.20101125/scons-2.1.0.alpha.20101125.tar.gz/download
wget http://ftp.mozilla.org/pub/mozilla.org/js/js-1.7.0.tar.gz
wget http://sourceforge.net/projects/pcre/files/pcre/7.4/pcre-7.4.tar.gz/download
wget http://downloads.sourceforge.net/project/boost/boost/1.42.0/boost_1_42_0.tar.gz?use_mirror=cdnetworks-kr-1
2、scons編譯安裝
tar zxvf scons-2.1.0.alpha.20101125.tar.gz
cd scons-2.1.0.alpha.20101125
python setup.py install
3、pcre編譯安裝
tar zxvf pcre-7.4.tar.gz
cd pcre-7.4
configure --enable-unicode-properties
make -j 2 && make install
configure中要加入--enable-unicode-properties支持,要不運行mongod會出現下面錯誤
Fri Dec 30 23:53:45 Assertion: 10342:pcre not compiled with utf8 support
0x53f16a 0x5cfda1 0x8945f3 0x338101d994 0x4c0e49
/usr/local/mongodb/bin/mongod(_ZN5mongo11msgassertedEiPKc+0x12a) [0x53f16a]
/usr/local/mongodb/bin/mongod(_ZN5mongo6RXTest3runEv+0x3b1) [0x5cfda1]
/usr/local/mongodb/bin/mongod(main+0x5c73) [0x8945f3]
/lib64/libc.so.6(__libc_start_main+0xf4) [0x338101d994]
/usr/local/mongodb/bin/mongod(__gxx_personality_v0+0x451) [0x4c0e49]
4、js編譯安裝
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 make -f Makefile.ref export
5、boost編譯安裝
tar -zxvf boost_1_42_0.tar.gz
cd boost_1_42_0/
#使用下面的命令創建boost自己的編譯工具bjam(目的是保證Boost在任何平臺上都能用bjam編譯),類似于GNU Make。
./bootstrap.sh
#會安裝頭文件和庫文件到相應指定目錄,頭文件安裝到/usr/local/include下,庫文件安裝到/usr/local/lib下
install
#最后執行的創建命令:
./bjam –without-python –layout=tagged variant=debug,release link=static,shared runtime-link=shared threading=multi stage
6、mongodb編譯安裝
tar -xzvf mongodb-src-r1.8.2.tar.tar
cd mongodb-src-r1.8.2/
scons all
scons --prefix=/usr/local/mongodb --full install
安裝成功后 安裝到/usr/local/mongodb下
文件結果
bin
GNU-AGPL-3.0
include
lib64
README
THIRD-PARTY-NOTICES
7、加入環境變量
/etc/profile 加入
CLASSPATH=.:/usr/local/lib
export CLASSPATH
然后source /etc/profile
完成后就可以運行mongodb。
[root@test_192.168.4.95 mongodb]# bin/mongo
MongoDB shell version: 1.8.2
connecting to: test
運行可能會出現下面錯誤
/usr/local/mongodb/bin/mongod: error while loading shared libraries: libboost_system.so.1.42.0: cannot open shared object file: No such file or directory
解決方法
echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
/sbin/ldconfig