本文簡單記錄在64位centos上安裝mongodb的過程。mongodb是用C++開發的面向文檔的資料庫,也就是反傳統的資料庫範式來設計的,把相關的對象都記錄到一個文檔裡,每個文檔內是schema-free的,也就是列名可以自由定義,比較靈活,特別是面對商務邏輯多變的應用情境十分給力。資料以BSON(類似JSON)的格式二進位儲存。不好的地方就是可能帶來一定的資料冗餘和儲存開銷。
mongodb目前最新的版本是.8.2-rc3,其源碼安裝用了很多第三方的東西,比如JS引擎(目前官方推薦的是mozilla的Spider Monkey,以後可能改成google的V8,和node.js一樣,呵呵)、Regex引擎(pcre)、安裝構建工具scons(這東西還要用python來安裝)、boost C++庫等等。下面是安裝實錄:
1,下載需要的源檔案和相關軟體包:
[root@localhost mongodb]# wget http://downloads.mongodb.org/src/mongodb-src-r1.8.2-rc3.tar.gz [root@localhost mongodb]# wget http://sourceforge.net/projects/scons/files/scons/2.1.0.alpha.20101125/scons-2.1.0.alpha.20101125.tar.gz/download [root@localhost mongodb]# wget http://ftp.mozilla.org/pub/mozilla.org/js/js-1.7.0.tar.gz [root@localhost mongodb]# wget http://sourceforge.net/projects/pcre/files/pcre/7.4/pcre-7.4.tar.gz/download
2,安裝scons:
[root@localhost mongodb]# tar zxvf scons-2.1.0.alpha.20101125.tar.gz [root@localhost mongodb]# cd scons-2.1.0.alpha.20101125 [root@localhost scons-2.1.0.alpha.20101125]# python setup.py install
3,安裝pcre:
[root@localhost mongodb]# tar zxvf pcre-7.4.tar.gz [root@localhost mongodb]# cd pcre-7.4 [root@localhost pcre-7.4]# ./configure [root@localhost pcre-7.4]# make [root@localhost pcre-7.4]# make install
4,安裝Spider Monkey:
[root@localhost mongodb]# tar zxvf js-1.7.0.tar.gz [root@localhost mongodb]# cd js/src [root@localhost src]# export CFLAGS="-DJS_C_STRINGS_ARE_UTF8" [root@localhost src]# make -f Makefile.ref [root@localhost src]# JS_DIST=/usr make -f Makefile.ref export
5,安裝boost,yum方式比較偷懶:
[root@localhost src]# yum -y install boost boost-devel
6,安裝mongodb:
[root@localhost mongodb]# tar zxvf mongodb-src-r1.8.2-rc3.tar.gz [root@localhost mongodb]# cd mongodb-src-r1.8.2-rc3 [root@localhost mongodb-src-r1.8.2-rc3]# scons all [root@localhost mongodb-src-r1.8.2-rc3]# scons --prefix=/usr/local/mongodb --full install
7,啟動mongodb來測試:
[root@localhost bin]# ./mongod --dbpath /tmp./mongod: error while loading shared libraries: libpcrecpp.so.0: cannot open shared object file: No such file or directory
[root@localhost bin]# ./mongod --dbpath /tmp ./mongod: error while loading shared libraries: libpcrecpp.so.0: cannot open shared object file: No such file or directory [root@localhost bin]# LD_DEBUG=libs ./mongod -v ...... 29656: trying file=/lib64/tls/x86_64/libpcrecpp.so.0 29656: trying file=/lib64/tls/libpcrecpp.so.0 29656: trying file=/lib64/x86_64/libpcrecpp.so.0 29656: trying file=/lib64/libpcrecpp.so.0 29656: trying file=/usr/lib64/tls/x86_64/libpcrecpp.so.0 29656: trying file=/usr/lib64/tls/libpcrecpp.so.0 29656: trying file=/usr/lib64/x86_64/libpcrecpp.so.0 29656: trying file=/usr/lib64/libpcrecpp.so.0 29656: ./mongod: error while loading shared libraries: libpcrecpp.so.0: cannot open shared object file: No such file or directory [root@localhost bin]# ln -s /usr/local/lib/libpcrecpp.so.0 /usr/lib64/libpcrecpp.so.0 [root@localhost bin]# ll /usr/lib64/libpcrecpp.so.0 lrwxrwxrwx 1 root root 30 Jun 8 11:57 /usr/lib64/libpcrecpp.so.0 -> /usr/local/lib/libpcrecpp.so.0 [root@localhost bin]# ./mongod --dbpath /tmp Wed Jun 8 11:57:38 [initandlisten] MongoDB starting : pid=29700 port=27017 dbpath=/tmp 64-bit Wed Jun 8 11:57:38 [initandlisten] db version v1.8.2-rc3, pdfile version 4.5 Wed Jun 8 11:57:38 [initandlisten] git version: nogitversion Wed Jun 8 11:57:38 [initandlisten] build sys info: Linux localhost.localdomain 2.6.18-128.el5 #1 SMP Wed Jan 21 10:41:14 EST 2009 x86_64 BOOST_LIB_VERSION=1_33_1 Wed Jun 8 11:57:38 [initandlisten] waiting for connections on port 27017 Wed Jun 8 11:57:38 [websvr] web admin interface listening on port 28017
在debian下安裝mongoDB
1. apt-get install scons2. apt-get install libpcrecpp0 ( Perl 5 Compatible Regular Expression Library - C++ runtime files )3. apt-get install libpcre3-dev - Perl 5 Compatible Regular Expression Library - development files4. apt-get install libboost1.35-dev (boost 庫, 官網最新為1.4)5. apt-get install libpcap-dev6. apt-get install libmozjs-dev7. apt-get install xulrunner-dev (gecko庫)8. wget http://fastdl.mongodb.org/src/mongodb-src-r1.4.4.tar.gz9. tar zxvf mongodb-src-r1.4.4.tar.gz10.cd 原始碼解壓目錄11. scons --sharedclient=SHAREDCLIENT all --prefix=/home/liubao/mongodb/mongodb12. scons --prefix=/usr/local/enginc/mongodb install
mongoDB是用C++寫的,在編譯的過程中用到gecko的庫。內部應該用了很多js的操作。而且看到了類似json.cpp檔案。不知道資料是不是以json格式壓縮儲存的。明天看看這個東東怎麼用。
還注意到一個問題。mongoDB是自己寫的driver;而canssandra一類的則是用Thrift的協議進行跨語言通訊;不知道這是出於效能的考慮還是其它的原因
apt-get install sconsE: Sub-process /usr/bin/dpkg returned an error code (1)問題解決辦法:此時可以這樣解決:cd /var/lib/dpkgsudo mv info info.baksudo mkdir info