MongoDB源码编译

 

MongoDB源码编译

本人编译的版本编译的版本为mongodb2.6分支,目前MongoDB3.0已经发布,编译步骤和2.6的差不多,不过3.0版本要求编译器支持c++11标准,所以如果是在Linux平台下编译,必须先升级GCC到4.8.2版本,在Windows下编译需要Visual Studio 2013 Update 2以上版本。

MongoDB源码下载地址: 源码下载

2.6版本源码编译使用Scons,所以需要准备以下软件:
Python 2.7.9 : 点此下载
Scons 2.3.4: 点此下载
Windos平台-VS2010以上版本: 点此下载
Linux平台-GCC: 点此下载

Windows下软件安装说明:
1, Python安装目录中不能有空格,也就是不能放在“Program Files”类似目录中,使用默认目录就可以。
2, Python安装完成后需要配置环境变量,在PATH后面增加”;D:\Python27”(此处根据自己目录配置)。
3, 先安装Python,然后安装Scons,安装完成后配置环境变量”;D:\Python27\Scripts”。

Windows下编译:
开始菜单中找到Visual Studio Tools,然后打开VS2013 x64 Native Tools Command Prompt(VS2013 x64 本机工具命令提示),cd到源码目录,然后输入“scons all –64 -j4”即可开始编译, 如果只是需要MongoDB中某个模块,则可以”scons mongod –64 -j4”。

说明:
1, 源码不要放在中文目录下面,这个是我个人编译时候犯的错误,导致编译时候出现”C++ compiler $CC does not work”错误,不知道和我自己电脑有没有关系。
2, 在Windows上编译2.6版本时需要加上”–64”命令,否则会出现”error : You cannot use 32-bit time_t (_USE_32BIT_TIME_T) with _WIN64”错误,这个是MongoDB的BUG,点此查看
3, “-j4”命令是为了加快编译速度,“4”问自己电脑CPU数量,这个命令使用多进程编译。

Linux下软件安装说明:
笔者个人为电脑为Centos6,默认已经安装Python,只需要升级就行,我自己下载了Python源码然后编译升级。
1, Python编译升级: 在终端中cd到Python源码目录,运行./configure, 再运行make install即可。
2, Scons安装: 在终端中cd到Scons目录,运行”python setup.py install”即可。

Linux下编译:
在终端中cd到MongoDB源码目录,然后直接运行“scons all –64 -j4”即可。

