Compile and deploy the arm64 version of Mongodb5.0.18
MongoDB source code compilation
Prepare installation package
https://github.com/mongodb/mongo/releases/tag/r5.0.18
Upload: /opt/package
Unzip:
tar -zxvf /opt/package/mongo-r5.0.18.tar.gz -C /opt/package
View the build documentation, which contains detailed instructions and requires the server to meet the conditions.
cat /opt/package/mongo-r5.0.18/docs/building.md
Install gcc
Download address: http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-9.5.0/gcc-9.5.0.tar.gz
Upload: /opt/package
Unzip: gcc-9.5.0.tar.gz
tar -zxvf /opt/package/gcc-9.5.0.tar.gz -C /opt/package
Install dependencies
# Install dependencies yum -y install bzip2 wget # Enter the gcc-9.5.0 directory cd /opt/package/gcc-9.5.0 # Execute in the decompression root directory ./contrib/download_prerequisites
When there is a network, you can execute .contrib/download_prerequisities to download and install dependencies.
If it cannot be executed on the intranet, check the file code and find that you need to download and install four files: gmp-6.1.0.tar.bz2, mpfr-3.1.4.tar.bz2, and mpc-1.0.3.tar. .gz, isl-0.18.tar.bz2, decompress and install it in the first directory of the gcc installation package.
gmp-6.1.0.tar.bz2, the download path is https://ftp.gnu.org/pub/gnu/gmp/gmp-6.1.0.tar.bz2 mpfr-3.1.4.tar.bz2, the download path is https://ftp.gnu.org/pub/gnu/mpfr/mpfr-3.1.4.tar.bz2 mpc-1.0.3.tar.gz, the download path is https://ftp.gnu.org/pub/gnu/mpc/mpc-1.0.3.tar.gz isl-0.18.tar.bz2, the download path is http://www.mirrorservice.org/sites/sourceware.org/pub/gcc/infrastructure/isl-0.18.tar.bz2 Then in the gcc-9.5.0 directory tar -xf gmp-6.1.0.tar.bz2 tar -xf mpfr-3.1.4.tar.bz2 tar -xf mpc-1.0.3.tar.gz tar -xf isl-0.18.tar.bz2 Create soft link ln -sf gmp-6.1.0 gmp ln -sf mpfr-3.1.4 mpfr ln -sf mpc-1.0.3 mpc ln -sf isl-0.18 isl
Compile
# Create compilation directory cd ../ & amp; & amp; mkdir gcc-build-9.5.0 & amp; & amp; cd gcc-build-9.5.0 #Configuration ../gcc-9.5.0/configure --enable-checking=release --enable-languages=c,c++ --disable-multilib # Compile with 32 core # You need to wait for a long time, depending on the machine performance. make -j32 # Install make install # Switch gcc to the new version update-alternatives --install /usr/bin/gcc gcc /opt/gcc-9.5.0/gcc-9.5.0 # The first pitfall: After the installation, it was found that the update-alternatives command could not be executed. Through the update-alternative view command --list gcc, it was found to be empty, that is, the preset gcc could not be updated using update-alternatives. My final The method is to change the original gcc to gcc.bak, g++ to g++.bak, and then create new links for gcc and g++ under /usr/bin, so that they point to the bin directory of gcc9.5.0 gcc and g++.
Upgrade Python
Download the source code address to find version 3.7: Python Source Releases | Python.org
After decompression, switch to the decompression package directory and perform precompile -> compile -> compile and install.
# Install dependencies yum groupinstall -y "Development tools" yum install -y openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel psmisc libffi-devel # Precompile and set the installation directory to /usr/local/python3. The installation directory can be customized ./configure --prefix=/usr/local/python3 # Compile. Because the CPU has 8 cores, set -j8 to speed up compilation. make -j8 #Compile and install make install -j8
Install Python module
# Installation environment yum install python3-devel # Install scons pip3 install scons #Install Python module python3 -m pip install -r /opt/package/mongo-r5.0.18/etc/pip/compile-requirements.txt
But under the intranet situation, this part took nearly a day.
The pip module to be installed includes the dependent libraries specified in scons and compile-requirements.txt, which in turn points to three other files./mongo-r5.0.5/etc/pip/components/platform.req, core.req and compile .req, the final list is as follows:
scons, pypiwin32=223, pywin32=225, psutil, pymongo>=3.9, PyYAML>=3.0.0, requests>=2.0.0, Cheetah3, regex, requirement_parse, setuptools.
Of course, when installing these libraries, some other dependent libraries will also be generated, such as urllib3, idna, charset_normalizer, certifi, types_setuptools, dnspython, etc.
(1) The first thing to do is that you can download the installation package through pip3 download in an environment with the same chip architecture and the same operating system with a network. The downloaded directly is a whl file, upload it to the intranet server, and use pip3 Install can install more than 70% of dependent libraries such as scons, requests, setuptools, etc.
(2) The rest downloaded through pip3 download is tar.gz, such as Cheetah3, psutil, pymongo, PyYAML, etc., and then can be compiled through pip3 wheel
A small number of dependent libraries can be solved, such as psutil, but others such as Cheetah3, PyYAML, pymongo, etc. still report errors, such as pip3 install pymongo-4.3.2-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
It actually prompted an unsupported package.
After working on it for a few more hours, I finally found the answer on Baidu. It is based on the fields in the file name, such as aarch_64, manylinux24, etc. Therefore, to skip this check, just change it to none-any It means there are no requirements for the operating system and chip architecture. For example, change the above file to pymongo-4.3.2-cp37-none-any.whl, and then use pip3 install pymongo-4.3.2-cp37-none-any. whl was successful!
Note: The exception is pywin32, which cannot be found under centos. It may be dedicated to windows. There is no problem during subsequent compilation.
Compile and install
python3 buildscripts/scons.py DESTDIR=/opt/software/mongodb install-core MONGO_VERSION=5.0.18 # Pay attention to the last parameter. If it is not added, the warning during compilation will be regarded as an error and compilation will stop midway. # The compilation time is very long. On a 4C8G machine, it takes 5 or 6 hours.
Error during compilation:
Couldn’t find OpenSSL crypto.h header and library
#Compile and install openssl wget https://www.openssl.org/source/old/3.0/openssl-3.0.0.tar.gz # Download address --- Download version: 3.0.1 (openssl-3.0.1.tar.gz) https://www.openssl.org/source/old/3.0/ # Unzip tar -zxvf openssl-3.0.1.tar.gz cd openssl-3.0.1 #Configuration # --prefix specifies the installation path ./config --prefix=/usr/local/openssl # There is a problem here, the following error will be reported: Can't locate IPC/Cmd.pm in @INC (@INC contains: /root/Downloads/openssl-3.0.1/util/perl /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/ lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 . /root/Downloads/openssl-3.0.1/external/perl/Text-Template-1.56/lib) at /root/Downloads/openssl-3.0.1/util/perl/OpenSSL/config.pm line 18. BEGIN failed--compilation aborted at /root/Downloads/openssl-3.0.1/util/perl/OpenSSL/config.pm line 18. Compilation failed in require at /root/Downloads/openssl-3.0.1/Configure line 23. BEGIN failed--compilation aborted at /root/Downloads/openssl-3.0.1/Configure line 23. Solution: 1) Install perl-CPAN yum install -y perl-CPAN 2) Enter the shell mode of CPAN perl -MCPAN -e shell 3) Install missing modules cpan[1]> install IPC/Cmd.pm ... ... ... cpan[2]>exit # quit # Reconfigure ./config --prefix=/usr/local/openssl #Compile and install make make install # View installation results [root@linux openssl-3.0.0]# cd /usr/local/openssl [root@linux openssl]# ls bin include lib share ssl
Recompile and install to add ssl parameters
[root@linux mongodb-src-r5.0.18]# python3 buildscripts/scons.py --ssl CPPPATH=/usr/local/openssl/include LIBPATH=/usr/local/openssl/lib DESTDIR=/opt/ software/mongodb install-core MONGO_VERSION=5.0.18
Report an error
Checking for C library lzma... no Cannot find system library 'lzma' required for use with libunwin
solve
[root@linux ~]# /bin/ld.gold -llzma --verbose /bin/ld.gold: Attempt to open //lib/liblzma.so failed /bin/ld.gold: Attempt to open //lib/liblzma.a failed /bin/ld.gold: Attempt to open //usr/lib/liblzma.so failed /bin/ld.gold: Attempt to open //usr/lib/liblzma.a failed /bin/ld.gold: error: cannot find -llzma /bin/ld.gold: Opened new descriptor 3 for "a.out" [root@linux ~]# yum install xz-devel [root@linux ~]# find /usr/ -name liblzma.so [root@linux ~]# ln -s /usr/lib64/liblzma.so /usr/lib/liblzma.so [root@linux ~]# /bin/ld.gold -llzma --verbose /bin/ld.gold: Opened new descriptor 3 for "//lib/liblzma.so" /bin/ld.gold: Attempt to open //lib/liblzma.so succeeded /bin/ld.gold: Unlocking file "//lib/liblzma.so" /bin/ld.gold: Released descriptor 3 for "//lib/liblzma.so" /bin/ld.gold: Opened new descriptor 4 for "a.out"
Compile and install again to add ssl parameters
[root@linux ~]# cd /usr/local/mongodb/mongodb-src-r5.0.18/ python3 buildscripts/scons.py --ssl CPPPATH=/usr/local/openssl/include LIBPATH=/usr/local/openssl/lib DESTDIR=/opt/software/mongodb install-core MONGO_VERSION=5.0.18
Report an error
Checking for curl_global_init(0) in C library curl... no Could not find <curl/curl.h> and curl lib
solve
yum install -y libcurl-devel
Continue compilation and installation
python3 buildscripts/scons.py --ssl CPPPATH=/usr/local/openssl/include LIBPATH=/usr/local/openssl/lib DESTDIR=/opt/software/mongodb install-core MONGO_VERSION=5.0.18
Report errors, all warnings are treated as errors
In file included from /usr/include/string.h:638, from /usr/local/include/c + + /9.5.0/cstring:42, from src/third_party/mozjs-60/include/mozilla/Span.h:33, from src/third_party/mozjs-60/include/mozilla/Range.h:12, from src/third_party/mozjs-60/include/jsapi.h:15, from src/mongo/scripting/mozjs/jsstringwrapper.h:33, from src/mongo/scripting/mozjs/jsstringwrapper.cpp:32: In function 'char* strncpy(char*, const char*, size_t)', inlined from 'mongo::mozjs::JSStringWrapper::JSStringWrapper(int32_t)' at src/mongo/scripting/mozjs/jsstringwrapper.cpp:48:12: /usr/include/bits/string3.h:120:34: error: 'char* __builtin_strncpy(char*, const char*, long unsigned int)' specified bound 64 equals destination size [-Werror=stringop-truncation] 120 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest)); | ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~ cc1plus: all warnings being treated as errors scons: *** [build/59f4f0dd/mongo/scripting/mozjs/jsstringwrapper.o] Error 1 scons: building terminated because of errors. build/59f4f0dd/mongo/scripting/mozjs/jsstringwrapper.o failed: Error 1
Solution:
method 1:
Later I found that the official build document also has instructions.
Note : For C++ compilers that are newer than the supported version, the compiler may issue new warnings that cause MongoDB tofail to build since the build system treats compiler warnings aserrors. To ignore the warnings, pass the switch --disable-warnings-as-errors to scons. python3 buildscripts/scons.py install mongod --disable-warnings-as-errors
To ignore this warning, add the –disable-warnings-as-errors parameter
Method 2: The mongo code needs to be modified. It is probably an official bug of this version. It is in the mongo source code directory.
vi src/mongo/scripting/mozjs/jsstringwrapper.cpp # Find line 48 and delete it, add two lines strncpy(_buf, formatted.c_str(), sizeof(_buf) - 1); _buf[sizeof(_buf) - 1] = '\0';
Continue compilation and installation again
python3 buildscripts/scons.py --ssl CPPPATH=/usr/local/openssl/include LIBPATH=/usr/local/openssl/lib DESTDIR=/opt/software/mongodb install-core MONGO_VERSION=5.0.18 -- disable-warnings-as-errors
Done
Linking build/59f4f0dd/mongo/s/mongos Install file: "build/59f4f0dd/mongo/s/mongos" as "/opt/software/mongodb/bin/mongos" scons: done building targets.
Configuring Mongdb
We added DESTDIR=/opt/software/mongodb above, and the built mongodb is in this directory.
Set environment variables
vim /etc/profile
Add content at the end
#MongoDB Env export MONGODB_HOME=/opt/software/mongodb export PATH=$PATH:$MONGODB_HOME/bin
Effective immediately
source /etc/profile
Create folder
Create database folder
mkdir -p /opt/software/mongodb/data
Create log folder
mkdir -p /opt/software/mongodb/log
Modify configuration file
Create the configuration file mongodb.conf
vim /opt/software/mongodb/bin/mongodb.conf dbpath = /opt/software/mongodb/data #Data file storage directory logpath = /opt/software/mongodb/log #Log file storage directory journal=false auth=true # bind_ip_all = true # Any machine can connect # bind_ip = 127.0.0.1,192.168.0.3 # This machine and 192.168.0.3 can be accessed bind_ip = 0.0.0.0 port = 27017 # The instance runs on port 27017 (default) logappend = true # Whether to add or rewrite the log file at startup fork = true # Whether to run in the background
Clean the compressed mongo files
Introduction to strip command in linux——undressing files
cd /opt/software/mongodb/bin strip mongod strip mongo strip mongos
Start MongoDB
mongod -f /opt/software/mongodb/bin/mongodb.conf
Error during startup
Prompt that the libstdc++ .so.6 file version is too low
strings /usr/lib64/libstdc + + .so.6 | grep GLIBCXX
Search the path to install gcc above
find ./ -name libstdc + + .so.6*
Copy to the /usr/lib64 path
cp ./aarch64-unknown-linux-gnu/libstdc + + -v3/src/.libs/libstdc + + .so.6.0.28 /lib64/ # Delete the original soft link mv /lib64/libstdc + + .so.6 /lib64/libstdc + + .so.6_back #Create new soft link ln -s /lib64/libstdc + + .so.6.0.28 /lib64/libstdc + + .so.6
Just use the command to start it again! ! !
Create superuser
MongoDB does not have an invincible user root, only userAdminAnyDatabase who can manage users
Connect to mongoDB server
mongo
Enter admin database
use admin
Create user
User permission list:
Read: Allows users to read the specified database. readWrite: allows users to read and write the specified database. dbAdmin: Allows users to perform management functions in the specified database, such as index creation, deletion, viewing statistics or accessing system.profile. userAdmin: allows users to write to the system.users collection and create, delete and manage users in the specified database. clusterAdmin: only available in the admin database, giving the user administrative rights to all sharding and replication set-related functions. readAnyDatabase: only available in the admin database, giving the user read permissions on all databases. readWriteAnyDatabase: only available in the admin database, giving the user read and write permissions on all databases. userAdminAnyDatabase: only available in the admin database, giving the user userAdmin permissions on all databases. dbAdminAnyDatabase: Only available in the admin database, giving the user dbAdmin permissions on all databases. root: only available in the admin database, super account, super permissions.
stencil:
db.createUser({ user: username, pwd: password, roles:[ { role: permission type, db: accessible db}] })
example:
Create superuser
db.createUser({ user: "root", pwd: "root_123", roles: [ { role: "root", db: "admin" } ] })
Create database
Connect to MongoDB
Specify user to enter MongoDB: mongo admin -u username -p password
mongo admin -u root -p Enter password: root_123
Create database
# If not, it will be created automatically. use ga
Access MongoDB
Connect to MongoDB using Navicat
Test the connection and see if the connection is successful
Operating MongoDB
Start MongoDB
mongod -f /opt/software/mongodb/etc/mongodb.conf
Close MongoDB
Log in to MongoDB using superuser
mongo admin -u root -p Enter password: root_123
Enter the admin database
use admin
CloseMongoDB
db.shutdownServer();