mongdb官网提供的mongo bin文件仅支持64位的。
没有办法,只得从源码安装了。源码下载:
https://fastdl.mongodb.org/src/mongodb-src-r4.0.4.tar.gz
mongo master build要求:
To build MongoDB, you will need:
A modern C++ compiler. One of the following is required.
GCC 5.4.0 or newer
Clang 3.8 (or Apple XCode 8.3.2 Clang) or newer
Visual Studio 2015 Update 3 or newer (See Windows section below for details)
On Linux and macOS, the libcurl library and header is required. MacOS includes libcurl.
Fedora/RHEL - dnf install libcurl-devel
Ubuntu/Debian - apt-get install libcurl-dev
Python 2.7.x and Pip modules:
pyyaml
typing
cheetah
MongoDB supports the following architectures: arm64, ppc64le, s390x, and x86-64. More detailed platform instructions can be found below.
升级gcc
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
#sudo apt-get install software-properties-common
sudo apt-get install gcc-5 g++-5
sudo ln -s /usr/bin/gcc-5 /usr/bin/gcc -f
sudo ln -s /usr/bin/g++-5 /usr/bin/g++ -f
安装python依赖:
sudo pip install pyyaml typing Cheetah
安装编译依赖:
#apt-get install build-essential
apt-get install libboost-filesystem-dev libboost-program-options-dev libboost-system-dev libboost-thread-dev libcurl4-openssl-dev
编译mongo
sudo python buildscripts/scons.py core
碰到问题:
WiredTiger is not supported on 32-bit platforms
Re-run scons with --wiredtiger=off to build on 32-bit platforms
sudo python buildscripts/scons.py core --wiredtiger=off
碰到问题:
(1) Compiling build/opt/third_party/mozjs-45/extract/js/src/mfbt/Unified_cpp_mfbt0.o
cc1plus: fatal error: js-confdefs.h: No such file or directory
compilation terminated.
scons: *** [build/opt/third_party/mozjs-45/extract/js/src/mfbt/Unified_cpp_mfbt0.o] Error 1
(2) src/third_party/gperftools-2.5/src/static_vars.cc:34:20: fatal error: config.h: No such file or directory
(3)src/third_party/gperftools-2.5/src/symbolize.cc:37:20: fatal error: config.h: No such file or directory
执行:
sudo python buildscripts/scons.py core --wiredtiger=off --disable-warnings-as-errors
如此编译还有问题。
终于从mongo官方github上docs/building.md中看到.3.4之后的版本,不支持32位系统。
且3.3和3.4版本的某些地方依赖不支持i386架构(如gperftools和mozjs).
综合考虑,使用3.2.9的版本。
3.2.9的build要求及适应系统类型如下:
To build MongoDB, you will need:
* A modern C++ compiler. One of the following is required.
* GCC 4.8.2 or newer
* Clang 3.4 (or Apple XCode 5.1.1 Clang) or newer
* Visual Studio 2013 Update 2 or newer
* Python 2.7
* SCons 2.3
for the target x86, or x86-64 platform.
sudo apt-get install scons python-pymongo
git clone https://github.com/mongodb/mongo.git
#git reset --hard
git checkout r3.2.9
scons core --wiredtiger=off
install:
sudo mkdir -p /opt/mongo
cd build/opt
sudo ln -s $(pwd)/mongo* /opt/mongo
#执行完上述操作后,在/opt/mongo目录下应该有mongod, mongo,mongos三个文件。
启动mongo,如果出现如下结果表示mongo启动成功。
cd /opt/mongo
sudo mkdir log data
sudo chown -R {login_user}:{login_user} /opt/mongo
touch mongo.cnf
####输入如下内容
dbpath=/opt/mongo/data/
logpath=/opt/mongo/log/mongo.log
logappend=true
fork=true
storageEngine=mmapv1
################
./mongod --config mongo.cnf
测试mongo服务:
./mongo
MongoDB shell version: 3.2.9
connecting to: test
Server has startup warnings:
2018-11-17T21:11:02.163+0800 I CONTROL [initandlisten]
2018-11-17T21:11:02.163+0800 I CONTROL [initandlisten] ** WARNING: This 32-bit MongoDB binary is deprecated
2018-11-17T21:11:02.163+0800 I CONTROL [initandlisten]
2018-11-17T21:11:02.163+0800 I CONTROL [initandlisten]
2018-11-17T21:11:02.163+0800 I CONTROL [initandlisten] ** NOTE: This is a 32 bit MongoDB binary.
2018-11-17T21:11:02.163+0800 I CONTROL [initandlisten] ** 32 bit builds are limited to less than 2GB of data (or less with --journal).
2018-11-17T21:11:02.163+0800 I CONTROL [initandlisten] ** Note that journaling defaults to off for 32 bit and is currently off.
2018-11-17T21:11:02.163+0800 I CONTROL [initandlisten] ** See http://dochub.mongodb.org/core/32bit
2018-11-17T21:11:02.163+0800 I CONTROL [initandlisten]
2018-11-17T21:11:02.163+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2018-11-17T21:11:02.164+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-11-17T21:11:02.164+0800 I CONTROL [initandlisten]
2018-11-17T21:11:02.164+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-11-17T21:11:02.164+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-11-17T21:11:02.164+0800 I CONTROL [initandlisten]
> show dbs
local 0.078GB
> db.stats()
{
"db" : "test",
"collections" : 0,
"objects" : 0,
"avgObjSize" : 0,
"dataSize" : 0,
"storageSize" : 0,
"numExtents" : 0,
"indexes" : 0,
"indexSize" : 0,
"fileSize" : 0,
"ok" : 1
}
> exit;
参考:
网友安装实例: https://blog.csdn.net/winnie_shi/article/details/79834498?utm_source=blogxgwz5
官方源码安装文档:https://github.com/mongodb/mongo/blob/master/docs/building.md
升级gcc到5.x: https://www.cnblogs.com/loadofleaf/p/5667989.html
ubuntu32为安装ubuntu限制:https://askubuntu.com/questions/772181/how-can-i-install-mongodb-on-32-bit-ubuntu
mongodb 编译手册:
https://github.com/mongodb/mongo/blob/r3.2.9/docs/building.md
https://github.com/mongodb/mongo/wiki/Build-Mongodb-From-Source
scons介绍: https://www.scons.org/
raspberry-pi 安装mongodb: http://koenaerts.ca/compile-and-install-mongodb-on-raspberry-pi/