ELMA365 On-Premises > Creating external databases / MongoDB

MongoDB

This article describes how to install MongoDB for Ubuntu Linux 20.04. Also, you can find a short user guide here: https://docs.mongodb.com/v3.6/tutorial/install-mongodb-on-ubuntu/.

начало внимание 

In this examaple we use elma365 as database name, elma365 as user, and SecretPassword as password.

When doing your settings, specify these data according to your company's security policies.

конец внимание

MongoDB installation

For correct operation, you will need MongoDB versions 3.6 or 4.0.

To install MongoDB, add the official repository:

sudo echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list
sudo wget -qO - https://www.mongodb.org/static/pgp/server-3.6.asc | sudo apt-key add -
sudo apt update

Next install MongoDB:

sudo apt install mongodb-org

Allowing connection from another network

In the /etc/mongod.conf comfiguration file find "network interfaces", select the "bindIp" value and after a comma add an external IP address of the server where MongoDB is running (for example 10.0.1.1):

sudo nano /etc/mongod.conf
 
# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1,10.0.1.1

Restart MongoDB to apply the changes:

sudo systemctl restart mongod

Creating database

  1. Open mongi cli or create a database:

mongo

  1. Use the elma365 database. If there is no database, you will need to create it.  

use elma365

  1. Create the elma365 user with the password SecretPassword:

db.createUser({user:'elma365', pwd:'SecretPassword', roles:["readWrite"]})

  1. Complete the settings:

exit

MongoDB security

When MongoDB is not installed in a demilitarized zone, and other users can connect to it, you have to provide data security:

  1. Connect to mongo:

mongo

  1. Create a superuser:

use admin
db.createUser(
  {
    user: “superuser”,
    pwd: “SecretPassword”,
    roles: [ “root” ]
  }
)

  1. Make sure the user has been created:

show users

  1. To enable authentication, modify the /etc/mongod.conf configuration file:

sudo nano /etc/mongod.conf

  1. Find and uncomment the Security section, then add the authorization parameter and set its value to "enabled". Note that there is no space before the security line, and the authorization line is separated by two spaces at the beginning:

security:
  authorization: "enabled"

  1. Restart mongodb

sudo systemctl restart mongod

Connect to MongoDB

Use this command to connect MondoDB:

mongodb://elma365:SecretPassword@<mongodb-server-address>:27017/elma365

Back up the MongoDB data using elma365ctl dump

начало внимание

While creating a backup, elma365 services will be discontinued and the app will become unavailable.

конец внимание

  1. To back up the Mongodb data, use the following command:

elma365ctl dump --parts=mongo –consistent

  1. The dump will be saved to the /backup folder with a Time Stamp Protocol.

Restore the MongoDB data using elma365ctl restore

  1. Discontinue the app services and prepare the system for the data recovery using the command:

elma365ctl restore –prepare

After that, you need to recreate the MongoDB database.

  1. Connect to the elma365 database and delete it using the commands:

use elma365
db.dropDatabase()

  1. Create a database and assign the selected user as its owner, as described above.
  2. Restore the data with the command:

elma365ctl restore --parts=mongo --path=/backup/<dump_folder>

The system will be available within a few minutes after the command is completed.

Found a typo? Highlight the text, press ctrl + enter and notify us