Select your language

MongoDB is a document-oriented NoSQL database management system. This guide explains how to run MongoDB on your Managed Flex Server.

Requirements

MongoDB can be used with a Managed Flex Server M, L, XL or XXL.

Setting up MongoDB

Hostpoint provides you with the appropriate MongoDB tool collection for your Managed Flex Server operating system. Links to the standard version can be found at /usr/local/bin/. Specific versions can be found at /usr/local/mongodbXX. The XX stands for the version. We recommend using the standard version whenever possible.

We will notify you of changes to available versions by e-mail. We recommend that you read these informational e-mails carefully at all times, so that you can find out about any maintenance work you need and can plan and carry it out accordingly.

Please also read section “3. Maintenance” in this guide.

Creating a data directory

For the MongoDB server to save your database, you need a corresponding folder on your home page.

To complete these steps, you must be logged into your Managed Flex Server via SSH.

As an example in this guide, we use the hidden folder ~/.mongod/data/db/ on your home page. Create this folder as follows:

[username@flex:~] 1 $ mkdir -p ~/.mongod/data/db

Manual startup of MongoDB

For the setup, start the MongoDB server manually in a shell with the following command:

[username@flex:~] 1 $ /usr/local/bin/mongod --dbpath ~/.mongod/data/db

The MongoDB server initializes the previously created data directory and then waits for connections. In your terminal, you will see various text outputs about the current status as well as possible problems during start-up and operation. Do not cancel the command and continue setting up the database user with the next step.

(You can find out how to start the service as usual for operation on your web server in the section “2.4 Integration of MongoDB into Custom Service Control (CSC)” below in this guide.

Installation of mongosh

These steps are necessary to install the CLI application mongosh so that you can communicate with MongoDB via CLI.

First you need to create or edit these 2 files and insert the appropriate content:

NPM_PACKAGES="${HOME}/.npm-packages"
NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"
export PATH="$NPM_PACKAGES/bin:$PATH"
prefix=${HOME}/.npm-packages

These entries allow you to install global packages with NPM.

In order for the changes in the .profile file to become active, you would now have to log out and log back in, or run the source command:

source ~/.profile

Finally, you would need to install the mongosh package with NPM:

npm install -g @mongosh/cli-repl

Creating a database user

In the next step, you need to create a user with a password for protected access to your MongoDB server.

To do this, start an additional shell session and run the mongosh command on your flex server to connect to the MongoDB process you started before:

[username@flex:~] 1 $ mongosh
MongoDB shell version v5.0.12

connecting to: mongodb://127.0.0.1:27017/[..]

>

Tell the MongoDB server that you now want to use the database admin:

use admin

Now you can create the user. The following example shows how to create an admin user with access to all databases. For more information about the different roles, refer to the MongoDB Role-Based Access Control documentation.

db.createUser(
{ user: "User",
	 pwd: "password",
			
	 roles:[{role: "userAdminAnyDatabase" , db:"admin"}]})

Once you have set up the database user, you have created the prerequisites for the regular operation of your MongoDB server. You can exit the MongoDB server in your first terminal with Ctrl+C and continue with the next step.

Integration of MongoDB into Custom Service Control (CSC)

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

Configuring MongoDB in the CSC is fairly simple. Set up a new custom service for MongoDb as follows:

[username@flex:~] 1 $ hpservices supervisord add mongodb

A configuration framework is created in the file ~/.services/supervisord/mongodb/service.conf . Open this file in a text editor. For MongoDB you essentially have to change the command, otherwise, you can accept the suggested values and comment out the lines accordingly (remove semicolons at the beginning of the line for all lines except the directory line):

~/.services/supervisord/mongodb/service.conf
[program:mongodb]
command=/usr/local/bin/mongod --auth --dbpath %(ENV_HOME)s/.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)

If you are using CSC for the first time, you must now activate it. If this is the case, we also recommend that you read the detailed documentation on Custom Service Control.

[username@flex:~] 1 $ hpservices supervisord start

If you are already using CSC for other services, use supervisorctl update update to add and activate the new configuration for MongoDB. With the above service definition, MongoDB starts automatically:

