您的位置:首页 > 数据库 > Mongodb

在Ubuntu上编译安装MongoDB

2017-09-09 20:46 1081 查看
1 背景

希望在银河麒麟(飞腾处理器),中标麒麟(龙芯3A处理器)上部署MongoDB数据库,这两种操作系统都是非常接近linux的操作系统。在银河麒麟操作系统上,使用mongodb-linux-x86_64-ubuntu1404-3.4.7.gz即可运行MongoDB,而在中标麒麟操作系统上则不可以,因此需要使用源码进行编译。于是我在自己的电脑(Ubuntu操作系统)上面进行练习。

2 平台

以下为实验室的实验平台:

操作系统:Ubuntu:14.04.4
LTS,具备如下的必要工具。

Python:2.7.6 (自带)

GCC:4.8.4 (自带)

编译工具:Scons:2.5.1(下载tar.gz文件安装,方法见下文)

Mongo:3.2 (下载地址:Github上面选择mongo的3.2branch,方法见下文)

3 MongoDB官方文档

GitHub上可以看到:https://github.com/mongodb/mongo/wiki/Build-Mongodb-From-Source

主要摘要:

Dependencies & Installation

The requirements for building MongoDB vary by branch:

To build the master branch, you will need:

A modern and complete C++11 compiler. One of the following is required:
VS2015 Update 2 or newer
GCC 5.3.0
Clang 3.4 (or Apple XCode 5.1.1 Clang) or newer

Python 2.7
SCons 2.3.5 or newer (for MSVC 2015 support)
To build the 3.2 and 3.0 branches, you will need
4000
:

A C++11 compiler. One of the following is required:
VS2013 Update 4 or newer. Note that VS2015 is currently not compatible with the 3.0 and 3.2 branches. You must use VS2013.
GCC 4.8.2 or newer. Note that versions of GCC newer than 4.8.2 may produce warnings when building these branches, which are promoted to errors. Please use the --disable-warnings-as-errors build option if necessary to allow the build to succeed despite the
warnings.

Python 2.7
SCons 2.3.0 or newer
To build the 2.6 branch, you will need:

A C++03 compiler, or VS2010 or newer.
MongoDB uses SCons to build the Server and the shell. While it is unnecessary to know all the intricacies of SCons, glancing over the documentation may be helpful. SCons is unlikely to come
preinstalled on your system, so make sure to install it using your preferred package manager.

注:

1. 紫色标注版本为本问实验的参考,因此在编译过程中也需要保证版本的要求,亲测不满足的话会通不过编译前的检测的

2. 实话说,官网真是最权威的参考,应该先看官网,卡住没有办法进行的时候再参考别人是如何操作的,这样才不会从大方向上走歪

4 编译步骤

(一)下载源代码及所需工具

step 1: 下载mongo

下载网址:https://github.com/mongodb/mongo

选择3.2版本,下载mongo-3.2.zip

step 2: 下载Scons

下载:scons-2.5.1.tar.gz,我在CSDN上面下载哒

(二)安装Scons

step 1: 将scons-2.5.1.tar.gz文件拷贝解压至/opt/scons文件夹下(只要在/opt下面的自定义文件夹下就好)

step 2: 进入/opt/scons/scons-2.5.1文件夹

step 3: 运行python setup.py install

step 4: 运行scons --version查看是否安装成功

特别鸣谢:http://www.educity.cn/net/1575267.html

注:可能会遇到需要可以使用sudo chmod -R 777将/opt/scons文件夹权限放大的问题

(三)编译及安装MongoDB

step 1: 将mongo-3.2.zip拷贝并解压在/opt/mongo文件夹下

step 2: 在/opt/mongo/mongo-3.2文件夹下建立文件version.json,内容如下:

{

"version":"3.2.0"

}

step3 :在/opt/mongo/mongo-3.2文件夹下执行如下命令,开始编译,编译好之后,发现该文件夹下多了一些文件和文件夹:

scons core

step 4: 在/opt/mongo/mongo-3.2文件夹下执行如下命令来安装mongo,这样在/opt/mongo文件夹下面就会出现一个/bin文件夹:

scons --prefix=/opt/mongo install

step 5: 在/bin文件夹下看到mongo,mongod等可执行文件,可以右击修改其权限为可执行文件,以及复制移动到其它电脑上都可以使用

注:当进行不下去的时候,需要可以使用sudo chmod -R 777将/opt/scons文件夹权限放大来尝试解决

(四)使用MongoDB

step 1: 在/opt/mongo文件夹下新建/data和/log文件夹

step 2: 在/log文件夹下新建mongodb.log文件

step 3: 部署数据库,在/log/mongo文件夹下运行:

./bin/mongod -port 27017 --dbpath data/ --logpath log/mongodb.log --fork

step 4: 使用mongo客户端,在/log/mongo文件夹下运行如下命令以启动数据库:

./bin/mongod

好啦,看到客户端能够使用,终于完成了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: