📜 ⬆️ ⬇️

Building and Installing MongoDB from Source

We will install MongoDB and work with it in Linux. The manufacturer’s website contains packages for various types of operating systems and their most popular distributions. The list of recommended and supported operating systems is here .

Binaries prepared for installation are also available, and there are detailed instructions for installing them, but we will do our own assembly to better understand the processes. All actions described below are performed on the openSUSE Linux version 13.2 operating system. Currently, the latest available version of MongoDB is version number 3.0.3.

Immediately it should be noted that the MongoDB manufacturers strongly recommend installing the DBMS on dedicated servers running 64-bit operating systems, in an amount of at least three replicas in the cluster. But since we are not planning to open our data center, for a start we will only need a standalone server running an instance of Mongi or even a virtual machine of a very modest configuration. The system user under which MongoDB will be launched is called “sysadmin” (I created it during the installation of the system), the main group is “users”. The installation consists of the following steps:

We receive archive of source codes of the latest MongoDB version from an official site.
')
We read the manual on assembly of a DBMS from source codes.

Under the superuser account, we install the packages that are required for assembly if they are not already installed in the system.

zypper in gcc python scons glibc-devel 

Prepare the infrastructure for the database.

 mkdir -p /opt/mongo //      MongoDB chown sysadmin:users -R /opt/mongo mkdir -p /data/mongo/db //       mkdir -p /data/mongo/log //      chown sysadmin:users -R /data/mongo 

Further actions are performed in the account created to install MongoDB (sysadmin).

We unpack archive and in the folder with source codes we start assembly.

 gunzip mongodb-src-r3.0.3.tar.gz tar -xvf mongodb-src-r3.0.3.tar cd mongodb-src-r3.0.3 scons all —prefix=/opt/mongo install 

If you do not use the –prefix option, MongoDB executable files will by default be installed in / usr / local. The option all means that the database engine and tests will be compiled, the execution of which will be done by scons during the build process. At the end of the process, a bin subdirectory will be created in the / opt / mongo directory, storing the executable database.

So, we installed and tested the MongoDB kernel. Files in the bin directory have the following purposes:

mongod - the database server itself, which starts Mongi processes, manages the databases and access to them.
mongo - shell interface, implemented as an interactive javascript shell for working with databases and collections.
mongos is a sharding controller that routes application requests and locates data in a cluster
mongoperf is a utility for checking the performance of a disk device when performing read / write operations.

After installing the core kernel components, we need to build and install additional utilities that come with MongoDB and collectively called mongo-tools. As the official manual says, starting from version 2.8, these tools are written in the Go language. We also need git to clone the mongo-tools repository.

Install the missing packages:

 zypper in go git 

Clone repository:

 git clone https://github.com/mongodb/mongo-tools 

To install GOPATH and resolve dependencies, in the root of the mongo-tools directory, run the set_gopath.sh script:

 cd mongo-tools . ./set_gopath.sh 

We proceed to the assembly and installation of tools:

 go build -o /opt/mongo/bin/mongoimport mongoimport/main/mongoimport.go go build -o /opt/mongo/bin/mongoexport mongoexport/main/mongoexport.go go build -o /opt/mongo/bin/mongodump mongodump/main/mongodump.go go build -o /opt/mongo/bin/mongorestore mongorestore/main/mongorestore.go go build -o /opt/mongo/bin/mongofiles mongofiles/main/mongofiles.go go build -o /opt/mongo/bin/mongooplog mongooplog/main/mongooplog.go go build -o /opt/mongo/bin/mongostat mongostat/main/mongostat.go go build -o /opt/mongo/bin/mongotop mongotop/main/mongotop.go 

Now mongo-tools are installed. After completing all the procedures, the MongoBD installation directory looks like this:

 ls -all /opt/mongo/bin/ drwxr-xr-x 1 sysadmin users 228  13 18:14 . drwxr-xr-x 1 sysadmin users 20  13 16:36 .. -rwxr-xr-x 1 sysadmin users 4246936  13 18:03 bsondump -rwxr-xr-x 1 sysadmin users 11217232  13 15:32 mongo -rwxr-xr-x 1 sysadmin users 21482704  13 15:32 mongod -rwxr-xr-x 1 sysadmin users 6100416  13 17:56 mongodump -rwxr-xr-x 1 sysadmin users 5907680  13 17:56 mongoexport -rwxr-xr-x 1 sysadmin users 5864160  13 18:05 mongofiles -rwxr-xr-x 1 sysadmin users 6097960  13 17:42 mongoimport -rwxr-xr-x 1 sysadmin users 5574328  13 18:07 mongooplog -rwxr-xr-x 1 sysadmin users 21269648  13 15:32 mongoperf -rwxr-xr-x 1 sysadmin users 6227288  13 17:58 mongorestore -rwxr-xr-x 1 sysadmin users 10155600  13 15:32 mongos -rwxr-xr-x 1 sysadmin users 5795640  13 18:13 mongostat -rwxr-xr-x 1 sysadmin users 5662040  13 18:14 mongotop 


Purpose utilities:

bsondump is a utility for converting BSON files to human-readable formats, including JSON. For example, it is convenient for reading output files generated using mongodump;
mongodump is a tool for uploading the contents of a database to binary format. Together with the utility mongorestore make up tools for backup and restore MongoDB databases;
mongorestore - a program to restore the contents of the database from the binary dump format of the database generated by the mongodump;
mongooplog - an application for receiving replication operations from remote servers and applying them on a local server;
mongoimport - a program for uploading content obtained from JSON, TSV, CSV files into the database, formed by mongoexport or other similar applications;
mongoexport - utility for exporting data stored in the database in formats JSON, TSV, CSV;
mongostat is an application for monitoring the status of running mongod and mongos instances. This program is functionally similar to the UNIX / Linux utility vmstat, distinguished by the fact that it provides statistics on mongo applications;
mongotop - a means of tracking the time spent by an instance of the Mongi base for reading and writing data;
mongofiles is a tool for managing files that a DBMS stores as GridFS objects.

At the end we export the search paths of executable files.

 export PATH=/opt/mongo/bin:$PATH 

Create (if absent) and edit /home/sysadmin/.bash_profile.

 touch .bash_profile echo 'export PATH=/opt/mongo/bin:$PATH' > .bash_profile 

Everything, MongoDB is built and installed. You can begin to create the necessary configuration.

Source: https://habr.com/ru/post/258527/


All Articles