Build and install MongoDB from source
Binaries prepared for installation are also available and there are detailed instructions for installing them, but for a better understanding of the processes we will make our own assembly. All the actions described below are performed in the openSUSE Linux operating system version 13.2. Currently, the latest available version of MongoDB is version number 3.0.3.
It should be noted right away that MongoDB manufacturers strongly recommend installing DBMSs on dedicated servers running 64-bit operating systems, in the amount of at least three replicas in a cluster. But since we do not plan to open our own data center yet, for starters we only need a standalone server with a running instance of Monga or even a virtual machine with a very modest configuration. The system user under which MongoDB will be launched is called "sysadmin" (I created it when installing the system), the main group is "users". Installation consists of the following steps:
We get the source archive of the latest version of MongoDB from the official site.
We read the DBMS assembly manual from source.
Under the superuser account, install the packages that are required for assembly, if they are not already installed on the system.
zypper in gcc python scons glibc-devel
We 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
We perform further actions in the account created for installing MongoDB (sysadmin).
Unpack the archive and start the assembly in the source folder.
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 executables will be installed by default in / usr / local. The all option means that the DBMS kernel and tests will be built, which scons will execute during the build process. At the end of the process, the bin subdirectory will be created in the / opt / mongo directory, storing the DBMS executable files.
So, we installed and tested the MongoDB core. The files in the bin directory have the following purpose:
mongod - directly the database server that starts the Mongi processes, manages the databases and access to them.
mongo is a shell interface implemented as an interactive javascript shell for working with databases and collections.
mongos- a sharding controller that routes application requests and determines the location of data in the
mongoperf cluster - a utility for checking the performance of a disk device when performing read / write operations.
After installing the core components of the kernel, we need to build and install additional utilities that are bundled with MongoDB and collectively called mongo-tools. As the official guide says, starting with version 2.8, these tools are written in Go . We also need git to clone the mongo-tools repository.
Install the missing packages:
zypper in go git
Clone the repository:
git clone https://github.com/mongodb/mongo-tools
To install GOPATH and resolve dependencies, you must run the set_gopath.sh script in the root of the mongo-tools directory :
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 all the procedures have been completed, 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 of utilities:
bsondump is a utility for converting BSON files to “human-readable” formats, including JSON. For example, it is convenient for reading the output files generated with mongodump;
mongodump is a tool for uploading database contents to binary format. Together with the mongorestore utility, they compose tools for backing up and restoring MongoDB databases;
mongorestore - a program to restore the contents of a database from the binary format of the dump database generated by mongodump;
mongooplog - an application for receiving replication operations from remote servers and applying them to a local server;
mongoimport- a program for uploading to the database content obtained from JSON, TSV, CSV files generated by mongoexport or other similar applications;
mongoexport - utility for exporting data stored in the database to JSON, TSV, CSV formats;
mongostat is an application for monitoring the status of running instances of mongod and mongos. This program is functionally similar to the UNIX / Linux vmstat utility, differing in that it provides statistics on mongo applications;
mongotop - a tool for tracking the time spent by an instance of the Monga database on data read and write operations;
mongofiles is a tool for managing files that the DBMS stores as GridFS objects.
At the end, export the executable file search paths.
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
That's it, MongoDB is assembled and installed. You can begin to create the necessary configuration.