搭建MongoDB编译环境以及踩的一些坑

搭建MongoDB编译环境以及踩的一些坑


编译环境


Ubuntu 20.04.6 LTS

编译版本


github中最新的主分支,应该为8.1.0

编译步骤


依赖安装

  • 安装基本构建工具
    • sudo apt-get install build-essential
  • 安装libcurl-dev和liblzma-dev
    • sudo apt install libcurl4-openssl-dev liblzma-dev
  • 升级GCC版本到11.3及以上
    • 添加必要的PPA:sudo add-apt-repository ppa:ubuntu-toolchain-r/test
    • 更新包索引:sudo apt update
    • 安装GCC 11sudo apt install gcc-11 g++-11
    • 设置默认的GCC版本:sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 60 --slave /usr/bin/g++ g++ /usr/bin/g++-11
    • 确认GCC的版本: gcc -v
  • 升级Python版本到3.10以上
    • 安装必需的依赖:sudo apt install software-properties-common
    • 添加 deadsnakes PPA(包含较新版本的 Python):sudo add-apt-repository ppa:deadsnakes/ppa
    • 安装Python3.10:sudo apt install python3.10 python3.10-dev python3.10-venv
      注意:系统默认安装的Python版本是3.8,不建议把Python3命令指向Python3.10,会出现原先依赖Python3.8的命令不能使用的情况

正式开始编译

  • 下载源代码:git clone git@github.com:mongodb/mongo.git,并进入其目录
  • 创建虚拟环境(可选):
    • python3.10 -m venv python3.10-venv --prompt mongo,如果执行成功会看到目录下出现python3.10-venv这个文件夹
    • source python3.10-venv/bin/activate,执行成功后命令行最前面会出现 (mongo)
    • 运行脚本安装 Poetry 和所需的 Python 依赖:buildscripts/poetry_sync.sh
    • 编译MongoDB:python3 buildscripts/scons.py --build-profile=opt
      • 如果需要使用gdb调试,加上--gdbserver=GDBSERVER
      • 可能会报错:ERROR: Failed to query remote execution capabilities: PERMISSION_DENIED: You must provide a client TLS certificate with a Common Name (CN); for Bazel, use --tls_client_certificate and --tls_client_key,我添加BAZEL_FLAGS=--config=local也不管用,但是当我先folk到自己仓库,再clone到本地这个错误就不会发生。
      • 报错Invalid MONGO_VERSION ‘’, or could not derive from version.json or git metadata. Please add a conforming MONGO_VERSION=x.y.z[-extra] as an argument to SCons则在上面命令中加上MONGO_VERSION=x.x.xx.x.x替换成你下载的源码的版本号。当时我的版本号是8.1.0,记录在 .bazelrc文件中)
      • 报错ERROR: /home/cdf/.engflow/creds/engflow.crt not found. Please reach out to #ask-devprod-build if you need help with the steps below.
        (If the below steps are not working or you are an external person to MongoDB, remote execution can be disabled by passing BAZEL_FLAGS=–config=local at the end of your scons.py invocation)

        在命令后面加上BAZEL_FLAGS=--config=local
      • 报错FAILED: build/opt/mongo/db/libcloner.so
        /bin/sh: 1: /opt/mongodbtoolchain/v4/bin/gdb: not found
        [48/918] Compiled build/opt/mongo/db/repl/rollback_impl.dyn.o
        ninja: build stopped: subcommand failed.

        如图找不到gdb报错

解决方法:提示找不到gdb,但是系统里已经装好了gdb,并且我的目录下没有mongodbtoolchain这个文件夹,我的思路是把找不到的gdb链接到已有的gdb上
sudo mkdir -p /opt/mongodbtoolchain/v4/bin
sudo ln -s /usr/bin/gdb /opt/mongodbtoolchain/v4/bin/gdb

  • ninja -f opt.ninja -j 200 install-devcore参数-j可以根据cpu核心数进行修改,后面install-devcore这个参数可以根据文档只构建所需的部分

参考文档


https://github.com/mongodb/mongo/blob/master/docs/building.md

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值