说明:
1, 如果是使用“all”命令编译,则源码所在目录挂载的分区内存最好大于30G,不然会编译一半提示内存不足而终止。

 
%23%23%20MongoDB%u6E90%u7801%u7F16%u8BD1%0A%0A%u672C%u4EBA%u7F16%u8BD1%u7684%u7248%u672C%u7F16%u8BD1%u7684%u7248%u672C%u4E3Amongodb2.6%u5206%u652F%uFF0C%u76EE%u524DMongoDB3.0%u5DF2%u7ECF%u53D1%u5E03%uFF0C%u7F16%u8BD1%u6B65%u9AA4%u548C2.6%u7684%u5DEE%u4E0D%u591A%uFF0C%u4E0D%u8FC73.0%u7248%u672C%u8981%u6C42%u7F16%u8BD1%u5668%u652F%u6301c++11%u6807%u51C6%uFF0C%u6240%u4EE5%u5982%u679C%u662F%u5728Linux%u5E73%u53F0%u4E0B%u7F16%u8BD1%uFF0C%u5FC5%u987B%u5148%u5347%u7EA7GCC%u5230%u65B0%u7248%u672C%u3002%0A%0AMongoDB%u6E90%u7801%u4E0B%u8F7D%u5730%u5740%3A%20%5B%u6E90%u7801%u4E0B%u8F7D%5D%28https%3A//github.com/mongodb%29%0A%0A2.6%u7248%u672C%u6E90%u7801%u7F16%u8BD1%u4F7F%u7528Scons%uFF0C%u6240%u4EE5%u9700%u8981%u51C6%u5907%u4EE5%u4E0B%u8F6F%u4EF6%3A%0APython%202.7.9%20%3A%20%5B%u70B9%u6B64%u4E0B%u8F7D%5D%28https%3A//www.python.org/%29%0AScons%202.3.4%3A%20%5B%u70B9%u6B64%u4E0B%u8F7D%5D%28http%3A//www.scons.org/%29%0AWindos%u5E73%u53F0-VS2010%u4EE5%u4E0A%u7248%u672C%3A%20%20%5B%u70B9%u6B64%u4E0B%u8F7D%5D%28http%3A//msdn.itellyou.cn/%29%0ALinux%u5E73%u53F0-GCC%3A%20%5B%u70B9%u6B64%u4E0B%u8F7D%5D%28http%3A//gcc.gnu.org/%29%0A%0AWindows%u4E0B%u8F6F%u4EF6%u5B89%u88C5%u8BF4%u660E%3A%0A1%2C%20Python%u5B89%u88C5%u76EE%u5F55%u4E2D%u4E0D%u80FD%u6709%u7A7A%u683C%uFF0C%u4E5F%u5C31%u662F%u4E0D%u80FD%u653E%u5728%u201CProgram%20Files%u201D%u7C7B%u4F3C%u76EE%u5F55%u4E2D%uFF0C%u4F7F%u7528%u9ED8%u8BA4%u76EE%u5F55%u5C31%u53EF%u4EE5%u3002%0A2%2C%20Python%u5B89%u88C5%u5B8C%u6210%u540E%u9700%u8981%u914D%u7F6E%u73AF%u5883%u53D8%u91CF%uFF0C%u5728PATH%u540E%u9762%u589E%u52A0%22%3BD%3A%5CPython27%22%uFF08%u6B64%u5904%u6839%u636E%u81EA%u5DF1%u76EE%u5F55%u914D%u7F6E%uFF09%u3002%0A3%2C%20%u5148%u5B89%u88C5Python%uFF0C%u7136%u540E%u5B89%u88C5Scons%uFF0C%u5B89%u88C5%u5B8C%u6210%u540E%u914D%u7F6E%u73AF%u5883%u53D8%u91CF%22%3BD%3A%5CPython27%5CScripts%22%u3002%0A%0AWindows%u4E0B%u7F16%u8BD1%3A%0A%u5F00%u59CB%u83DC%u5355%u4E2D%u627E%u5230Visual%20Studio%20Tools%uFF0C%u7136%u540E%u6253%u5F00VS2013%20x64%20Native%20Tools%20Command%20Prompt%28VS2013%20x64%20%u672C%u673A%u5DE5%u5177%u547D%u4EE4%u63D0%u793A%29%uFF0Ccd%u5230%u6E90%u7801%u76EE%u5F55%uFF0C%u7136%u540E%u8F93%u5165%u201Cscons%20all%20--64%20-j4%u201D%u5373%u53EF%u5F00%u59CB%u7F16%u8BD1%uFF0C%20%u5982%u679C%u53EA%u662F%u9700%u8981MongoDB%u4E2D%u67D0%u4E2A%u6A21%u5757%uFF0C%u5219%u53EF%u4EE5%22scons%20mongod%20--64%20-j4%22%u3002%0A%21%5BAlt%20text%5D%28./%u672A%u547D%u540D.jpg%29%0A%0A%u8BF4%u660E%3A%0A1%2C%20%u6E90%u7801%u4E0D%u8981%u653E%u5728%u4E2D%u6587%u76EE%u5F55%u4E0B%u9762%uFF0C%u8FD9%u4E2A%u662F%u6211%u4E2A%u4EBA%u7F16%u8BD1%u65F6%u5019%u72AF%u7684%u9519%u8BEF%uFF0C%u5BFC%u81F4%u7F16%u8BD1%u65F6%u5019%u51FA%u73B0%22C++%20compiler%20%24CC%20does%20not%20work%22%u9519%u8BEF%uFF0C%u4E0D%u77E5%u9053%u548C%u6211%u81EA%u5DF1%u7535%u8111%u6709%u6CA1%u6709%u5173%u7CFB%u3002%0A2%2C%20%u5728Windows%u4E0A%u7F16%u8BD12.6%u7248%u672C%u65F6%u9700%u8981%u52A0%u4E0A%22--64%22%u547D%u4EE4%uFF0C%u5426%u5219%u4F1A%u51FA%u73B0%22error%20%3A%20You%20cannot%20use%2032-bit%20time_t%20%28_USE_32BIT_TIME_T%29%20with%20_WIN64%22%u9519%u8BEF%uFF0C%u8FD9%u4E2A%u662FMongoDB%u7684BUG%uFF0C%5B%u70B9%u6B64%u67E5%u770B%5D%28https%3A//jira.mongodb.org/browse/SERVER-14649%29%0A3%2C%20%u201C-j4%u201D%u547D%u4EE4%u662F%u4E3A%u4E86%u52A0%u5FEB%u7F16%u8BD1%u901F%u5EA6%uFF0C%u201C4%u201D%u95EE%u81EA%u5DF1%u7535%u8111CPU%u6570%u91CF%uFF0C%u8FD9%u4E2A%u547D%u4EE4%u4F7F%u7528%u591A%u8FDB%u7A0B%u7F16%u8BD1%u3002%0A%0ALinux%u4E0B%u8F6F%u4EF6%u5B89%u88C5%u8BF4%u660E%3A%0A%u7B14%u8005%u4E2A%u4EBA%u4E3A%u7535%u8111%u4E3ACentos6%uFF0C%u9ED8%u8BA4%u5DF2%u7ECF%u5B89%u88C5Python%uFF0C%u53EA%u9700%u8981%u5347%u7EA7%u5C31%u884C%uFF0C%u6211%u81EA%u5DF1%u4E0B%u8F7D%u4E86Python%u6E90%u7801%u7136%u540E%u7F16%u8BD1%u5347%u7EA7%u3002%0A1%2C%20%20Python%u7F16%u8BD1%u5347%u7EA7%3A%20%u5728%u7EC8%u7AEF%u4E2Dcd%u5230Python%u6E90%u7801%u76EE%u5F55%uFF0C%u8FD0%u884C./configure%2C%20%20%u518D%u8FD0%u884Cmake%20install%u5373%u53EF%u3002%0A2%2C%20Scons%u5B89%u88C5%3A%20%u5728%u7EC8%u7AEF%u4E2Dcd%u5230Scons%u76EE%u5F55%uFF0C%u8FD0%u884C%22python%20setup.py%20install%22%u5373%u53EF%u3002%0A%0ALinux%u4E0B%u7F16%u8BD1%3A%0A%u5728%u7EC8%u7AEF%u4E2Dcd%u5230MongoDB%u6E90%u7801%u76EE%u5F55%uFF0C%u7136%u540E%u76F4%u63A5%u8FD0%u884C%u201Cscons%20all%20--64%20-j4%u201D%u5373%u53EF%u3002%0A%0A%u8BF4%u660E%3A%0A1%2C%20%u5982%u679C%u662F%u4F7F%u7528%u201Call%u201D%u547D%u4EE4%u7F16%u8BD1%uFF0C%u5219%u6E90%u7801%u6240%u5728%u76EE%u5F55%u6302%u8F7D%u7684%u5206%u533A%u5185%u5B58%u6700%u597D%u5927%u4E8E30G%uFF0C%u4E0D%u7136%u4F1A%u7F16%u8BD1%u4E00%u534A%u63D0%u793A%u5185%u5B58%u4E0D%u8DB3%u800C%u7EC8%u6B62%u3002
posted @ 2015-03-26 19:10  _ccx  阅读(2752)  评论(0编辑  收藏  举报