MongoDB on Managed Flex Server

MongoDB is a document-oriented NoSQL database management system.
In this guide you will find out how to set up MongoDB on your Managed Flex Server.

Requirements

MongoDB can be used on Managed Flex Server M and higher.

Install MongoDB

To be able to execute the following steps, you must be logged in to your Managed Flex Server via SSH.

For the installation, first create the folder

mkdir -p ~/.mongod/data/db

Starting MongoDB

You can choose from two different MongoDB versions. The currently available versions can be found in the folder /usr/local under mongodbxx.

Start MongoDB in a shell with the appropriate version. 

/usr/local/mongodbxx/bin/mongod --dbpath ~/.mongod/data/db

Create a user

In a new shell, execute the command mongo to create the user. In the following example, the user is a root user who has access to all databases. For more information on the different roles, see the MongoDB documentation at https://www.mongodb.com/docs/manual/.

Connect to the admin database:

use admin

Create user:


db.createUser(
{        user: "User",
        pwd: "password",

        roles:[{role: "userAdminAnyDatabase" , db:"admin"}]})

For more information on the different roles, see the MongoDB documentation at https://www.mongodb.com/docs/manual/.

Integration of MongoDB in the Custom Service Control (CSC)

The Custom Service Control (CSC) can take care of the operation and the automatic management of your application (e.g. start and stop during maintenance).

Configuring MongoDB in the CSC is very simple. Create a new custom service for MongoDB as follows:

hpservices supervisord add mongodb

This creates a configuration framework for the new service in the file ~/.services/supervisord/mongodb/service.conf . For MongoDB only the command has to be modified, otherwise you can accept all suggested values (remove semicolon at the beginning of the line).

~/.services/supervisord/mongodb/service.conf
[program:mongodb]
command=/usr/local/mongodbxx/bin/mongod --auth --dbpath /home/USER/.mongod/data/db
;directory=%(ENV_HOME)s/app/mongodb/       ; directory to cwd to before exec (default no cwd)
autostart=true                ; start application at supervisord start (default: true)
stopwaitsecs=10               ; max num secs to wait before SIGKILL (default 10)
stdout_logfile=%(ENV_HOME)s/.services/supervisord/mongodb/log/default.log
stdout_logfile_maxbytes=1MB   ; filesize at which to rotate logfiles (default ist 50MB)
stdout_logfile_backups=10     ; number of stdout logfile backups (0 means none, default 10)
stderr_logfile=%(ENV_HOME)s/.services/supervisord/mongodb/log/default.err
stderr_logfile_maxbytes=1MB   ; filesize at which to rotate logfiles (default is 50MB)
stderr_logfile_backups=10     ; number of stderr logfile backups (0 means none, default 10)

With supervisorctl update you can activate the new configuration for MongoDB:

supervisorctl update
mongodb: added process group

For more detailed information on how to use the CSC and the options available to you, please refer to the Custom Service Control manual.

Test MongoDB

The MongoDB instance can now be tested with this command:

mongo

If everything has been configured correctly, you should receive the following output:


MongoDB shell version v5.0.5
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("818c38f7-8cfa-497f-901c-0b94818f8862") }
MongoDB server version: 5.0.5

Further information

 

Unable to find what you were looking for?

Our support experts are happy to assist you personally!

 

© 2001 - Hostpoint AG