1 软件介绍
MongoDB是一个基于分布式文件存储的数据库。由C++语言编写。旨在为WEBll应用提供可扩展的高性能数据存储解决方案。MongoDB是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的。
2 预置条件
本文档基于TaiShan 100 2280服务器上新安装的Linx GNU/Linux 6.0.90 (stretch)系统环境展开。
3 下载MongoDB源码
Mongodb3.4.2源码下载地址:https://github.com/mongodb/mongo/archive/r3.4.2.tar.gz
将r3.4.2.tar.gz安装包放于/home目录下,并解压:
#tar zxvf r3.4.2.tar.gz
4 依赖包下载安装
4.1 编译安装gcc7.3.0
如果对应系统有gcc7.3.0 deb安装包,可以直接apt-get install安装,按照4.2章节进行操作
4.1.1 gcc7.3.0下载
Linx6.0.90自带的gcc软件包是6.3.0版本,需要重新安装
a) gcc7.3下载地址:
https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz
b) 将gcc-7.3.0.tar.gz放于/home目录下,将解压安装:
#cd /home
#tar -xvf gcc-7.3.0.tar.gz
4.1.2 依赖库isl、gmp、mpc、mpfr下载
如果服务器可以正常连接外网,则不需要执行依赖包下载和配置文件修改,直接执行步骤2中脚本运行即可
a) gmp6.1.0、isl0.16.1、mpc1.0.3、mpfr3.1.4下载地址:,不用解压,直接放到gcc解压的目录下
https://gcc.gnu.org/pub/gcc/infrastructure/
b) 将安装包放于/home/gcc-7.3.0目录下
1 注釋掉contrib/download_prerequisites文件的218~225行
2 在gcc-7.3.0目录下,执行命令:
#/home/soft/gcc-7.3.0/contrib/download_prerequisites ##根据具体软件存放路径进行修改,一定要在标黄的目录路径下运行
4.1.3 gcc编译安装
#cd home/gcc-7.3.0
#mkdir gcc73builddir
#cd gcc73builddir
#../configure --enable-checking=release --enable-language=c,c++ --disable-multilib
#make -j 64
这里64是CPU核数,可以使用lscpu命令查看CPU具体核数,一般建议设置为CPU核数*2
#make install
支持c,c++,默认安装到/usr/local
这个如果是在虚拟机下执行,编译大约需要30分钟~50分钟。
4.1.4 运行
# /usr/local/bin/gcc -v
a) 在/etc/profile文件中添加如下内容:
export PATH=$PATH:/usr/local/bin
b) 在文件~/.bashrc文件中添加如下内容:
source /etc/profile
c) 验证是否安装成功
#source /etc/profile
#gcc -v
4.2 使用deb包直接安装gcc 7.3.0
Linx系统默认gcc是6.3.0版本。Linx系统方已单独提供gcc7.3.0 deb安装包,上传到服务器后,直接使用apt命令进行安装。
apt-get install /home/gcc-7.3_7.3.0linx_arm64.deb |
配置java环境变量,在/etc/profile文件末尾处增加下面的代码:
GCC_HOME=/usr/local/gcc-7.3.0 PATH=$GCC_HOME/bin:$PATH export GCC_HOME PATH |
运行下面命令,使修改的环境变量生效:
source /etc/profile |
查看版本:gcc -v
4.3 解决-fsigned-char问题
1.使用command -v gcc命令寻找gcc所在路径(一般位于/usr/bin/gcc,本次gcc7.3.0默认安装在/usr/local/gcc-7.3.0/bin/gcc)
2.更改gcc的名字(比如改成gcc-impl)
3.在gcc所在目录执行vim gcc,并填入如下内容保存:
#! /bin/sh /usr/bin/gcc-impl -fsigned-char "$@" |
4.执行chmod +x gcc给脚本添加执行权限
5.使用与1-4步相似的方式给g++创建同名字的脚本文件
5 编译安装
# tar -zxvf mongo-r3.4.2.tar.gz
# cd mongo-r3.4.2
由于mongodb测试代码bug,请优先参考常见问题7.5章节进行测试代码修改。
#python2 buildscripts/scons.py MONGO_VERSION=3.4.2 all CFLAGS="-march=armv8-a+crc -mtune=generic" -j64 --disable-warnings-as-errors
-j64
#mkdir /opt/mongo
#python buildscripts/scons.py MONGO_VERSION=3.4.2 --prefix=/opt/mongo --disable-warnings-as-errors CFLAGS="-march=armv8-a+crc" install -j64
安装完成!在/opt/mongo下产生bin目录,bin目录下内容为:
删除调试信息
cd /opt/mongo/bin
strip mongos
strip mongod
strip mongo
6 运行
创建在/opt/mongo/下新建mongodb.conf 配置文件,添加 bind_ip=0.0.0.0
#vi /opt/mongo/mongodb.conf
#mkdir /data/db
使用配置文件启动cd /opt/mongo/bin
./mongod --config /opt/mongo/mongodb.conf
#./mongod不使用配置文件启动的时候,不允许客户端远程连接,所以用上述启动方式启动数据库
打开另一个终端:
#./mongo
7 常见问题
7.1 mangled name will change in C++17
error: mangled name for 'mongo::ScopeGuardImpl1<int (*)(pthread_attr_t*) throw (), pthread_attr_t*>::ScopeGuardImpl1(const mongo::ScopeGuardImpl1<int (*)(pthread_attr_t*) throw (), pthread_attr_t*>&)' will change in C++17 because the exception specification is part of a function type [-Werror=noexcept-type]
解决方案:
GCC 7 的--Wall标志显然还包含对C ++ 17兼容性的警告。由于我们没有对该编译器进行限定,因此它会对我们的代码发出警告并不太令人惊讶。但是,我们还使用--Werror构建,因此这些警告会成为错误。在这种情况下,警告是无害的。您可以通过使用--disable-warnings-as-errors构建再次将其降级为警告。
7.2 No space left on device
src/third_party/mozjs-45/extract/js/src/jit/MCallOptimize.cpp:3611:1: fatal error: error writing to /tmp/ccGS0uQN.s: No space left on device
解决方案:编译产生大量文件,把编译文件放在足够大的目录下面。例如:将文件放于home目录下,并删除原本root目录下的包
7.3 processor does not support `crc32cb w2,w2,w3'
/tmp/ccNLTPMq.s:35: Error: selected processor does not support `crc32cb w2,w2,w3'
解决方案:
The ARMv8 CRC32 instructions are optional ARMv8 ISA instructions. They require a compiler flag to enable so that the assembler recognizes them.
Add CFLAGS="-march=armv8-a+crc -mtune=generic"
7.4 No module named pkg_resources
解决方法:apt-get install pip 安装此包
apt-get install python-setuptools 安装此包
7.5 parse_number_test.cpp:295:5: note: in expansion of macro 'ASSERT_PARSES' ASSERT_PARSES(double, "0xabcab.defdefP-10", 0xabcab.defdefP-10);
具体报错信息:
In file included from src/mongo/base/parse_number_test.cpp:37:0:
src/mongo/base/parse_number_test.cpp:295:49: error: exponent has no digits
ASSERT_PARSES(double, "0xabcab.defdefP-10", 0xabcab.defdefP-10);
^
src/mongo/unittest/unittest.h:106:93: note: in definition of macro '_ASSERT_COMPARISON'
::mongo::unittest::ComparisonAssertion_##COMPARISON(__FILE__, __LINE__, #a, #b, a, b)) \
^
src/mongo/unittest/unittest.h:85:29: note: in expansion of macro 'ASSERT_EQ'
#define ASSERT_EQUALS(a, b) ASSERT_EQ(a, b)
^~~~~~~~~
src/mongo/base/parse_number_test.cpp:44:9: note: in expansion of macro 'ASSERT_EQUALS'
ASSERT_EQUALS(static_cast<TYPE>(EXPECTED_VALUE), v); \
^~~~~~~~~~~~~
src/mongo/base/parse_number_test.cpp:295:5: note: in expansion of macro 'ASSERT_PARSES'
ASSERT_PARSES(double, "0xabcab.defdefP-10", 0xabcab.defdefP-10);
^~~~~~~~~~~~~
scons: *** [build/opt/mongo/base/parse_number_test.o] Error 1
scons: building terminated because of errors.
build/opt/mongo/base/parse_number_test.o failed: Error 1
解决方案:
mongodb测试代码存在bug,需要修改src/mongo/base/parse_number_test.cpp代码
即修改为标黄色部分的代码:
#if !(defined(_WIN32) || defined(__sun))
// Parse hexadecimal representations of a double. Hex literals not supported by MSVC, and
// not parseable by the Windows SDK libc or the Solaris libc in the mode we build.
// See SERVER-14131.
ASSERT_PARSES(double, "0xff", 255);
ASSERT_PARSES(double, "-0xff", -255);
ASSERT_PARSES(double, "0xabcab.defdefP-10", 687.16784283419838);
#endif