Rate This Document
Findability
Accuracy
Completeness
Readability

Compiling and Installing MongoDB Tools

This section uses MongoDB 3.6.13 as an example. You can also refer to this section for MongoDB of other versions.

In the following commands, 3.6.13 indicates the MongoDB version. When installing another version, replace 3.6.13 with the actual version.

  1. Download the source package of the Go compiler.
    1
    2
    cd /root
    wget https://dl.google.com/go/go1.13.5.linux-arm64.tar.gz
    
  2. Decompress the Go source package to the /usr/local directory.
    1
    2
    tar -C /usr/local -xzf go1.13.5.linux-arm64.tar.gz
    ls /usr/local/go
    

  3. Set the environment variables of the Go compiler.
    1. Configure the environment variables.
      1. Open profile.
        1
        vim /etc/profile
        
      2. Press i to enter the insert mode and add the following content to the end of the file:
        1
        2
        export PATH=$PATH:/usr/local/go/bin
        export GOROOT="/usr/local/go"
        
      3. Press Esc, type :wq!, and press Enter to save the file and exit.
    2. Make the environment variables take effect.
      1
      source /etc/profile
      
    3. Check whether the environment variables of the Go compiler are set successfully.
      1
      go env
      

  4. View the Go compiler version.
    1
    2
    whereis go
    /usr/local/go/bin/go version
    

  5. Download the MongoDB Tools source package.
    1
    2
    cd /root 
    wget https://github.com/mongodb/mongo-tools/archive/r3.6.13.tar.gz --no-check-certificate
    

    If the wget command fails to be executed, replace github.com with github.com.cnpmjs.org and run the download command again.

  6. Decompress the MongoDB Tools source package.
    1
    2
    3
    mv r3.6.13.tar.gz mongo-tools-r3.6.13.tar.gz
    tar -xvf mongo-tools-r3.6.13.tar.gz
    ll mongo-tools-r3.6.13
    

  7. Set the environment variables of MongoDB Tools.
    1
    2
    3
    4
    cd /root/mongo-tools-r3.6.13
    chmod +x set_goenv.sh
    source set_goenv.sh
    ls
    

  8. Change the compilation directory of MongoDB Tools.

    The mongo-tools-r3.6.13 directory is generated after the decompression. You need to perform the following operations to change the directory structure. Otherwise, an error will be reported during the compilation.

    Run the following command in the same directory as mongo-tools-r3.6.13 (/root in this section):

    1
    2
    3
    4
    cd /root
    mkdir -p mongodb-tools-3.6.13/src/github.com/mongodb
    mv mongo-tools-r3.6.13 mongodb-tools-3.6.13/src/github.com/mongodb/mongo-tools
    ls
    

  9. Download and decompress the gopacket package to replace the gopacket package of MongoDB Tools.
    1. Download gopacket.
      1
      2
      cd /root 
      wget https://github.com/google/gopacket/archive/master.zip --no-check-certificate
      

      If the wget command fails to be executed, replace github.com with github.com.cnpmjs.org and run the download command again.

    2. Decompress gopacket.
      1
      2
      unzip master.zip
      ll gopacket-master
      

    3. Replace gopacket of MongoDB Tools.
      1
      2
      3
      4
      ls /root/mongodb-tools-3.6.13/src/github.com/mongodb/mongo-tools/vendor/github.com/google/gopacket/
      rm -rf /root/mongodb-tools-3.6.13/src/github.com/mongodb/mongo-tools/vendor/github.com/google/gopacket/
      mv gopacket-master /root/mongodb-tools-3.6.13/src/github.com/mongodb/mongo-tools/vendor/github.com/google/gopacket
      ls /root/mongodb-tools-3.6.13/src/github.com/mongodb/mongo-tools/vendor/github.com/google/gopacket/
      

  10. Create a GCC soft link.
    1. View the GCC path and version.
      1
      2
      whereis gcc
      /usr/bin/gcc --version
      

    2. Create a GCC soft link and view it.
      1
      2
      3
      mkdir -p /opt/mongodbtoolchain/v3/bin
      ln -s /usr/bin/gcc /opt/mongodbtoolchain/v3/bin/aarch64-mongodb-linux-gcc
      ll /opt/mongodbtoolchain/v3/bin/aarch64-mongodb-linux-gcc
      

      • aarch64-mongodb-linux-gcc: Name of the soft link file to be created.
      • /opt/mongodbtoolchain/v3/bin: Path for storing the soft link file.
      • /usr/bin/gcc: Source file linked by the soft link file.
      • To delete the soft link, run the following command. In the command, /opt/mongodbtoolchain/v3/bin/aarch64-mongodb-linux-gcc indicates the created soft link file.
        rm -rf /opt/mongodbtoolchain/v3/bin/aarch64-mongodb-linux-gcc
  11. Compile and install MongoDB Tools.
    cd /root/mongodb-tools-3.6.13/src/github.com/mongodb/mongo-tools/
    ./build.sh

    View the generated binary executable file.

    1
    ll /root/mongodb-tools-3.6.13/src/github.com/mongodb/mongo-tools/bin
    

  12. Check whether the MongoDB Tools commands are normal. This section uses mongostat and mongoexport as examples.
    1
    2
    3
    /root/mongodb-tools-3.6.13/src/github.com/mongodb/mongo-tools/bin/mongostat --version
    /root/mongodb-tools-3.6.13/src/github.com/mongodb/mongo-tools/bin/mongoexport --version
    /root/mongodb-tools-3.6.13/src/github.com/mongodb/mongo-tools/bin/mongodump --version