mongodb 编译得到的二进制非常大
使用官方提供的编译方式,编译完成后,发现非常大
ls -lh mongo mongod
-rwx------. 1 root root 1.2G 3月 31 13:53 mongo
-rwx------. 1 root root 3.6G 3月 31 13:54 mongod
这是因为附带了调试信息,可以使用file mongo
查看一下,得到如下信息
file mongo
mongo: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=9a1f1f5feda555affa07ce3c40e69b744e9bd561, with debug_info, not stripped
最后提示with debug_info, not stripped
,表示有调试信息,使用strip mongo
,去掉调试信息,再查看,体积正常
ls -lh mongo mongod
-rwx------. 1 root root 48M 3月 31 14:44 mongo
-rwx------. 2 root root 100M 3月 31 14:45 mongod
file mongo
mongo: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=9a1f1f5feda555affa07ce3c40e69b744e9bd561, stripped
也可以在编译时增加--separate-debug
参数
python3 buildscripts/scons.py install-core -j16 DESTDIR=/home/mymongo MONGO_VERSION=6.0.3 --separate-debug
上面就是编译mongo常用的一些参数
install-core
表示要编译哪些内容,下面是官方文档介绍的,不过要注意,千万别用install-all或者install-all-meta,这两个编译出来的内容有上百G,编译时间非长久。
The following targets can be named on the scons command line to build and install a subset of components:
install-mongod
install-mongos
install-core (includes only mongod and mongos)
install-servers (includes all server components)
install-devcore (includes mongod, mongos, and jstestshell (formerly mongo shell))
install-all (includes a complete end-user distribution and tests)
install-all-meta (absolutely everything that can be built and installed)
NOTE: The install-core and install-servers targets are not guaranteed to be identical. The install-core target will only ever include a minimal set of "core" server components, while install-servers is intended for a functional end-user installation. If you are testing, you should use the install-core or install-devcore targets instead.
-j16
与make的参数一样,表示几个job一起编译,与自己cpu内核数相关,越多速度越快
DESTDIR=/home/mymongo
编译的bin存放的目录
MONGO_VERSION=6.0.3
要编译的版本
https://github.com/mongodb/mongo/blob/master/docs/building.md
https://www.mongodb.com/community/forums/t/how-to-build-debug-or-release-on-windows/123260/12