good
MongoDB与C++ Client安装 - vincent的日志 - 网易博客
出处: http://hi.baidu.com/kissdev/blog/item/b275a14e9a82d9dcd0c86a57.html
Mongdb 是一个高性能可扩展的no-sql数据库产品,即适用key-value查询管理,也适用关系型数据管理,操作语言以JavaScript为主,访问接口提供C/C++/PHP/Perl/Python等多种(称为Driver)。
环境: CentOS 64-bit
1. 服务端安装
# 下载mongdb编译好的二进制服务端
wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-1.8.1.tgz
tar xvzf mongodb-linux-x86_64-1.8.1.tgz
mkdir /trackerdb
cd mongodb-linux-x86_64-1.8.1
# 指定数据目录,启动mongod服务端
bin/mongod --dbpath /trackerdb --nohttpinterface
2. 客户端安装
(1) 编译boost
卸载已有的boost
rpm -e --allmatches boost boost-devel
安装和编译boost 1.4.2,通过JAM编译
wget "http://downloads.sourceforge.net/project/boost/boost/1.42.0/boost_1_42_0.tar.bz2?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fboost%2Ffiles%2Fboost%2F1.42.0%2F&ts=1302909648&use_mirror=cdnetworks-kr-1"
tar xvjf boost_1_42_0.tar.bz2
cd boost_1_42_0
cd tools/jam
./build_dist.sh
cd src./build.sh
生成jam
ll bin.linuxx86_64/bjam
cd ../../../
tools/jam/src/bin.linuxx86_64/bjam toolset=gcc variant=debug threading=multi --with-program_options --with-filesystem --with-date_time --with-thread --prefix=/usr/local -d+2
编译完后
cp stage/lib/* /usr/local/lib
cp -r boost /usr/local/include
ldconfig
(2) 下载C++ Driver,编译例子程序
wget http://downloads.mongodb.org/cxx-driver/mongodb-linux-x86_64-v1.8-latest.tgz
tar xvzf mongodb-linux-x86_64-v1.8-latest.tgz
cd mongo-cxx-driver-v1.8/
scons (需要事先安装python的make工具scons, yum install scons , dag库上有)
将生成 libmongoclient.a
cd client/examples
g++ -I../../mongo -L../../ clientTest.cpp -lmongoclient -lboost_thread -lboost_filesystem -lboost_program_options
./clientTest 进行测试,结果如图所示