x86_64编译
编译要求,这部分内容来自安装包
* A modern C++ compiler capable of compiling C++17. One of the following is required:
* GCC 8.0 or newer
* Clang 7.0 (or Apple XCode 10.0 Clang) or newer
* Visual Studio 2017 version 15.9 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 3.7.x and Pip modules:
* See the section "Python Prerequisites" below.
In order to build MongoDB, Python 3.7.x is required, and several Python modules. To i
nstall
the required Python modules, run:
$ pip3 install -r etc/pip/compile-requirements.txt
Note: If the `pip3` command is not available, `pip` without a suffix may be the pip c
ommand
associated with Python 3.7.x.
MongoDB supports the following architectures: arm64, ppc64le, s390x, and x86-64.
- 编译gcc 8.4
wget https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-8.4.0/gcc-8.4.0.tar.gz
cd gcc-8.4.0
contrib/download_prerequisites
./configure --enable-checking=release --enable-language=c,c++ --disable-multilib
make -j 128
# 默认路径在/usr/local,lib库在/usr/local/lib64
make install
/usr/local/bin/gcc -v
# 查看是否安装成功
gcc -v
- 编译安装python3.7
安装依赖
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make libffi-devel
安装python
# 解压缩
tar -zxvf Python-3.7.0.tgz
# 进入解压后的目录,依次执行下面命令进行手动编译
./configure prefix=/usr/local/python3
make && make install
设置环境变量
export PATH=/usr/local/python3/bin:$PATH
- 编译mongodb4.2.6
安装依赖
yum install libcurl-devel -y
安装python依赖
pip3.7 install -r etc/pip/compile-requirements.txt
pip3 install scons
编译mongodb
# 编译所有组件,编译出来的文件超大, 编译花费超过半个小时
python3.7 buildscripts/scons.py all MONGO_VERSION=4.3.1 -j 8
# 编译核心组件 mongod, mongos, shell
scons core MONGO_VERSION=4.3.1 -j 8
python buildscripts/scons.py core MONGO_VERSION=3.4.0 -j 8 CC=/opt/rh/devtoolset-8/root/usr/bin/gcc CXX=/opt/rh/devtoolset-8/root/usr/bin/g++
# 安装( 安装到/opt/mongo )
scons --prefix=/opt/mongo install
# 如果需要lib库和include头文件 需要加上 –full 参数如下,这个测试未通过
scons –prefix=/opt/mongo –full install
编译后需要使用strip取消调试信息
执行 ./mongod
报错
[root@node1 mongo-r4.2.6]# ./mongod
./mongod: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by ./mongod)
./mongod: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.22' not found (required by ./mongod)
./mongod: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by ./mongod)
./mongod: /lib64/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by ./mongod)
查找 libstdc++.so.6
所在目录并设置环境变量
export LD_LIBRARY_PATH=/usr/local/lib64/