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.
- 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
- 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

- Set the environment variables of the Go compiler.
- Configure the environment variables.
- Open profile.
1vim /etc/profile - 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"
- Press Esc, type :wq!, and press Enter to save the file and exit.
- Open profile.
- Make the environment variables take effect.
1source /etc/profile
- Check whether the environment variables of the Go compiler are set successfully.
1go env
- Configure the environment variables.
- View the Go compiler version.
1 2
whereis go /usr/local/go/bin/go version

- 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.
- 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

- 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

- 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

- Download and decompress the gopacket package to replace the gopacket package of MongoDB Tools.
- 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.
- Decompress gopacket.
1 2
unzip master.zip ll gopacket-master

- 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/

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

- 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
- View the GCC path and version.
- 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.
1ll /root/mongodb-tools-3.6.13/src/github.com/mongodb/mongo-tools/bin
- 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