[username@flex:~] 1 $ supervisorctl update
mongodb: added process group
[username@flex:~] 1 $ supervisorctl status
mongodb RUNNING pid 92108, uptime 1:13:39

The output of the MongoDB server can now be found in the stdout_logfile, which you previously defined for the service.

Testing MongoDB instance

Your MongoDB server is now ready to accept connections. You can test this with the MongoDB-CLI:

[username@flex:~] 1 $ mongosh

If everything is configured correctly, you will get the following output:

MongoDB shell version vX.X.X
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("[..]") }
MongoDB server version: X.X.X
>

Maintenance

With updates of the MongoDB version, you may have to carry out some maintenance work. We will notify you by e-mail about upcoming software updates for your Managed Flex Server. Read these carefully and check in the Release Notes of the MongoDB project if you need to perform maintenance work on your database when upgrading the MongoDB version.

Backup

MongoDB stores the data in a binary format in the folder you specify.

The selected folder is located on your home page, which means that the data is generally collected by your regular file backup. However, since this data is structured DB data with an application-specific change pattern and backup requirements, you should consider a suitable backup strategy. For more on this, read the MongoDB documentation.

Additional information

Please use this form only to provide feedback on the above guide.
For support requests please use this form instead.

 

 

© 2001 - Hostpoint AG
Cookie

Wir verwenden Cookies  🍪

We use Cookies  🍪

Nous utilisons des cookies  🍪

Utilizziamo dei cookie  🍪

Die digitalen Auftritte von Hostpoint (Website, Control Panel, Support Center etc.) verwenden Cookies. Diese werden dazu verwendet, um Daten über Besucherinteraktionen zu sammeln. Wenn Sie auf «Akzeptieren» klicken, stimmen Sie der Verwendung dieser Cookies für Werbezwecke, Website-Analyse und Support zu. Gewisse essenzielle Cookies sind jedoch für eine ordnungsgemässe Funktion dieser Seiten unerlässlich und können deshalb nicht deaktiviert werden. Auch ohne Ihre Zustimmung können gewisse Daten in anonymisierter Form für statistische Zwecke und zur Verbesserung unserer Websites verwendet werden. Bitte beachten Sie unsere Datenschutzerklärung.

Hostpoint's digital presences (website, Control Panel, Support Center, etc.) use cookies. These are used to collect data on visitor interactions. If you click “Accept”, you agree to the use of these cookies for advertising purposes, website analysis and support. However, certain cookies are essential for the proper functioning of these pages and therefore cannot be disabled. Even without your consent, certain data may be used in anonymized form for statistical purposes and to improve our websites. Please note our Privacy policy.

Le sites Web de Hostpoint (site Web, Control Panel, Centre d'assistance, etc.) utilisent des cookies. Ces cookies servent à collecter des données sur les interactions des visiteurs. En cliquant sur «Accepter», vous consentez à l’utilisation de ces cookies à des fins de publicité, d’analyse du site Web et d’assistance. Certains cookies essentiels sont cependant indispensables au bon fonctionnement de notre sites Web et ne peuvent donc pas être désactivés. Même sans votre consentement, certaines données peuvent être utilisées sous forme anonymisée à des fins statistiques et pour améliorer notre sites Web. Veuillez prendre connaissance de notre Déclaration de protection des données.

Le presenze digitali di Hostpoint (sito web, Pannello di controllo, Support Center, ecc.) utilizzano i cookie. Questi vengono utilizzati per raccogliere dati sulle interazioni dei visitatori. Facendo clic su «Accetta», acconsente all’utilizzo di questi cookie per scopi pubblicitari, di analisi del sito web e di supporto. Alcuni cookie essenziali sono tuttavia indispensabili per il corretto funzionamento di questi siti web e pertanto non possono essere disattivati. Anche senza il Suo consenso, determinati dati potrebbero essere utilizzati in forma anonima per fini statistici e per l’ottimizzazione dei nostri siti web. Si prega di tenere conto della nostra Dichiarazione per la pivacy.

Ablehnen
Decline
Refuser
Rifiuta
Akzeptieren
Accept
Accepter
Accetta