4

白话MongoDB(二)

 2 years ago
source link: https://blogread.cn/it/article/3515?f=hot1
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

白话MongoDB(二)

浏览:2387次  出处信息

前面扯了一堆,要了解一个东西,最好的办法,还是让他跑起来,然后结合文档和测试,来验证其实现,并且了解其不足和优点。

MongoDB提供了部分系统的编译版本,但从研究学习以及线上不同依赖包的稳定性的目标,个人还是比较推荐从源代码编译安装的方式。MongoDB的源代码依赖了一些基础组件,如js引擎Spider Monkey,正则表达式引擎PCRE,安装构建工具Scons,以及C++的boost库等,因此编译还是有些麻烦的,realzyy的这篇文章已经比较详细的说明了编译的步骤,主要基于Redhat系统。在ubuntu上安装,还有几个注意点:

1. PCRE最好在编译的时候显式指明对UTF-8的支持

$ configure --enable-unicode-properties
$ sudo make -j 2 && make install

PCRE如果不支持UTF-8,则MongoDB无法启动

Thu Mar 31 17:27:16 Assertion: 10342:pcre not compiled with utf8 support
0x8169528 0x81e704e 0x8450212 0xb73b6ce7 0x80f5b11
 ./mongod(_ZN5mongo11msgassertedEiPKc+0x208) [0x8169528]
 ./mongod(_ZN5mongo6RXTest3runEv+0x3fe) [0x81e704e]
 ./mongod(main+0x3832) [0x8450212]
 /lib/libc.so.6(__libc_start_main+0xe7) [0xb73b6ce7]
 ./mongod() [0x80f5b11]

2. Ubutun自身带了一个Spider Monkey,但版本有些老,有些MongoDB需要的特性不支持,需要先卸载

$dpkg -l | grep xulrunner
$sudo apt-get remove xulrunner-1.9.2-dev xulrunner-1.9.2

$export CFLAGS=”-DJS_C_STRINGS_ARE_UTF8″
$sudo make -f Makefile.ref
$sudo JS_DIST=/usr make -f Makefile.ref export

3. 需要安装boost等库的支持

$sudo apt-get -y install tcsh git-core scons g++
$sudo apt-get -y install libpcre++-dev libboost-dev libreadline-dev xulrunner-dev
$sudo apt-get -y install libboost-program-options-dev \
libboost-thread-dev libboost-filesystem-dev libboost-date-time-dev

4. 源代码建议从github上下载,根据需要编译相应的版本

$git clone git://github.com/mongodb/mongo.git
$cd mongo
$git tag -l
$git checkout r1.8.0

5.最后,编译安装MongoDB的时候,建议连带头文件和库文件一起

$scons all
$scons --prefix=/opt/mongo --full install

另外,MongoDB也可以使用Google V8来作为js引擎,从性能方面来说,V8可能是更好的选择,从jira来看,MongoDB在未来或许会改用v8作为默认引擎。

首先编译V8,然后编译MongoDB的时候使用userv8参数:

$svn checkout http://v8.googlecode.com/svn/trunk/ v8
$cd v8
$scons
$sudo cp libv8.a /usr/lib
$sudo cp libv8preparser.a /usr/lib
$sudo cp -r include/* /usr/include/

$cd mongodb-src
$scons all --usev8
$scons --prefix=/opt/mongo --full install

MongoDB在32位环境下有诸多限制,只能用于学习研究的目的,线上环境一定要使用64位系统。

Thu Mar 31 17:24:58 --oplogSize of 1024MB is too big for 32 bit version. Use 64 bit build instead.

参考:
http://www.mongodb.org/display/DOCS/Building+Spider+Monkey
http://www.mongodb.org/display/DOCS/Building+for+Linux
http://www.howsthe.com/blog/2010/feb/22/mongodb-and-v8/
http://jira.mongodb.org/browse/SERVER-446


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK